• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3<title>oscl_singleton.h Source File</title>
4<link href="doxygen.css" rel="stylesheet" type="text/css">
5</head><body>
6<!-- Generated by Doxygen 1.2.18 -->
7<center>
8<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; </center>
9<hr><h1>oscl_singleton.h</h1><a href="oscl__singleton_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">// -*- c++ -*-</span>
1000002 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
1100003
1200004 <span class="comment">//                     O S C L _ S I N G L E T O N</span>
1300005
1400006 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
1500007
1600020 <span class="preprocessor">#ifndef OSCL_SINGLETON_H_INCLUDED</span>
1700021 <span class="preprocessor"></span><span class="preprocessor">#define OSCL_SINGLETON_H_INCLUDED</span>
1800022 <span class="preprocessor"></span>
1900023 <span class="preprocessor">#ifndef OSCL_BASE_H_INCLUDED</span>
2000024 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__base_8h.html">oscl_base.h</a>"</span>
2100025 <span class="preprocessor">#endif</span>
2200026 <span class="preprocessor"></span>
2300027 <span class="preprocessor">#ifndef OSCL_DEFALLOC_H_INCLUDED</span>
2400028 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__defalloc_8h.html">oscl_defalloc.h</a>"</span>
2500029 <span class="preprocessor">#endif</span>
2600030 <span class="preprocessor"></span>
2700031
2800032 <span class="preprocessor">#if (OSCL_HAS_SINGLETON_SUPPORT)</span>
2900033 <span class="preprocessor"></span>
3000034 <span class="comment">//verify config-- singleton support requires global var support</span>
3100035
3200036 <span class="comment">// list of singleton objects</span>
33<a name="l00037"></a><a class="code" href="oscl__singleton_8h.html#a0">00037</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a0">OSCL_SINGLETON_ID_TEST</a>           =  0;
34<a name="l00038"></a><a class="code" href="oscl__singleton_8h.html#a1">00038</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a1">OSCL_SINGLETON_ID_OSCLMEM</a>        =  1;
35<a name="l00039"></a><a class="code" href="oscl__singleton_8h.html#a2">00039</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a2">OSCL_SINGLETON_ID_PVLOGGER</a>       =  2;
36<a name="l00040"></a><a class="code" href="oscl__singleton_8h.html#a3">00040</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a3">OSCL_SINGLETON_ID_PVSCHEDULER</a>    =  3;
37<a name="l00041"></a><a class="code" href="oscl__singleton_8h.html#a4">00041</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a4">OSCL_SINGLETON_ID_PVERRORTRAP</a>    =  4;
38<a name="l00042"></a><a class="code" href="oscl__singleton_8h.html#a5">00042</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a5">OSCL_SINGLETON_ID_SDPMEDIAPARSER</a> =  5;
39<a name="l00043"></a><a class="code" href="oscl__singleton_8h.html#a6">00043</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a6">OSCL_SINGLETON_ID_PAYLOADPARSER</a>  =  6;
40<a name="l00044"></a><a class="code" href="oscl__singleton_8h.html#a7">00044</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a7">OSCL_SINGLETON_ID_CPM_PLUGIN</a>     =  7;
41<a name="l00045"></a><a class="code" href="oscl__singleton_8h.html#a8">00045</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a8">OSCL_SINGLETON_ID_PVMFRECOGNIZER</a> =  8;
42<a name="l00046"></a><a class="code" href="oscl__singleton_8h.html#a9">00046</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a9">OSCL_SINGLETON_ID_OSCLREGISTRY</a>   =  9;
43<a name="l00047"></a><a class="code" href="oscl__singleton_8h.html#a10">00047</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a10">OSCL_SINGLETON_ID_OMX</a>            = 10;
44<a name="l00048"></a><a class="code" href="oscl__singleton_8h.html#a11">00048</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a11">OSCL_SINGLETON_ID_OMXMASTERCORE</a>  = 11;
45<a name="l00049"></a><a class="code" href="oscl__singleton_8h.html#a12">00049</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a12">OSCL_SINGLETON_ID_TICKCOUNT</a>      = 12;
46<a name="l00050"></a><a class="code" href="oscl__singleton_8h.html#a13">00050</a> <span class="keyword">const</span> uint32 <a class="code" href="oscl__singleton_8h.html#a13">OSCL_SINGLETON_ID_LAST</a>           = 13;
4700051
4800052
49<a name="l00053"></a><a class="code" href="classOsclSingletonRegistry.html">00053</a> <span class="keyword">class </span><a class="code" href="classOsclSingletonRegistry.html">OsclSingletonRegistry</a>
5000054 {
5100055     <span class="keyword">public</span>:
5200056         <span class="comment">/*</span>
5300057 <span class="comment">        ** Get an entry</span>
5400058 <span class="comment">        ** @param ID: identifier</span>
5500059 <span class="comment">        ** @param error (output) 0 for success or an error from TPVBaseErrorEnum</span>
5600060 <span class="comment">        ** @returns: the entry value</span>
5700061 <span class="comment">        */</span>
5800062         OSCL_IMPORT_REF <span class="keyword">static</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* <a class="code" href="classOsclSingletonRegistry.html#d0">getInstance</a>(uint32 ID, int32 &amp;error);
5900063         <span class="comment">/*</span>
6000064 <span class="comment">        ** Set an entry</span>
6100065 <span class="comment">        ** @param ID: identifier</span>
6200066 <span class="comment">        ** @param error (output) 0 for success or an error from TPVBaseErrorEnum</span>
6300067 <span class="comment">        ** @returns: the entry value</span>
6400068 <span class="comment">        */</span>
6500069         OSCL_IMPORT_REF <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classOsclSingletonRegistry.html#d1">registerInstance</a>(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* ptr, uint32 ID, int32 &amp;error);
6600070
6700071         <span class="comment">/*</span>
6800072 <span class="comment">        //These two APIs can be used to do "test and set" operations on a singleton.</span>
6900073 <span class="comment">        //Be sure to always call both APIs to avoid deadlock.</span>
7000074 <span class="comment">        */</span>
7100075
7200076         <span class="comment">/*</span>
7300077 <span class="comment">        * Return the current value of the singleton and leave the singleton table locked</span>
7400078 <span class="comment">        * on return.</span>
7500079 <span class="comment">        * @param ID the singleton ID</span>
7600080 <span class="comment">        ** @param error (output) 0 for success or an error from TPVBaseErrorEnum</span>
7700081 <span class="comment">        * @returns the singleton value.</span>
7800082 <span class="comment">        */</span>
7900083         OSCL_IMPORT_REF <span class="keyword">static</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* <a class="code" href="classOsclSingletonRegistry.html#d2">lockAndGetInstance</a>(uint32 ID, int32&amp; error);
8000084         <span class="comment">/*</span>
8100085 <span class="comment">        * Set the value of the singleton.  Assume the singleton table is locked on entry.</span>
8200086 <span class="comment">        * @param ptr the singleton value</span>
8300087 <span class="comment">        * @param ID the singleton ID</span>
8400088 <span class="comment">        ** @param error (output) 0 for success or an error from TPVBaseErrorEnum</span>
8500089 <span class="comment">        */</span>
8600090         OSCL_IMPORT_REF <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classOsclSingletonRegistry.html#d3">registerInstanceAndUnlock</a>(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* ptr, uint32 ID, int32&amp; error);
8700091
8800092     <span class="keyword">private</span>:
8900093         <a class="code" href="classOsclSingletonRegistry.html">OsclSingletonRegistry</a>()
9000094         {}
9100095         <span class="keyword">typedef</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* registry_type;
9200096         <span class="keyword">typedef</span> registry_type* registry_pointer_type;
9300097
9400098     <span class="keyword">private</span>:
9500099         OSCL_IMPORT_REF <span class="keyword">static</span> <span class="keywordtype">void</span> initialize(<a class="code" href="classOscl__DefAlloc.html">Oscl_DefAlloc</a> &amp;alloc, int32 &amp;error);
9600100         OSCL_IMPORT_REF <span class="keyword">static</span> <span class="keywordtype">void</span> cleanup(<a class="code" href="classOscl__DefAlloc.html">Oscl_DefAlloc</a> &amp;alloc, int32 &amp;error);
97<a name="l00101"></a><a class="code" href="classOsclSingletonRegistry.html#l0">00101</a>         <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classOsclSingletonRegistry.html#l0">OsclBase</a>;
9800102
9900103     <span class="keyword">private</span>:
10000104         <span class="keyword">class </span>SingletonTable
10100105         {
10200106             <span class="keyword">public</span>:
10300107                 SingletonTable(): iRefCount(0)
10400108                 {
10500109                     <span class="keywordflow">for</span> (uint32 i = 0;i &lt; <a class="code" href="oscl__singleton_8h.html#a13">OSCL_SINGLETON_ID_LAST</a>;i++)
10600110                         iSingletons[i] = <a class="code" href="group__osclbase.html#a81">NULL</a>;
10700111                 }
10800112                 _OsclBasicLock iTableLock;
10900113                 uint32 iRefCount;
11000114                 <a class="code" href="group__osclbase.html#a25">OsclAny</a>* iSingletons[<a class="code" href="oscl__singleton_8h.html#a13">OSCL_SINGLETON_ID_LAST</a>];
11100115                 _OsclBasicLock iSingletonLocks[<a class="code" href="oscl__singleton_8h.html#a13">OSCL_SINGLETON_ID_LAST</a>];
11200116         };
11300117         <span class="comment">//The singleton table is a global variable.</span>
11400118         <span class="keyword">static</span> SingletonTable* iSingletonTable;
11500119 };
116<a name="l00120"></a><a class="code" href="classOsclSingleton.html">00120</a>
11700121 <span class="keyword">template</span> &lt; <span class="keyword">class</span> T, u<span class="keywordtype">int</span>32 ID, <span class="keyword">class</span> Registry = OsclSingletonRegistry &gt; <span class="keyword">class </span><a class="code" href="classOsclSingleton.html">OsclSingleton</a>
11800122 {
11900123     <span class="keyword">private</span>:
12000124         <span class="comment">// make the copy constructor and assignment operator private</span>
12100125         <a class="code" href="classOsclSingleton.html">OsclSingleton</a>&amp; operator=(<a class="code" href="classOsclSingleton.html">OsclSingleton</a>&amp; _Y)
12200126         {
12300127             <span class="keywordflow">return</span>(*this);
12400128         }
12500129
126<a name="l00130"></a><a class="code" href="classOsclSingleton.html#n0">00130</a>     <span class="keyword">protected</span>:
12700131         T* <a class="code" href="classOsclSingleton.html#n0">_Ptr</a>;
12800132
129<a name="l00133"></a><a class="code" href="classOsclSingleton.html#a0">00133</a>     <span class="keyword">public</span>:
13000134         <a class="code" href="classOsclSingleton.html#a0">OsclSingleton</a>()
13100135         {
13200136             int32 err;
13300137             <a class="code" href="classOsclSingleton.html#n0">_Ptr</a> = <a class="code" href="group__osclbase.html#a86">OSCL_STATIC_CAST</a>(T*, Registry::getInstance(ID, err));
13400138         }
135<a name="l00139"></a><a class="code" href="classOsclSingleton.html#a1">00139</a>
13600140         <a class="code" href="classOsclSingleton.html#a1">~OsclSingleton</a>() {};
13700141
13800149         T&amp; <a class="code" href="classOsclSingleton.html#a2">operator*</a>()<span class="keyword"> const</span>
13900150 <span class="keyword">        </span>{
14000151             <span class="keywordflow">return</span>(*_Ptr);
14100152         }
14200153
14300161         T *<a class="code" href="classOsclSingleton.html#a3">operator-&gt;</a>()<span class="keyword"> const</span>
14400162 <span class="keyword">        </span>{
14500163             <span class="keywordflow">return</span>(_Ptr);
14600164         }
14700165
14800166
14900173         <span class="keywordtype">bool</span> <a class="code" href="classOsclSingleton.html#a4">set</a>()
15000174         {
15100175             int32 err;
15200176             <a class="code" href="classOsclSingleton.html#n0">_Ptr</a> = <a class="code" href="group__osclbase.html#a86">OSCL_STATIC_CAST</a>(T*, Registry::getInstance(ID, err));
15300177             <span class="keywordflow">return</span> (<a class="code" href="classOsclSingleton.html#n0">_Ptr</a> ? <span class="keyword">true</span> : <span class="keyword">false</span>);
15400178         }
15500179
15600180 };
15700181
15800182
15900183 <span class="preprocessor">#endif //OSCL_HAS_SINGLETON_SUPPORT</span>
16000184 <span class="preprocessor"></span>
16100185 <span class="preprocessor">#endif</span>
16200186 <span class="preprocessor"></span>
163</pre></div><hr size="1"><img src="pvlogo_small.jpg"><address style="align: right;"><small>OSCL API</small>
164<address style="align: left;"><small>Posting Version: OPENCORE_20090310 </small>
165</small></address>
166</body>
167</html>
168