Main Page Modules Class Hierarchy Data Structures File List Data Fields Globals Related Pages

# oscl_error.h

Go to the documentation of this file.

    00001 // -*- c++ -*-
    00002 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    00003
    00004 //               O S C L _ E R R O R
    00005
    00006 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    00007
    00018 #ifndef OSCL_ERROR_H_INCLUDED
    00019 #define OSCL_ERROR_H_INCLUDED
    00020
    00021 #ifndef OSCL_HEAPBASE_H_INCLUDED
    00022 #include "oscl_heapbase.h"
    00023 #endif
    00024
    00025 #ifndef OSCL_DEFALLOC_H_INCLUDED
    00026 #include "oscl_defalloc.h"
    00027 #endif
    00028
    00029 #ifndef OSCL_ERROR_CODES_H_INCLUDED
    00030 #include "oscl_error_codes.h"
    00031 #endif
    00032
    00036 class OsclErrorTrapImp;
    00037 class OsclErrorTrap
    00038 {
    00039     public:
    00047         OSCL_IMPORT_REF static int32 Init(Oscl_DefAlloc *aAlloc = NULL);
    00053         OSCL_IMPORT_REF static int32 Cleanup();
    00058         OSCL_IMPORT_REF static OsclErrorTrapImp* GetErrorTrapImp();
    00059 };
    00060
    00061
    00065 class OsclError
    00066 {
    00067     public:
    00074         OSCL_IMPORT_REF static void PushL(_OsclHeapBase * aPtr);
    00075
    00078         OSCL_IMPORT_REF static void PushL(OsclAny* aPtr);
    00079
    00082         OSCL_IMPORT_REF static void PushL(OsclTrapItem anItem);
    00083
    00086         OSCL_IMPORT_REF static void Pop();
    00087
    00090         OSCL_IMPORT_REF static void Pop(int32 aCount);
    00091
    00095         OSCL_IMPORT_REF static void PopDealloc();
    00096
    00099         OSCL_IMPORT_REF static void PopDealloc(int32 aCount);
    00100
    00106         OSCL_IMPORT_REF static void Leave(int32 aReason);
    00107
    00111         OSCL_IMPORT_REF static void LeaveIfNull(OsclAny *a);
    00112
    00117         OSCL_IMPORT_REF static void LeaveIfError(int32 aReason);
    00118
    00119 };
    00120
    00123 #define OSCL_TRAPSTACK_PUSH(a) OsclError::PushL(a)
    00124 #define OSCL_TRAPSTACK_POP() OsclError::Pop()
    00125 #define OSCL_TRAPSTACK_POPDEALLOC() OsclError::PopDealloc()
    00126
    00131 //Map TPVBaseErrorEnum return codes to Oscl Error leave codes
    00132 //Some of these codes indicate failure to init Oscl layer, in
    00133 //that case they map to zero and assert.
    00134 static const int32 _OsclBaseToErrorMap[] =
    00135 {
    00136     /*0*/OsclErrGeneral
    00137     ,/*EPVErrorBaseNotInstalled=1*/0
    00138     ,/*EPVErrorBaseAlreadyInstalled=2*/OsclErrAlreadyInstalled
    00139     ,/*EPVErrorBaseOutOfMemory=3*/OsclErrNoMemory
    00140     ,/*EPVErrorBaseSystemCallFailed=4*/OsclErrSystemCallFailed
    00141     ,/*EPVErrorBaseTooManyThreads=5*/0
    00142     ,/*EPVErrorBaseNotSupported=6*/OsclErrNotSupported
    00143     ,/*EPVErrorBaseNotReady=7*/OsclErrNotReady
    00144 };
    00145
    00146 #include "oscl_singleton.h"
    00147 #include "oscl_assert.h"
    00148 #if(OSCL_HAS_SINGLETON_SUPPORT)
    00149 class OsclSingletonRegistryEx
    00150 {
    00151     public:
    00152         /*
    00153         ** Get an entry
    00154         ** @param ID: identifier
    00155         ** @returns: the entry value
    00156         ** @exception: leaves on error.
    00157         */
    00158         static OsclAny* getInstance(uint32 ID)
    00159         {
    00160             int32 error;
    00161             OsclAny* val = OsclSingletonRegistry::getInstance(ID, error);
    00162             if (error)
    00163             {
    00164                 OSCL_ASSERT(_OsclBaseToErrorMap[error]);
    00165                 OsclError::Leave(_OsclBaseToErrorMap[error]);
    00166             }
    00167             return val;
    00168         }
    00169
    00170         /*
    00171         ** Set an entry
    00172         ** @param ID: identifier
    00173         ** @returns: the entry value
    00174         ** @exception: leaves on error.
    00175         */
    00176         static void registerInstance(OsclAny* ptr, uint32 ID)
    00177         {
    00178             int32 error;
    00179             OsclSingletonRegistry::registerInstance(ptr, ID, error);
    00180             if (error)
    00181             {
    00182                 OSCL_ASSERT(_OsclBaseToErrorMap[error]);
    00183                 OsclError::Leave(_OsclBaseToErrorMap[error]);
    00184             }
    00185         }
    00186
    00187         /*
    00188         //These two APIs can be used to do "test and set" operations on a singleton.
    00189         //Be sure to always call both APIs to avoid deadlock.
    00190         */
    00191
    00192         /*
    00193         * Return the current value of the singleton and leave the singleton table locked
    00194         * on return.
    00195         * @param ID the singleton ID
    00196         * @returns the singleton value.
    00197         ** @exception: leaves on error.
    00198         */
    00199         static OsclAny* lockAndGetInstance(uint32 ID)
    00200         {
    00201             int32 error;
    00202             OsclAny* val = OsclSingletonRegistry::lockAndGetInstance(ID, error);
    00203             if (error)
    00204             {
    00205                 OSCL_ASSERT(_OsclBaseToErrorMap[error]);
    00206                 OsclError::Leave(_OsclBaseToErrorMap[error]);
    00207             }
    00208             return val;
    00209         }
    00210
    00211         /*
    00212         * Set the value of the singleton.  Assume the singleton table is locked on entry.
    00213         * @param ptr the singleton value
    00214         * @param ID the singleton ID
    00215         ** @exception: leaves on error.
    00216         */
    00217         static void registerInstanceAndUnlock(OsclAny* ptr, uint32 ID)
    00218         {
    00219             int32 error;
    00220             OsclSingletonRegistry::registerInstanceAndUnlock(ptr, ID, error);
    00221             if (error)
    00222             {
    00223                 OSCL_ASSERT(_OsclBaseToErrorMap[error]);
    00224                 OsclError::Leave(_OsclBaseToErrorMap[error]);
    00225             }
    00226         }
    00227 };
    00228
    00229 template < class T, uint32 ID, class Registry = OsclSingletonRegistryEx > class OsclSingletonEx
    00230 {
    00231     private:
    00232         // make the copy constructor and assignment operator private
    00233         OsclSingletonEx& operator=(OsclSingletonEx& _Y)
    00234         {
    00235             return(*this);
    00236         }
    00237
    00238     protected:
    00239         T* _Ptr;
    00240
    00241     public:
    00242         OsclSingletonEx(): _Ptr(OSCL_STATIC_CAST(T*, Registry::getInstance(ID))) {};
    00243
    00244         ~OsclSingletonEx() {};
    00245
    00253         T& operator*() const
    00254         {
    00255             return(*_Ptr);
    00256         }
    00257
    00265         T *operator->() const
    00266         {
    00267             return(_Ptr);
    00268         }
    00269
    00270
    00277         bool set()
    00278         {
    00279             _Ptr = OSCL_STATIC_CAST(T*, Registry::getInstance(ID));
    00280             return (_Ptr ? true : false);
    00281         }
    00282
    00283 };
    00284 #endif //OSCL_HAS_SINGLETON_SUPPORT
    00285
    00286 #include "oscl_tls.h"
    00287 #include "oscl_assert.h"
    00288 class OsclTLSRegistryEx
    00289 {
    00290     public:
    00291         /*
    00292         ** Get an entry
    00293         ** @param ID: identifier
    00294         ** @returns: the entry value
    00295         ** @exception: leaves on error.
    00296         */
    00297         static OsclAny* getInstance(uint32 ID)
    00298         {
    00299             int32 error;
    00300             OsclAny* val = OsclTLSRegistry::getInstance(ID, error);
    00301             if (error)
    00302             {
    00303                 OSCL_ASSERT(_OsclBaseToErrorMap[error]);
    00304                 OsclError::Leave(_OsclBaseToErrorMap[error]);
    00305             }
    00306             return val;
    00307         }
    00308         /*
    00309         ** Set an entry
    00310         ** @param ID: identifier
    00311         ** @returns: the entry value
    00312         ** @exception: leaves on error.
    00313         */
    00314         static void registerInstance(OsclAny* ptr, uint32 ID)
    00315         {
    00316             int32 error;
    00317             OsclTLSRegistry::registerInstance(ptr, ID, error);
    00318             if (error)
    00319             {
    00320                 OSCL_ASSERT(_OsclBaseToErrorMap[error]);
    00321                 OsclError::Leave(_OsclBaseToErrorMap[error]);
    00322             }
    00323         }
    00324 };
    00325
    00326 template < class T, uint32 ID, class Registry = OsclTLSRegistryEx > class OsclTLSEx
    00327 {
    00328     private:
    00329         // make the copy constructor and assignment operator private
    00330         OsclTLSEx& operator=(OsclTLSEx& _Y)
    00331         {
    00332             return(*this);
    00333         }
    00334
    00335     protected:
    00336         T* _Ptr;
    00337
    00338     public:
    00339         OsclTLSEx(): _Ptr(OSCL_STATIC_CAST(T*, Registry::getInstance(ID))) {};
    00340
    00341         ~OsclTLSEx() {};
    00342
    00350         T& operator*() const
    00351         {
    00352             return(*_Ptr);
    00353         }
    00354
    00362         T *operator->() const
    00363         {
    00364             return(_Ptr);
    00365         }
    00366
    00367
    00374         bool set()
    00375         {
    00376             _Ptr = OSCL_STATIC_CAST(T*, Registry::getInstance(ID));
    00377             return (_Ptr ? true : false);
    00378         }
    00379
    00380 };
    00381
    00382 #endif
    00383