00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "exception.h"
00022
00023 namespace SaX {
00024
00025
00026
00027 volatile bool DEBUG = false;
00028
00029
00030
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
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
00067
00068 void SaXException::setDebug ( bool enable ) {
00069
00071
00072 DEBUG = enable;
00073 }
00074
00075
00076
00077
00078 void SaXException::setErrorCode (int id) {
00079
00082
00083 mErrorCode = id;
00084 QTextOStream (mErrorString) << strerror (mErrorCode);
00085 }
00086
00087
00088
00089
00090 void SaXException::setErrorCode (const char* msg, int id) {
00091
00094
00095 mErrorCode = id;
00096 QTextOStream (mErrorString) << msg;
00097 }
00098
00099
00100
00101
00102 void SaXException::setErrorValue ( int data ) {
00103
00105
00106 QTextOStream (mErrorValue) << data;
00107 }
00108
00109
00110
00111
00112 void SaXException::setErrorValue ( const char* data ) {
00113
00115
00116 QTextOStream (mErrorValue) << data;
00117 }
00118
00119
00120
00121
00122 void SaXException::setErrorValue ( void* data ) {
00123
00125
00126 QTextOStream (mErrorValue) << data;
00127 }
00128
00129
00130
00131
00132 void SaXException::errorReset ( void ) {
00133
00136
00137 mErrorCode = 0;
00138 QTextOStream (mErrorString) << strerror (mErrorCode);
00139 QTextOStream (mErrorValue) << "(null)";
00140 }
00141
00142
00143
00144
00145 int SaXException::errorCode ( void ) {
00146
00149
00150 return mErrorCode;
00151 }
00152
00153
00154
00155
00156 QString SaXException::errorString ( void ) {
00157
00160
00161 return QString::fromLocal8Bit(*mErrorString);
00162 }
00163
00164
00165
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
00180
00181 bool SaXException::havePrivileges (void) {
00182
00185
00186 if (! getuid() == 0) {
00187 return false;
00188 }
00189 return true;
00190 }
00191
00192
00193
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
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
00229
00231 void SaXException::excProcessFailed (void) {
00232 setErrorCode (EAGAIN);
00233 emit saxProcessFailed();
00234 }
00235
00237 void SaXException::excImportSectionFailed (void) {
00238 setErrorCode (EISAXIMPORT,EISAXIMPORTID);
00239 emit saxImportSectionFailed();
00240 }
00241
00243 void SaXException::excExportSectionFailed (void) {
00244 setErrorCode (EISAXEXPORT,EISAXEXPORTID);
00245 emit saxExportSectionFailed();
00246 }
00247
00249 void SaXException::excFileOpenFailed (int e) {
00250 setErrorCode (ENOENT);
00251 setErrorValue (e);
00252 emit saxFileOpenFailed (e);
00253 }
00254
00256 void SaXException::excNoStorage (int id) {
00257 setErrorCode (ENODATA);
00258 setErrorValue (id);
00259 emit saxNoStorage (id);
00260 }
00261
00263 void SaXException::excCDBFileFailed (void) {
00264 setErrorCode (ENOENT);
00265 emit saxCDBFileFailed ();
00266 }
00267
00269 void SaXException::excPermissionDenied (void) {
00270 setErrorCode (EACCES);
00271 emit saxPermissionDenied ();
00272 }
00273
00275 void SaXException::excProfileNotFound (void) {
00276 setErrorCode (ENOENT);
00277 emit saxProfileNotFound ();
00278 }
00279
00281 void SaXException::excProfileUndefined (int id) {
00282 setErrorCode (EPROFILE,EPROFILEID);
00283 setErrorValue (id);
00284 emit saxProfileUndefined (id);
00285 }
00286
00288 void SaXException::excImportAlreadyAdded (int id) {
00289 setErrorCode (EALREADY);
00290 setErrorValue (id);
00291 emit saxImportAlreadyAdded (id);
00292 }
00293
00295 void SaXException::excUnknownImport (SaXImport* in) {
00296 setErrorCode (EBADF);
00297 setErrorValue ((void*)in);
00298 emit saxUnknownImport (in);
00299 }
00300
00302 void SaXException::excNoAPIFileFound (void) {
00303 setErrorCode (ENOENT);
00304 emit saxNoAPIFileFound ();
00305 }
00306
00308 void SaXException::excNullPointerArgument (void) {
00309 setErrorCode (EINVAL);
00310 emit saxNullPointerArgument ();
00311 }
00312
00314 void SaXException::excDesktopImportBindFailed (int id) {
00315 setErrorCode (EBADF);
00316 setErrorValue (id);
00317 emit saxDesktopImportBindFailed (id);
00318 }
00319
00321 void SaXException::excCardImportBindFailed (int id) {
00322 setErrorCode (EBADF);
00323 setErrorValue (id);
00324 emit saxCardImportBindFailed (id);
00325 }
00326
00328 void SaXException::excPointerImportBindFailed (int id) {
00329 setErrorCode (EBADF);
00330 setErrorValue (id);
00331 emit saxPointerImportBindFailed (id);
00332 }
00333
00335 void SaXException::excKeyboardImportBindFailed (int id) {
00336 setErrorCode (EBADF);
00337 setErrorValue (id);
00338 emit saxKeyboardImportBindFailed (id);
00339 }
00340
00342 void SaXException::excPathImportBindFailed (int id) {
00343 setErrorCode (EBADF);
00344 setErrorValue (id);
00345 emit saxPathImportBindFailed (id);
00346 }
00347
00349 void SaXException::excExtensionsImportBindFailed (int id) {
00350 setErrorCode (EBADF);
00351 setErrorValue (id);
00352 emit saxExtensionsImportBindFailed (id);
00353 }
00354
00356 void SaXException::excLayoutImportBindFailed (int id) {
00357 setErrorCode (EBADF);
00358 setErrorValue (id);
00359 emit saxLayoutImportBindFailed (id);
00360 }
00361
00363 void SaXException::excXKBLoadRulesFailed (void) {
00364 setErrorCode (ENOENT);
00365 emit saxXKBLoadRulesFailed ();
00366 }
00367
00369 void SaXException::excCDBRecordNotFound (const char* group) {
00370 setErrorCode (ECDBGROUP,ECDBGROUPID);
00371 setErrorValue (group);
00372 emit saxCDBRecordNotFound (group);
00373 }
00374
00376 void SaXException::excWrongInputFashion (const char* fashion) {
00377 setErrorCode (EFASHION,EFASHIONID);
00378 setErrorValue (fashion);
00379 emit saxWrongInputFashion (fashion);
00380 }
00381
00383 void SaXException::excSetStorageIDFailed (int id) {
00384 setErrorCode (ERECORD,ERECORDID);
00385 setErrorValue (id);
00386 emit saxSetStorageIDFailed (id);
00387 }
00388
00390 void SaXException::excPointerFashionTypeFailed (const char* fashion) {
00391 setErrorCode (EFASHION,EFASHIONID);
00392 setErrorValue (fashion);
00393 emit saxPointerFashionTypeFailed (fashion);
00394 }
00395
00397 void SaXException::excInvalidArgument (int id) {
00398 setErrorCode (EINVAL);
00399 setErrorValue (id);
00400 emit saxInvalidArgument (id);
00401 }
00402
00404 void SaXException::excInvalidArgument (const char* arg) {
00405 setErrorCode (EINVAL);
00406 setErrorValue (arg);
00407 emit saxInvalidArgument (arg);
00408 }
00409
00411 void SaXException::excLockSetFailed (int error) {
00412 setErrorCode (error);
00413 emit saxLockSetFailed (error);
00414 }
00415
00417 void SaXException::excLockUnsetFailed (int error) {
00418 setErrorCode (error);
00419 emit saxLockUnsetFailed (error);
00420 }
00421
00423 void SaXException::excGetScreenLayoutFailed (int id) {
00424 setErrorCode (ESCREEN,ESCREENID);
00425 setErrorValue (id);
00426 emit saxGetScreenLayoutFailed (id);
00427 }
00428
00430 void SaXException::excGetInputLayoutFailed (void) {
00431 setErrorCode (ENODEV);
00432 emit saxGetInputLayoutFailed();
00433 }
00434
00436 void SaXException::excEmptyCDBGroup (const char* name) {
00437 setErrorCode (ECDBDATA,ECDBDATAID);
00438 setErrorValue (name);
00439 emit saxEmptyCDBGroup (name);
00440 }
00441
00443 void SaXException::excNvidiaDriverMissing ( void ) {
00444 setErrorCode (ENVIDIAMIS,ENVIDIAMISID);
00445 emit saxNvidiaDriverMissing();
00446 }
00447
00449 void SaXException::excNvidiaDriverInstalled ( void ) {
00450 setErrorCode (ENVIDIAINS,ENVIDIAINSID);
00451 emit saxNvidiaDriverInstalled();
00452 }
00453
00455 void SaXException::excXKBLayoutUndefined ( const char* layout ) {
00456 setErrorCode (EXKBLAYOUT,EXKBLAYOUTID);
00457 emit saxXKBLayoutUndefined (layout);
00458 }
00460 void SaXException::excDriverMismatch ( const char* cdb,const char* cur) {
00461 setErrorCode (ECDBMISMATCH,ECDBMISMATCHID);
00462 setErrorValue (QString(cdb)+" -> "+QString(cur));
00463 emit saxDriverMismatch (cdb,cur);
00464 }
00465 }