|
libsax 7.2
|
00001 /************** 00002 FILE : exception.cpp 00003 *************** 00004 PROJECT : SaX2 - library interface 00005 : 00006 AUTHOR : Marcus Schäfer <ms@suse.de> 00007 : 00008 BELONGS TO : SaX2 - SuSE advanced X11 configuration 00009 : 00010 : 00011 DESCRIPTION : native C++ class library to access SaX2 00012 : functionality. Easy to use interface for 00013 : //.../ 00014 : - importing/exporting X11 configurations 00015 : - modifying/creating X11 configurations 00016 : --- 00017 : 00018 : 00019 STATUS : Status: Development 00020 **************/ 00021 #include "exception.h" 00022 #include <QTextOStream> 00023 00024 namespace SaX { 00025 //==================================== 00026 // Globals... 00027 //------------------------------------ 00028 volatile bool DEBUG = false; 00029 00030 //==================================== 00031 // Functions... 00032 //------------------------------------ 00033 void handle_error ( 00034 const char *file, int lineno, const char *msg, const char* exc 00035 ) { 00036 // .../ 00039 // ---- 00040 if (! DEBUG) { 00041 return; 00042 } 00043 flockfile ( stderr ); 00044 fprintf ( stderr, "*** libsax: %s:%i: Qt: *** %s *** delivered\n", 00045 file, lineno - 1,exc 00046 ); 00047 fprintf ( stderr, "*** libsax: %s:%i: error: %s:\n", 00048 file, lineno , msg 00049 ); 00050 funlockfile ( stderr ); 00051 } 00052 00053 //==================================== 00054 // Constructor... 00055 //------------------------------------ 00056 SaXException::SaXException (void) { 00057 // .../ 00060 // ---- 00061 mErrorCode = 0; 00062 mErrorString = new QString (strerror (mErrorCode)); 00063 mErrorValue = new QString ("(null)"); 00064 } 00065 00066 //==================================== 00067 // Enable debugging... 00068 //------------------------------------ 00069 void SaXException::setDebug ( bool enable ) { 00070 // .../ 00072 // ---- 00073 DEBUG = enable; 00074 } 00075 00076 //==================================== 00077 // setErrorCode... 00078 //------------------------------------ 00079 void SaXException::setErrorCode (int id) { 00080 // .../ 00083 // ---- 00084 mErrorCode = id; 00085 *mErrorString = ""; 00086 QTextOStream (mErrorString) << strerror (mErrorCode); 00087 } 00088 00089 //==================================== 00090 // setErrorCode... 00091 //------------------------------------ 00092 void SaXException::setErrorCode (const char* msg, int id) { 00093 // .../ 00096 // ---- 00097 mErrorCode = id; 00098 *mErrorString = ""; 00099 QTextOStream (mErrorString) << msg; 00100 } 00101 00102 //==================================== 00103 // setErrorValue... 00104 //------------------------------------ 00105 void SaXException::setErrorValue ( int data ) { 00106 // .../ 00108 // ---- 00109 QTextOStream (mErrorValue) << data; 00110 } 00111 00112 //==================================== 00113 // setErrorValue... 00114 //------------------------------------ 00115 void SaXException::setErrorValue ( const char* data ) { 00116 // .../ 00118 // ---- 00119 QTextOStream (mErrorValue) << data; 00120 } 00121 00122 //==================================== 00123 // setErrorValue... 00124 //------------------------------------ 00125 void SaXException::setErrorValue ( void* data ) { 00126 // .../ 00128 // ---- 00129 QTextOStream (mErrorValue) << data; 00130 } 00131 00132 //==================================== 00133 // errorReset... 00134 //------------------------------------ 00135 void SaXException::errorReset ( void ) { 00136 // .../ 00139 // ---- 00140 mErrorCode = 0; 00141 *mErrorString = ""; 00142 QTextOStream (mErrorString) << strerror (mErrorCode); 00143 QTextOStream (mErrorValue) << "(null)"; 00144 } 00145 00146 //==================================== 00147 // get last error code 00148 //------------------------------------ 00149 int SaXException::errorCode ( void ) { 00150 // .../ 00153 // ---- 00154 return mErrorCode; 00155 } 00156 00157 //==================================== 00158 // get last error string 00159 //------------------------------------ 00160 QString SaXException::errorString ( void ) { 00161 // .../ 00164 // ---- 00165 return QString::fromLocal8Bit(*mErrorString); 00166 } 00167 00168 //==================================== 00169 // get last error value 00170 //------------------------------------ 00171 QString SaXException::errorValue ( void ) { 00172 // .../ 00175 // ---- 00176 if (mErrorValue->isEmpty()) { 00177 return "(null)"; 00178 } 00179 return QString::fromLocal8Bit(*mErrorValue); 00180 } 00181 00182 //==================================== 00183 // havePrivileges... 00184 //------------------------------------ 00185 bool SaXException::havePrivileges (void) { 00186 // .../ 00189 // ---- 00190 if (! getuid() == 0) { 00191 return false; 00192 } 00193 return true; 00194 } 00195 00196 //==================================== 00197 // setLock... 00198 //------------------------------------ 00199 bool SaXException::setLock ( void ) { 00200 // .../ 00203 // ---- 00204 mLFD = open (ZERO_DEV,O_RDONLY); 00205 if ((flock (mLFD,LOCK_EX)) != 0) { 00206 excLockSetFailed (errno); 00207 qError (errorString(),EXC_LOCKSETFAILED); 00208 return false; 00209 } 00210 return true; 00211 } 00212 00213 //==================================== 00214 // unsetLock... 00215 //------------------------------------ 00216 bool SaXException::unsetLock ( void ) { 00217 // .../ 00220 // ---- 00221 if ((flock (mLFD,LOCK_UN)) != 0) { 00222 excLockUnsetFailed (errno); 00223 qError (errorString(),EXC_LOCKUNSETFAILED); 00224 return false; 00225 } 00226 close (mLFD); 00227 return true; 00228 } 00229 00230 00231 //==================================== 00232 // Exceptions... 00233 //------------------------------------ 00235 void SaXException::excProcessFailed (void) { 00236 setErrorCode (EAGAIN); 00237 emit saxGlobalException (EXC_PROCESSFAILED); 00238 emit saxProcessFailed(); 00239 } 00240 00242 void SaXException::excImportSectionFailed (void) { 00243 setErrorCode (EISAXIMPORT,EISAXIMPORTID); 00244 emit saxGlobalException (EXC_IMPORTSECTIONFAILED); 00245 emit saxImportSectionFailed(); 00246 } 00247 00249 void SaXException::excExportSectionFailed (void) { 00250 setErrorCode (EISAXEXPORT,EISAXEXPORTID); 00251 emit saxGlobalException (EXC_EXPORTSECTIONFAILED); 00252 emit saxExportSectionFailed(); 00253 } 00254 00256 void SaXException::excFileOpenFailed (int e) { 00257 setErrorCode (ENOENT); 00258 setErrorValue (e); 00259 emit saxGlobalException (EXC_FILEOPENFAILED); 00260 emit saxFileOpenFailed (e); 00261 } 00262 00264 void SaXException::excNoStorage (int id) { 00265 setErrorCode (ENODATA); 00266 setErrorValue (id); 00267 emit saxGlobalException (EXC_NOSTORAGE); 00268 emit saxNoStorage (id); 00269 } 00270 00272 void SaXException::excCDBFileFailed (void) { 00273 setErrorCode (ENOENT); 00274 emit saxGlobalException (EXC_CDBFILEFAILED); 00275 emit saxCDBFileFailed (); 00276 } 00277 00279 void SaXException::excPermissionDenied (void) { 00280 setErrorCode (EACCES); 00281 emit saxGlobalException (EXC_PERMISSIONDENIED); 00282 emit saxPermissionDenied (); 00283 } 00284 00286 void SaXException::excProfileNotFound (void) { 00287 setErrorCode (ENOENT); 00288 emit saxGlobalException (EXC_PROFILENOTFOUND); 00289 emit saxProfileNotFound (); 00290 } 00291 00293 void SaXException::excProfileUndefined (int id) { 00294 setErrorCode (EPROFILE,EPROFILEID); 00295 setErrorValue (id); 00296 emit saxGlobalException (EXC_PROFILEUNDEFINED); 00297 emit saxProfileUndefined (id); 00298 } 00299 00301 void SaXException::excImportAlreadyAdded (int id) { 00302 setErrorCode (EALREADY); 00303 setErrorValue (id); 00304 emit saxGlobalException (EXC_IMPORTALREADYADDED); 00305 emit saxImportAlreadyAdded (id); 00306 } 00307 00309 void SaXException::excUnknownImport (SaXImport* in) { 00310 setErrorCode (EBADF); 00311 setErrorValue ((void*)in); 00312 emit saxGlobalException (EXC_UNKNOWNIMPORT); 00313 emit saxUnknownImport (in); 00314 } 00315 00317 void SaXException::excNoAPIFileFound (void) { 00318 setErrorCode (ENOENT); 00319 emit saxGlobalException (EXC_NOAPIFILEFOUND); 00320 emit saxNoAPIFileFound (); 00321 } 00322 00324 void SaXException::excNullPointerArgument (void) { 00325 setErrorCode (EINVAL); 00326 emit saxGlobalException (EXC_NULLPOINTERARGUMENT); 00327 emit saxNullPointerArgument (); 00328 } 00329 00331 void SaXException::excDesktopImportBindFailed (int id) { 00332 setErrorCode (EBADF); 00333 setErrorValue (id); 00334 emit saxGlobalException (EXC_DESKTOPIMPORTBINDFAILED); 00335 emit saxDesktopImportBindFailed (id); 00336 } 00337 00339 void SaXException::excCardImportBindFailed (int id) { 00340 setErrorCode (EBADF); 00341 setErrorValue (id); 00342 emit saxGlobalException (EXC_CARDIMPORTBINDFAILED); 00343 emit saxCardImportBindFailed (id); 00344 } 00345 00347 void SaXException::excPointerImportBindFailed (int id) { 00348 setErrorCode (EBADF); 00349 setErrorValue (id); 00350 emit saxGlobalException (EXC_POINTERIMPORTBINDFAILED); 00351 emit saxPointerImportBindFailed (id); 00352 } 00353 00355 void SaXException::excKeyboardImportBindFailed (int id) { 00356 setErrorCode (EBADF); 00357 setErrorValue (id); 00358 emit saxGlobalException (EXC_KEYBOARDIMPORTBINDFAILED); 00359 emit saxKeyboardImportBindFailed (id); 00360 } 00361 00363 void SaXException::excPathImportBindFailed (int id) { 00364 setErrorCode (EBADF); 00365 setErrorValue (id); 00366 emit saxGlobalException (EXC_PATHIMPORTBINDFAILED); 00367 emit saxPathImportBindFailed (id); 00368 } 00369 00371 void SaXException::excExtensionsImportBindFailed (int id) { 00372 setErrorCode (EBADF); 00373 setErrorValue (id); 00374 emit saxGlobalException (EXC_EXTENSIONSIMPORTBINDFAILED); 00375 emit saxExtensionsImportBindFailed (id); 00376 } 00377 00379 void SaXException::excLayoutImportBindFailed (int id) { 00380 setErrorCode (EBADF); 00381 setErrorValue (id); 00382 emit saxGlobalException (EXC_LAYOUTIMPORTBINDFAILED); 00383 emit saxLayoutImportBindFailed (id); 00384 } 00385 00387 void SaXException::excXKBLoadRulesFailed (void) { 00388 setErrorCode (ENOENT); 00389 emit saxGlobalException (EXC_XKBLOADRULESFAILED); 00390 emit saxXKBLoadRulesFailed (); 00391 } 00392 00394 void SaXException::excCDBRecordNotFound (const char* group) { 00395 setErrorCode (ECDBGROUP,ECDBGROUPID); 00396 setErrorValue (group); 00397 emit saxGlobalException (EXC_CDBRECORDNOTFOUND); 00398 emit saxCDBRecordNotFound (group); 00399 } 00400 00402 void SaXException::excWrongInputFashion (const char* fashion) { 00403 setErrorCode (EFASHION,EFASHIONID); 00404 setErrorValue (fashion); 00405 emit saxGlobalException (EXC_WRONGINPUTFASHION); 00406 emit saxWrongInputFashion (fashion); 00407 } 00408 00410 void SaXException::excSetStorageIDFailed (int id) { 00411 setErrorCode (ERECORD,ERECORDID); 00412 setErrorValue (id); 00413 emit saxGlobalException (EXC_SETSTORAGEIDFAILED); 00414 emit saxSetStorageIDFailed (id); 00415 } 00416 00418 void SaXException::excPointerFashionTypeFailed (const char* fashion) { 00419 setErrorCode (EFASHION,EFASHIONID); 00420 setErrorValue (fashion); 00421 emit saxGlobalException (EXC_POINTERFASHIONTYPEFAILED); 00422 emit saxPointerFashionTypeFailed (fashion); 00423 } 00424 00426 void SaXException::excInvalidArgument (int id) { 00427 setErrorCode (EINVAL); 00428 setErrorValue (id); 00429 emit saxGlobalException (EXC_INVALIDARGUMENT); 00430 emit saxInvalidArgument (id); 00431 } 00432 00434 void SaXException::excInvalidArgument (const char* arg) { 00435 setErrorCode (EINVAL); 00436 setErrorValue (arg); 00437 emit saxGlobalException (EXC_INVALIDARGUMENT); 00438 emit saxInvalidArgument (arg); 00439 } 00440 00442 void SaXException::excLockSetFailed (int error) { 00443 setErrorCode (error); 00444 emit saxGlobalException (EXC_LOCKSETFAILED); 00445 emit saxLockSetFailed (error); 00446 } 00447 00449 void SaXException::excLockUnsetFailed (int error) { 00450 setErrorCode (error); 00451 emit saxGlobalException (EXC_LOCKUNSETFAILED); 00452 emit saxLockUnsetFailed (error); 00453 } 00454 00456 void SaXException::excGetScreenLayoutFailed (int id) { 00457 setErrorCode (ESCREEN,ESCREENID); 00458 setErrorValue (id); 00459 emit saxGlobalException (EXC_GETSCREENLAYOUTFAILED); 00460 emit saxGetScreenLayoutFailed (id); 00461 } 00462 00464 void SaXException::excGetInputLayoutFailed (void) { 00465 setErrorCode (ENODEV); 00466 emit saxGlobalException (EXC_GETINPUTLAYOUTFAILED); 00467 emit saxGetInputLayoutFailed(); 00468 } 00469 00471 void SaXException::excEmptyCDBGroup (const char* name) { 00472 setErrorCode (ECDBDATA,ECDBDATAID); 00473 setErrorValue (name); 00474 emit saxGlobalException (EXC_EMPTYCDBGROUP); 00475 emit saxEmptyCDBGroup (name); 00476 } 00477 00479 void SaXException::excNvidiaDriverMissing ( void ) { 00480 setErrorCode (ENVIDIAMIS,ENVIDIAMISID); 00481 emit saxGlobalException (EXC_NVIDIADRIVERMISSING); 00482 emit saxNvidiaDriverMissing(); 00483 } 00484 00486 void SaXException::excNvidiaDriverInstalled ( void ) { 00487 setErrorCode (ENVIDIAINS,ENVIDIAINSID); 00488 emit saxGlobalException (EXC_NVIDIADRIVERINSTALLED); 00489 emit saxNvidiaDriverInstalled(); 00490 } 00491 00493 void SaXException::excXKBLayoutUndefined ( const char* layout ) { 00494 setErrorCode (EXKBLAYOUT,EXKBLAYOUTID); 00495 emit saxGlobalException (EXC_XKBLAYOUTUNDEFINED); 00496 emit saxXKBLayoutUndefined (layout); 00497 } 00498 00500 void SaXException::excDriverMismatch ( const char* cdb,const char* cur) { 00501 setErrorCode (ECDBMISMATCH,ECDBMISMATCHID); 00502 setErrorValue ((QString(cdb)+" -> "+QString(cur)).latin1()); 00503 emit saxGlobalException (EXC_DRIVERMISMATCH); 00504 emit saxDriverMismatch (cdb,cur); 00505 } 00506 } // end namespace
1.7.3