Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 // -*- c++ -*-
     19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
     20 
     21 //                           O S C L _ B A S E
     22 
     23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
     24 
     25 /*! \addtogroup osclbase OSCL Base
     26  *
     27  * @{
     28  */
     29 
     30 
     31 /*! \file oscl_base.h
     32     \brief The file oscl_base.h is the public header that should be included to pick up the platform configuration, basic type definitions, and common macros.*/
     33 
     34 
     35 #ifndef OSCL_BASE_H_INCLUDED
     36 #define OSCL_BASE_H_INCLUDED
     37 
     38 #include "osclconfig.h"
     39 #include "oscl_base_macros.h"
     40 #include "oscl_types.h"
     41 #include "osclconfig_check.h"
     42 
     43 #ifdef USE_CML2_CONFIG
     44 #include "pv_config.h"
     45 #endif
     46 
     47 //singleton support derives from global var support.
     48 #define OSCL_HAS_SINGLETON_SUPPORT 1
     49 
     50 #ifdef __cplusplus
     51 
     52 class OsclLockBase;
     53 
     54 class OsclBase
     55 {
     56     public:
     57         /**
     58          * Initializes OsclBase functionality.
     59          * OsclBase must be initialized before any OsclBase
     60          * functionality can be used.
     61          *
     62          * Note: The first call to OsclBase::Init will initialize
     63          *  the thread lock that is used to avoid thread contention
     64          *  for process scope singleton access.  The last call to
     65          *  OsclBase::Cleanup will cleanup the thread lock.
     66          *  Case should be taken to avoid possible thread contention
     67          *  on the first Init and the last Cleanup call.
     68          *
     69          * @return 0 on success
     70          */
     71         OSCL_IMPORT_REF static int32 Init();
     72 
     73         /**
     74          * Cleanup OsclBase functionality
     75          * OsclBase should be cleaned once OsclBase
     76          * functions are no longer needed
     77          * @return 0 on success
     78          */
     79         OSCL_IMPORT_REF static int32 Cleanup();
     80 };
     81 
     82 /**
     83 //OsclBase error codes.  These values are used as return codes for OsclBase, OsclTLSRegistry,
     84 //and OsclSingletonRegistry.
     85 //Maintenance note: _OsclBaseToErrorMap in oscl_error must match this list
     86 */
     87 enum TPVBaseErrorEnum
     88 {
     89     EPVErrorBaseNotInstalled = 1
     90     , EPVErrorBaseAlreadyInstalled = 2
     91     , EPVErrorBaseOutOfMemory = 3
     92     , EPVErrorBaseSystemCallFailed = 4
     93     , EPVErrorBaseTooManyThreads = 5
     94 };
     95 
     96 #include "oscl_lock_base.h"
     97 
     98 /**
     99  * _OsclBasicLock is a simple thread lock class for internal use by
    100  * OsclTLSRegistry and OsclSingleton.
    101  * Higher-level code should use OsclMutex instead.
    102  */
    103 #if (OSCL_HAS_BASIC_LOCK)
    104 class _OsclBasicLock : public OsclLockBase
    105 {
    106     public:
    107 
    108         /**
    109          * Class constructor.
    110          */
    111         OSCL_IMPORT_REF _OsclBasicLock();
    112 
    113         /**
    114          * Class destructor
    115          */
    116         OSCL_IMPORT_REF ~_OsclBasicLock();
    117 
    118         /**
    119          * Takes the lock
    120          *
    121          */
    122         OSCL_IMPORT_REF void Lock();
    123 
    124         /**
    125          * Releases the lock
    126          *
    127          */
    128         OSCL_IMPORT_REF void Unlock();
    129 
    130 
    131         /**
    132         * Set to non-zero on error
    133         */
    134         int32 iError;
    135 
    136     private:
    137         TOsclBasicLockObject    ObjLock;
    138 
    139 };
    140 #else
    141 typedef OsclNullLock _OsclBasicLock;
    142 #endif
    143 
    144 #else
    145 
    146 /**
    147  * Initializes OsclBase functionality.
    148  * OsclBase must be initialized before any OsclBase
    149  * functionality can be used.
    150  *
    151  * @exception leaves if out-of-memory
    152  */
    153 void PVOsclBase_Init();
    154 
    155 /**
    156  * Cleanup OsclBase functionality
    157  * OsclBase should be cleaned once OsclBase
    158  * functions are no longer needed
    159  */
    160 void PVOsclBase_Cleanup();
    161 
    162 #endif
    163 
    164 /*! @} */
    165 
    166 #endif  // OSCL_BASE_H_INCLUDED
    167