exception.cpp

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 
00023 namespace SaX {
00024 //====================================
00025 // Globals...
00026 //------------------------------------
00027 volatile bool DEBUG = false;
00028 
00029 //====================================
00030 // Functions...
00031 //------------------------------------
00032 void handle_error (
00033         const char *file, int lineno, const char *msg, const char* exc
00034 ) {
00035         // .../
00038         // ----
00039         if (! DEBUG) {
00040                 return;
00041         }
00042         flockfile ( stderr );
00043         fprintf ( stderr, "*** libsax: %s:%i: Qt: *** %s *** delivered\n",
00044                 file, lineno - 1,exc
00045         );
00046         fprintf ( stderr, "*** libsax: %s:%i: error: %s:\n",
00047                 file, lineno , msg
00048         );
00049         funlockfile ( stderr );
00050 }
00051 
00052 //====================================
00053 // Constructor...
00054 //------------------------------------
00055 SaXException::SaXException (void) {
00056         // .../
00059         // ----
00060         mErrorCode   = 0;
00061         mErrorString = new QString (strerror (mErrorCode));
00062         mErrorValue  = new QString ("(null)");
00063 }
00064 
00065 //====================================
00066 // Enable debugging...
00067 //------------------------------------
00068 void SaXException::setDebug ( bool enable ) {
00069         // .../
00071         // ----
00072         DEBUG = enable;
00073 }
00074 
00075 //====================================
00076 // setErrorCode...
00077 //------------------------------------
00078 void SaXException::setErrorCode (int id) {
00079         // .../
00082         // ----
00083         mErrorCode   = id;
00084         QTextOStream (mErrorString) << strerror (mErrorCode);
00085 }
00086 
00087 //====================================
00088 // setErrorCode...
00089 //------------------------------------
00090 void SaXException::setErrorCode (const char* msg, int id) {
00091         // .../
00094         // ----
00095         mErrorCode   = id;
00096         QTextOStream (mErrorString) << msg;
00097 }
00098 
00099 //====================================
00100 // setErrorValue...
00101 //------------------------------------
00102 void SaXException::setErrorValue ( int data ) {
00103         // .../
00105         // ----
00106         QTextOStream (mErrorValue) << data;
00107 }
00108 
00109 //====================================
00110 // setErrorValue...
00111 //------------------------------------
00112 void SaXException::setErrorValue ( const char* data ) {
00113         // .../
00115         // ----
00116         QTextOStream (mErrorValue) << data;
00117 }
00118 
00119 //====================================
00120 // setErrorValue...
00121 //------------------------------------
00122 void SaXException::setErrorValue ( void* data ) {
00123         // .../
00125         // ----
00126         QTextOStream (mErrorValue) << data;
00127 }
00128 
00129 //====================================
00130 // errorReset...
00131 //------------------------------------
00132 void SaXException::errorReset ( void ) {
00133         // .../
00136         // ----
00137         mErrorCode   = 0;
00138         QTextOStream (mErrorString) << strerror (mErrorCode);
00139         QTextOStream (mErrorValue)  << "(null)";
00140 }
00141 
00142 //====================================
00143 // get last error code
00144 //------------------------------------
00145 int SaXException::errorCode ( void ) {
00146         // .../
00149         // ----
00150         return mErrorCode;
00151 }
00152 
00153 //====================================
00154 // get last error string
00155 //------------------------------------
00156 QString SaXException::errorString ( void ) {
00157         // .../
00160         // ----
00161         return QString::fromLocal8Bit(*mErrorString);
00162 }
00163 
00164 //====================================
00165 // get last error value
00166 //------------------------------------
00167 QString SaXException::errorValue ( void ) {
00168         // .../
00171         // ----
00172         if (mErrorValue->isEmpty()) {
00173                 return "(null)";
00174         }
00175         return QString::fromLocal8Bit(*mErrorValue);
00176 }
00177 
00178 //====================================
00179 // havePrivileges...
00180 //------------------------------------
00181 bool SaXException::havePrivileges (void) {
00182         // .../
00185         // ----
00186         if (! getuid() == 0) {
00187                 return false;
00188         }
00189         return true;
00190 }
00191 
00192 //====================================
00193 // setLock...
00194 //------------------------------------
00195 bool SaXException::setLock ( void ) {
00196         // .../
00199         // ----
00200         mLFD = open (ZERO_DEV,O_RDONLY);
00201         if ((flock (mLFD,LOCK_EX)) != 0) {
00202                 excLockSetFailed (errno);
00203                 qError (errorString(),EXC_LOCKSETFAILED);
00204                 return false;
00205         }
00206         return true;
00207 }
00208 
00209 //====================================
00210 // unsetLock...
00211 //------------------------------------
00212 bool SaXException::unsetLock ( void ) {
00213         // .../
00216         // ----
00217         if ((flock (mLFD,LOCK_UN)) != 0) {
00218                 excLockUnsetFailed (errno);
00219                 qError (errorString(),EXC_LOCKUNSETFAILED);
00220                 return false;
00221         }
00222         close (mLFD);
00223         return true;
00224 }
00225 
00226 
00227 //====================================
00228 // Exceptions...
00229 //------------------------------------
00231 void SaXException::excProcessFailed (void) {
00232         setErrorCode (EAGAIN);
00233         emit saxGlobalException (EXC_PROCESSFAILED);
00234         emit saxProcessFailed();
00235 }
00236 
00238 void SaXException::excImportSectionFailed (void) {
00239         setErrorCode (EISAXIMPORT,EISAXIMPORTID);
00240         emit saxGlobalException (EXC_IMPORTSECTIONFAILED);
00241         emit saxImportSectionFailed();
00242 }
00243 
00245 void SaXException::excExportSectionFailed (void) {
00246         setErrorCode (EISAXEXPORT,EISAXEXPORTID);
00247         emit saxGlobalException (EXC_EXPORTSECTIONFAILED);
00248         emit saxExportSectionFailed();
00249 }
00250 
00252 void SaXException::excFileOpenFailed (int e) {
00253         setErrorCode (ENOENT);
00254         setErrorValue (e);
00255         emit saxGlobalException (EXC_FILEOPENFAILED);
00256         emit saxFileOpenFailed (e);
00257 }
00258 
00260 void SaXException::excNoStorage (int id) {
00261         setErrorCode (ENODATA);
00262         setErrorValue (id);
00263         emit saxGlobalException (EXC_NOSTORAGE);
00264         emit saxNoStorage (id);
00265 }
00266 
00268 void SaXException::excCDBFileFailed (void) {
00269         setErrorCode (ENOENT);
00270         emit saxGlobalException (EXC_CDBFILEFAILED);
00271         emit saxCDBFileFailed ();
00272 }
00273 
00275 void SaXException::excPermissionDenied (void) {
00276         setErrorCode (EACCES);
00277         emit saxGlobalException (EXC_PERMISSIONDENIED);
00278         emit saxPermissionDenied ();
00279 }
00280 
00282 void SaXException::excProfileNotFound (void) {
00283         setErrorCode (ENOENT);
00284         emit saxGlobalException (EXC_PROFILENOTFOUND);
00285         emit saxProfileNotFound ();
00286 }
00287 
00289 void SaXException::excProfileUndefined (int id) {
00290         setErrorCode (EPROFILE,EPROFILEID);
00291         setErrorValue (id);
00292         emit saxGlobalException (EXC_PROFILEUNDEFINED);
00293         emit saxProfileUndefined (id);
00294 }
00295 
00297 void SaXException::excImportAlreadyAdded (int id) {
00298         setErrorCode (EALREADY);
00299         setErrorValue (id);
00300         emit saxGlobalException (EXC_IMPORTALREADYADDED);
00301         emit saxImportAlreadyAdded (id);
00302 }
00303 
00305 void SaXException::excUnknownImport (SaXImport* in) {
00306         setErrorCode (EBADF);
00307         setErrorValue ((void*)in);
00308         emit saxGlobalException (EXC_UNKNOWNIMPORT);
00309         emit saxUnknownImport (in);
00310 }
00311 
00313 void SaXException::excNoAPIFileFound (void) {
00314         setErrorCode (ENOENT);
00315         emit saxGlobalException (EXC_NOAPIFILEFOUND);
00316         emit saxNoAPIFileFound ();
00317 }
00318 
00320 void SaXException::excNullPointerArgument (void) {
00321         setErrorCode (EINVAL);
00322         emit saxGlobalException (EXC_NULLPOINTERARGUMENT);
00323         emit saxNullPointerArgument ();
00324 }
00325 
00327 void SaXException::excDesktopImportBindFailed (int id) {
00328         setErrorCode (EBADF);
00329         setErrorValue (id);
00330         emit saxGlobalException (EXC_DESKTOPIMPORTBINDFAILED);
00331         emit saxDesktopImportBindFailed (id);
00332 }
00333 
00335 void SaXException::excCardImportBindFailed (int id) {
00336         setErrorCode (EBADF);
00337         setErrorValue (id);
00338         emit saxGlobalException (EXC_CARDIMPORTBINDFAILED);
00339         emit saxCardImportBindFailed (id);
00340 }
00341 
00343 void SaXException::excPointerImportBindFailed (int id) {
00344         setErrorCode (EBADF);
00345         setErrorValue (id);
00346         emit saxGlobalException (EXC_POINTERIMPORTBINDFAILED);
00347         emit saxPointerImportBindFailed (id);
00348 }
00349 
00351 void SaXException::excKeyboardImportBindFailed (int id) {
00352         setErrorCode (EBADF);
00353         setErrorValue (id);
00354         emit saxGlobalException (EXC_KEYBOARDIMPORTBINDFAILED);
00355         emit saxKeyboardImportBindFailed (id);
00356 }
00357 
00359 void SaXException::excPathImportBindFailed (int id) {
00360         setErrorCode (EBADF);
00361         setErrorValue (id);
00362         emit saxGlobalException (EXC_PATHIMPORTBINDFAILED);
00363         emit saxPathImportBindFailed (id);
00364 }
00365 
00367 void SaXException::excExtensionsImportBindFailed (int id) {
00368         setErrorCode (EBADF);
00369         setErrorValue (id);
00370         emit saxGlobalException (EXC_EXTENSIONSIMPORTBINDFAILED);
00371         emit saxExtensionsImportBindFailed (id);
00372 }
00373 
00375 void SaXException::excLayoutImportBindFailed (int id) {
00376         setErrorCode (EBADF);
00377         setErrorValue (id);
00378         emit saxGlobalException (EXC_LAYOUTIMPORTBINDFAILED);
00379         emit saxLayoutImportBindFailed (id);
00380 }
00381 
00383 void SaXException::excXKBLoadRulesFailed (void) {
00384         setErrorCode (ENOENT);
00385         emit saxGlobalException (EXC_XKBLOADRULESFAILED);
00386         emit saxXKBLoadRulesFailed ();
00387 }
00388 
00390 void SaXException::excCDBRecordNotFound (const char* group) {
00391         setErrorCode (ECDBGROUP,ECDBGROUPID);
00392         setErrorValue (group);
00393         emit saxGlobalException (EXC_CDBRECORDNOTFOUND);
00394         emit saxCDBRecordNotFound (group);
00395 }
00396 
00398 void SaXException::excWrongInputFashion (const char* fashion) {
00399         setErrorCode (EFASHION,EFASHIONID);
00400         setErrorValue (fashion);
00401         emit saxGlobalException (EXC_WRONGINPUTFASHION);
00402         emit saxWrongInputFashion (fashion);
00403 }
00404 
00406 void SaXException::excSetStorageIDFailed (int id) {
00407         setErrorCode (ERECORD,ERECORDID);
00408         setErrorValue (id);
00409         emit saxGlobalException (EXC_SETSTORAGEIDFAILED);
00410         emit saxSetStorageIDFailed (id);
00411 }
00412 
00414 void SaXException::excPointerFashionTypeFailed (const char* fashion) {
00415         setErrorCode (EFASHION,EFASHIONID);
00416         setErrorValue (fashion);
00417         emit saxGlobalException (EXC_POINTERFASHIONTYPEFAILED);
00418         emit saxPointerFashionTypeFailed (fashion);
00419 }
00420 
00422 void SaXException::excInvalidArgument (int id) {
00423         setErrorCode (EINVAL);
00424         setErrorValue (id);
00425         emit saxGlobalException (EXC_INVALIDARGUMENT);
00426         emit saxInvalidArgument (id);
00427 }
00428 
00430 void SaXException::excInvalidArgument (const char* arg) {
00431         setErrorCode (EINVAL);
00432         setErrorValue (arg);
00433         emit saxGlobalException (EXC_INVALIDARGUMENT);
00434         emit saxInvalidArgument (arg);
00435 }
00436 
00438 void SaXException::excLockSetFailed (int error) {
00439         setErrorCode (error);
00440         emit saxGlobalException (EXC_LOCKSETFAILED);
00441         emit saxLockSetFailed (error);
00442 }
00443 
00445 void SaXException::excLockUnsetFailed (int error) {
00446         setErrorCode (error);
00447         emit saxGlobalException (EXC_LOCKUNSETFAILED);
00448         emit saxLockUnsetFailed (error);
00449 }
00450 
00452 void SaXException::excGetScreenLayoutFailed (int id) {
00453         setErrorCode (ESCREEN,ESCREENID);
00454         setErrorValue (id);
00455         emit saxGlobalException (EXC_GETSCREENLAYOUTFAILED);
00456         emit saxGetScreenLayoutFailed (id);
00457 }
00458 
00460 void SaXException::excGetInputLayoutFailed (void) {
00461         setErrorCode (ENODEV);
00462         emit saxGlobalException (EXC_GETINPUTLAYOUTFAILED);
00463         emit saxGetInputLayoutFailed();
00464 }
00465 
00467 void SaXException::excEmptyCDBGroup (const char* name) {
00468         setErrorCode (ECDBDATA,ECDBDATAID);
00469         setErrorValue (name);
00470         emit saxGlobalException (EXC_EMPTYCDBGROUP);
00471         emit saxEmptyCDBGroup (name);
00472 }
00473 
00475 void SaXException::excNvidiaDriverMissing ( void ) {
00476         setErrorCode (ENVIDIAMIS,ENVIDIAMISID);
00477         emit saxGlobalException (EXC_NVIDIADRIVERMISSING);
00478         emit saxNvidiaDriverMissing();
00479 }
00480 
00482 void SaXException::excNvidiaDriverInstalled ( void ) {
00483         setErrorCode (ENVIDIAINS,ENVIDIAINSID);
00484         emit saxGlobalException (EXC_NVIDIADRIVERINSTALLED);
00485         emit saxNvidiaDriverInstalled();
00486 }
00487 
00489 void SaXException::excXKBLayoutUndefined ( const char* layout ) {
00490         setErrorCode (EXKBLAYOUT,EXKBLAYOUTID);
00491         emit saxGlobalException (EXC_XKBLAYOUTUNDEFINED);
00492         emit saxXKBLayoutUndefined (layout);
00493 }
00494 
00496 void SaXException::excDriverMismatch ( const char* cdb,const char* cur) {
00497         setErrorCode (ECDBMISMATCH,ECDBMISMATCHID);
00498         setErrorValue (QString(cdb)+" -> "+QString(cur));
00499         emit saxGlobalException (EXC_DRIVERMISMATCH);
00500         emit saxDriverMismatch (cdb,cur);
00501 }
00502 } // end namespace

Generated on Mon Jun 19 12:42:49 2006 for libsax by  doxygen 1.4.6