switch Cyclone to submodule on it's own git repo
[picodrive.git] / platform / uiq2 / audio / mediaserver / polledas.cpp
CommitLineData
cc68a136 1/*******************************************************************\r
2 *\r
3 * File: PolledAS.cpp\r
4 *\r
5 * Author: Peter van Sebille (peter@yipton.net)\r
6 *\r
7 * (c) Copyright 2002, Peter van Sebille\r
8 * All Rights Reserved\r
9 *\r
10 *******************************************************************/\r
11\r
12/*\r
13 * Oh Lord, forgive me for I have sinned.\r
14 * In their infinite wisdom, Symbian Engineers have decided that\r
15 * the Active Scheduler's queue of Active Objects is private\r
16 * and no getters are provided... sigh.\r
17 * This mere mortal will have to excercise the power of C pre-processor \r
18 * once more to circumvent the will of the gods.\r
19 */\r
20\r
21\r
22#include <e32std.h>\r
23\r
24// from e32base.h\r
25class CBase\r
26 {\r
27public:\r
28 IMPORT_C virtual ~CBase();\r
29 inline TAny* operator new(TUint aSize,TAny *aBase) {Mem::FillZ(aBase,aSize);return(aBase);}\r
30 IMPORT_C TAny* operator new(TUint aSize);\r
31 inline TAny* operator new(TUint aSize, TLeave) {return newL(aSize);}\r
32 IMPORT_C TAny* operator new(TUint aSize,TUint anExtraSize);\r
33protected:\r
34 IMPORT_C CBase();\r
35private:\r
36 CBase(const CBase&);\r
37 CBase& operator=(const CBase&);\r
38 IMPORT_C static TAny* newL(TUint aSize);\r
39 };\r
40\r
41class CActive : public CBase\r
42 {\r
43public:\r
44enum TPriority\r
45 {\r
46 EPriorityIdle=-100,\r
47 EPriorityLow=-20,\r
48 EPriorityStandard=0,\r
49 EPriorityUserInput=10,\r
50 EPriorityHigh=20,\r
51 };\r
52public:\r
53 IMPORT_C ~CActive();\r
54 IMPORT_C void Cancel();\r
55 IMPORT_C void Deque();\r
56 IMPORT_C void SetPriority(TInt aPriority);\r
57 inline TBool IsActive() const {return(iActive);}\r
58 inline TBool IsAdded() const {return(iLink.iNext!=NULL);}\r
59 inline TInt Priority() const {return iLink.iPriority;}\r
60protected:\r
61 IMPORT_C CActive(TInt aPriority);\r
62 IMPORT_C void SetActive();\r
63// Pure virtual\r
64 virtual void DoCancel() =0;\r
65 virtual void RunL() =0;\r
66 IMPORT_C virtual TInt RunError(TInt aError);\r
67public:\r
68 TRequestStatus iStatus;\r
69private:\r
70 TBool iActive;\r
71 TPriQueLink iLink;\r
72 friend class CActiveScheduler;\r
73// friend class CServer;\r
74 friend class CPrivatePolledActiveScheduler; // added\r
75 };\r
76\r
77class CActiveScheduler : public CBase\r
78 {\r
79public:\r
80 IMPORT_C CActiveScheduler();\r
81 IMPORT_C ~CActiveScheduler();\r
82 IMPORT_C static void Install(CActiveScheduler* aScheduler);\r
83 IMPORT_C static CActiveScheduler* Current();\r
84 IMPORT_C static void Add(CActive* anActive);\r
85 IMPORT_C static void Start();\r
86 IMPORT_C static void Stop();\r
87 IMPORT_C static TBool RunIfReady(TInt& aError, TInt aMinimumPriority);\r
88 IMPORT_C static CActiveScheduler* Replace(CActiveScheduler* aNewActiveScheduler);\r
89 IMPORT_C virtual void WaitForAnyRequest();\r
90 IMPORT_C virtual void Error(TInt anError) const;\r
91private:\r
92 void DoStart();\r
93 void OwnedStartLoop(TInt& aRunning);\r
94 IMPORT_C virtual void OnStarting();\r
95 IMPORT_C virtual void OnStopping();\r
96 IMPORT_C virtual void Reserved_1();\r
97 IMPORT_C virtual void Reserved_2();\r
98 friend class CPrivatePolledActiveScheduler; // added\r
99private:\r
100 // private interface used through by CActiveSchedulerWait objects\r
101 friend class CActiveSchedulerWait;\r
102 static void OwnedStart(CActiveSchedulerWait& aOwner);\r
103protected:\r
104 inline TInt Level() const {return(iLevel);}\r
105private:\r
106 TInt iLevel;\r
107 TPriQue<CActive> iActiveQ;\r
108 };\r
109\r
110class TCleanupItem;\r
111class CleanupStack\r
112 {\r
113public:\r
114 IMPORT_C static void PushL(TAny* aPtr);\r
115 IMPORT_C static void PushL(CBase* aPtr);\r
116 IMPORT_C static void PushL(TCleanupItem anItem);\r
117 IMPORT_C static void Pop();\r
118 IMPORT_C static void Pop(TInt aCount);\r
119 IMPORT_C static void PopAndDestroy();\r
120 IMPORT_C static void PopAndDestroy(TInt aCount);\r
121 IMPORT_C static void Check(TAny* aExpectedItem);\r
122 inline static void Pop(TAny* aExpectedItem);\r
123 inline static void Pop(TInt aCount, TAny* aLastExpectedItem);\r
124 inline static void PopAndDestroy(TAny* aExpectedItem);\r
125 inline static void PopAndDestroy(TInt aCount, TAny* aLastExpectedItem);\r
126 };\r
127\r
128\r
129/*\r
130 * This will declare CPrivatePolledActiveScheduler as a friend\r
131 * of all classes that define a friend. CPrivatePolledActiveScheduler needs to\r
132 * be a friend of CActive\r
133 */\r
134//#define friend friend class CPrivatePolledActiveScheduler; friend\r
135\r
136\r
137/*\r
138 * This will change the:\r
139 * void DoStart();\r
140 * method in CActiveScheduler to:\r
141 * void DoStart(); friend class CPrivatePolledActiveScheduler;\r
142 * We need this to access the private datamembers in CActiveScheduler.\r
143 */\r
144//#define DoStart() DoStart(); friend class CPrivatePolledActiveScheduler;\r
145//#include <e32base.h>\r
146#include "PolledAS.h"\r
147\r
148\r
149class CPrivatePolledActiveScheduler : public CActiveScheduler\r
150{\r
151public:\r
152 void Schedule();\r
153};\r
154\r
155\r
156\r
157void CPrivatePolledActiveScheduler::Schedule()\r
158{\r
159 TDblQueIter<CActive> q(iActiveQ);\r
160 q.SetToFirst();\r
161 FOREVER\r
162 {\r
163 CActive *pR=q++;\r
164 if (pR)\r
165 {\r
166 if (pR->IsActive() && pR->iStatus!=KRequestPending)\r
167 {\r
168 pR->iActive=EFalse;\r
169 TRAPD(r,pR->RunL());\r
170 break;\r
171 }\r
172 }\r
173 else\r
174 break;\r
175 }\r
176}\r
177\r
178\r
179CPolledActiveScheduler::~CPolledActiveScheduler()\r
180{\r
181 delete iPrivatePolledActiveScheduler;\r
182}\r
183\r
184//static CPolledActiveScheduler* sPolledActiveScheduler = NULL;\r
185CPolledActiveScheduler* CPolledActiveScheduler::NewL()\r
186{\r
187 //sPolledActiveScheduler = \r
188 CPolledActiveScheduler* self = new(ELeave)CPolledActiveScheduler;\r
189 CleanupStack::PushL(self);\r
190 self->ConstructL();\r
191 CleanupStack::Pop();\r
192 return self;\r
193}\r
194\r
195void CPolledActiveScheduler::ConstructL()\r
196{\r
197 iPrivatePolledActiveScheduler = new(ELeave) CPrivatePolledActiveScheduler;\r
198 iPrivatePolledActiveScheduler->Install(iPrivatePolledActiveScheduler);\r
199}\r
200\r
201\r
202void CPolledActiveScheduler::Schedule()\r
203{\r
204 iPrivatePolledActiveScheduler->Schedule();\r
205}\r
206\r
207/*\r
208CPolledActiveScheduler* CPolledActiveScheduler::Instance()\r
209{\r
210// return (CPolledActiveScheduler*) CActiveScheduler::Current();\r
211 return sPolledActiveScheduler;\r
212}\r
213*/\r