Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Fred/Error/JErrorController.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__JErrorController_CPP__
00002 #define __J2K__JErrorController_CPP__
00003 
00004 //////////////////////////////////////////////////////////////////////
00005 //                                                                  //
00006 //  Notice:                                                         //
00007 //  -------                                                         //
00008 //                                                                  //
00009 //  We can't use JString or any other J2K classes,                  //
00010 //  since we are not sure, where the error occured                  //
00011 //  and so, we can only rely on ourself !                           // 
00012 //  Hoping that this class works well... =)                         //
00013 //                                                                  //
00014 //////////////////////////////////////////////////////////////////////
00015 
00016 #include <j2k/Fred/Error/JErrorController.hpp>
00017 
00018 
00019   JErrorController::JErrorController()
00020   {
00021     array = new JErrorHandler*[ __J2K__MAX_ERROR ];
00022 
00023   //////////////////////////////////////////////////////////////////////
00024   // Assign to each error the same Error Handler                      //
00025   // i.e. Print message and quit.                                     //
00026   //                                                                  //
00027   // A more evolued version is needed since some error are not fatal  //
00028   // and should only be advertise or logged into a error.log file,    //
00029   // and the program should be resume instead.                        //
00030   //////////////////////////////////////////////////////////////////////
00031     register int i = 0;
00032     defaultHandler = new JErrorHandler();
00033 
00034     for( ; i < __J2K__MAX_ERROR; i++ ) {
00035       array[ i ] = defaultHandler;
00036     }
00037   }
00038 
00039   JErrorController::~JErrorController() 
00040   {
00041     // Optimization compiler will surely use a register.
00042     register int i = 0;
00043     for( ; i < __J2K__MAX_ERROR; i++ ) {
00044         if ( array[i] != defaultHandler ) {
00045           delete array[ i ];  // Delete each node of the array
00046         }                     // Each JErrorHandler will delete
00047     }                         // the linked-list using cascade deletion.
00048     delete   defaultHandler;
00049     delete[] array;
00050   }
00051 
00052   //////////////////////////////////////////////////////////////////////
00053   // Someone has a problem with a known error                         //
00054   // and call us to resolve it !                                      //
00055   //////////////////////////////////////////////////////////////////////
00056   void JErrorController::call( 
00057     JErrorLevel level, int no, const char* errmsg,
00058                        int line,  const char* file )
00059   {
00060     register int n = (int)no;
00061 
00062     if ( n < 0 ) { n += __J2K__QB_OFFSET; }
00063     if ( EAGAIN       == 35     &&  n == 35    ) { n =  11; }
00064     if ( ENAMETOOLONG == 63     &&  n == 63    ) { n =  78; }
00065 
00066 #ifndef _WIN32
00067     if ( EWOULDBLOCK  == 35     &&  n == 35    ) { n =  11; }
00068     if ( EALREADY     == 37     &&  n == 37    ) { n = 149; }
00069     if ( EALREADY     == EBUSY  &&  n == EBUSY ) { n =  16; }
00070     if ( ELOOP        == 62     &&  n == 62    ) { n =  90; }
00071     if ( ESTALE       == 70     &&  n == 70    ) { n = 151; }
00072     if ( EREMOTE      == 71     &&  n == 71    ) { n =  66; }
00073     if ( EOPNOTSUPP   == 103    &&  n == 103   ) { n = 122; }
00074     if ( ESTALE       == 122    &&  n == 122   ) { n = 151; }
00075 #endif
00076 
00077     array[ n ]->elem( level, (JErrorNo)n, errmsg, line, file );
00078   }
00079 
00080   //////////////////////////////////////////////////////////////////////
00081   // Someone needs some specific handler for an error number          //
00082   // from now until it's removed.                                     //
00083   // The new error handler is added to the JErrorNo                   //
00084   // top of single Linked-List for that error number.                 //
00085   // The second argument is the static error handler                  //
00086   // that will be call if that error happen.                          //
00087   //////////////////////////////////////////////////////////////////////
00088   void JErrorController::add( 
00089     JErrorNo no, void (*fn)( MC_JErrorHandlerArg ), short id 
00090   )
00091   {
00092     // Optimization compiler will surely use a register.
00093     register int n = (int)no;
00094     JErrorHandler* newHandler = new JErrorHandler( fn, array[ n ], id );
00095     array[ n ] = newHandler;
00096   }
00097 
00098   //////////////////////////////////////////////////////////////////////
00099   // Someone doesn't need anymore                                     //
00100   // some specific handler for an error number.                       //
00101   // The new error handler is now removed from the                    //
00102   // top of single Linked-List for that error number.                 //
00103   //////////////////////////////////////////////////////////////////////
00104   void JErrorController::remove( JErrorNo no )
00105   {
00106     // Optimization compiler will surely use a register.
00107     register int n = (int)no;
00108     JErrorHandler* temp = array[n]->next;
00109 
00110       // Else temp gets deleted too.
00111       array[n]->next = NULL;
00112   
00113       if ( array[n] != defaultHandler ) {
00114         delete array[n];
00115       }
00116     array[n] = temp;
00117   }
00118 
00119   short JErrorController::getID( JErrorNo no ) 
00120   {
00121     register int n = (int)no;
00122     JErrorHandler* temp = array[n];
00123 
00124     if ( temp == NULL ) return -1;
00125 
00126     return temp->id;
00127   }
00128 
00129 #endif

Generated on Sun Oct 14 18:46:31 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001