1 /*******************************************************************
\r
5 * Author: Peter van Sebille (peter@yipton.net)
\r
7 * (c) Copyright 2002, Peter van Sebille
\r
8 * All Rights Reserved
\r
10 *******************************************************************/
\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
32 IMPORT_C virtual ~CBase();
\r
33 inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW { Mem::FillZ(aBase, aSize); return aBase; }
\r
34 inline TAny* operator new(TUint aSize) __NO_THROW { return User::AllocZ(aSize); }
\r
35 inline TAny* operator new(TUint aSize, TLeave) { return User::AllocZL(aSize); }
\r
36 inline TAny* operator new(TUint aSize, TUint aExtraSize) { return User::AllocZ(aSize + aExtraSize); }
\r
37 inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize) { return User::AllocZL(aSize + aExtraSize); }
\r
38 IMPORT_C static void Delete(CBase* aPtr);
\r
40 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
\r
42 CBase(const CBase&);
\r
43 CBase& operator=(const CBase&);
\r
48 class TRequestStatusFaked
\r
51 inline TRequestStatusFaked() : iFlags(0) {};
\r
52 inline TRequestStatusFaked(TInt aVal) : iStatus(aVal), iFlags(aVal==KRequestPending ? TRequestStatusFaked::ERequestPending : 0) {}
\r
53 /* inline TInt operator=(TInt aVal);
\r
54 inline TBool operator==(TInt aVal) const;
\r
56 inline TBool operator!=(TInt aVal) const {return(iStatus!=aVal);}
\r
58 inline TBool operator>=(TInt aVal) const;
\r
59 inline TBool operator<=(TInt aVal) const;
\r
60 inline TBool operator>(TInt aVal) const;
\r
61 inline TBool operator<(TInt aVal) const;
\r
62 inline TInt Int() const;
\r
68 ERequestPending = 2, //bit1
\r
72 friend class CActive;
\r
73 friend class CActiveScheduler;
\r
74 friend class CServer2;
\r
78 class CActive : public CBase
\r
85 EPriorityStandard=0,
\r
86 EPriorityUserInput=10,
\r
90 IMPORT_C ~CActive();
\r
91 IMPORT_C void Cancel();
\r
92 IMPORT_C void Deque();
\r
93 IMPORT_C void SetPriority(TInt aPriority);
\r
94 inline TBool IsActive() const {return(iStatus.iFlags&TRequestStatus::EActive);}
\r
95 inline TBool IsAdded() const {return(iLink.iNext!=NULL);}
\r
96 inline TInt Priority() const {return iLink.iPriority;}
\r
98 IMPORT_C CActive(TInt aPriority);
\r
99 IMPORT_C void SetActive();
\r
100 virtual void DoCancel() =0;
\r
101 virtual void RunL() =0;
\r
102 IMPORT_C virtual TInt RunError(TInt aError);
\r
104 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
\r
106 TRequestStatusFaked iStatus; // hope this will work
\r
111 friend class CActiveScheduler;
\r
112 friend class CServer;
\r
113 friend class CServer2;
\r
114 friend class CPrivatePolledActiveScheduler; // added
\r
119 class CActiveScheduler : public CBase
\r
121 friend class CActiveSchedulerWait;
\r
124 typedef TLoop* TLoopOwner;
\r
126 IMPORT_C CActiveScheduler();
\r
127 IMPORT_C ~CActiveScheduler();
\r
128 IMPORT_C static void Install(CActiveScheduler* aScheduler);
\r
129 IMPORT_C static CActiveScheduler* Current();
\r
130 IMPORT_C static void Add(CActive* aActive);
\r
131 IMPORT_C static void Start();
\r
132 IMPORT_C static void Stop();
\r
133 IMPORT_C static TBool RunIfReady(TInt& aError, TInt aMinimumPriority);
\r
134 IMPORT_C static CActiveScheduler* Replace(CActiveScheduler* aNewActiveScheduler);
\r
135 IMPORT_C virtual void WaitForAnyRequest();
\r
136 IMPORT_C virtual void Error(TInt aError) const;
\r
137 IMPORT_C void Halt(TInt aExitCode) const;
\r
138 IMPORT_C TInt StackDepth() const;
\r
140 static void Start(TLoopOwner* aOwner);
\r
141 IMPORT_C virtual void OnStarting();
\r
142 IMPORT_C virtual void OnStopping();
\r
143 IMPORT_C virtual void Reserved_1();
\r
144 IMPORT_C virtual void Reserved_2();
\r
145 void Run(TLoopOwner* const volatile& aLoop);
\r
146 void DoRunL(TLoopOwner* const volatile& aLoop, CActive* volatile & aCurrentObj);
\r
147 friend class CPrivatePolledActiveScheduler; // added
\r
149 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
\r
151 inline TInt Level() const {return StackDepth();} // deprecated
\r
154 TPriQue<CActive> iActiveQ;
\r
160 class TCleanupItem;
\r
164 IMPORT_C static void PushL(TAny* aPtr);
\r
165 IMPORT_C static void PushL(CBase* aPtr);
\r
166 IMPORT_C static void PushL(TCleanupItem anItem);
\r
167 IMPORT_C static void Pop();
\r
168 IMPORT_C static void Pop(TInt aCount);
\r
169 IMPORT_C static void PopAndDestroy();
\r
170 IMPORT_C static void PopAndDestroy(TInt aCount);
\r
171 IMPORT_C static void Check(TAny* aExpectedItem);
\r
172 inline static void Pop(TAny* aExpectedItem);
\r
173 inline static void Pop(TInt aCount, TAny* aLastExpectedItem);
\r
174 inline static void PopAndDestroy(TAny* aExpectedItem);
\r
175 inline static void PopAndDestroy(TInt aCount, TAny* aLastExpectedItem);
\r
180 * This will declare CPrivatePolledActiveScheduler as a friend
\r
181 * of all classes that define a friend. CPrivatePolledActiveScheduler needs to
\r
182 * be a friend of CActive
\r
184 //#define friend friend class CPrivatePolledActiveScheduler; friend
\r
188 * This will change the:
\r
190 * method in CActiveScheduler to:
\r
191 * void DoStart(); friend class CPrivatePolledActiveScheduler;
\r
192 * We need this to access the private datamembers in CActiveScheduler.
\r
194 //#define DoStart() DoStart(); friend class CPrivatePolledActiveScheduler;
\r
195 //#include <e32base.h>
\r
196 #include "PolledAS.h"
\r
199 class CPrivatePolledActiveScheduler : public CActiveScheduler
\r
206 void CPrivatePolledActiveScheduler::Schedule()
\r
208 TDblQueIter<CActive> q(iActiveQ);
\r
215 //TRequestStatus::EActive = 1, //bit0
\r
216 //TRequestStatus::ERequestPending = 2, //bit1
\r
217 if (pR->IsActive() && pR->iStatus!=KRequestPending)
\r
219 // pR->iActive=EFalse; // won't this cause trouble?
\r
220 pR->iStatus.iFlags&=~TRequestStatusFaked::EActive;
\r
221 //debugPrintFile(_L("as: %08x"), pR);
\r
222 TRAPD(r,pR->RunL());
\r
223 //pR->iStatus=TRequestStatus::ERequestPending;
\r
233 static CPolledActiveScheduler* sPolledActiveScheduler = NULL;
\r
235 CPolledActiveScheduler::~CPolledActiveScheduler()
\r
237 sPolledActiveScheduler = NULL;
\r
238 delete iPrivatePolledActiveScheduler;
\r
241 CPolledActiveScheduler* CPolledActiveScheduler::NewL()
\r
243 // if (sPolledActiveScheduler == NULL)
\r
245 sPolledActiveScheduler = new(ELeave)CPolledActiveScheduler;
\r
246 CleanupStack::PushL(sPolledActiveScheduler);
\r
247 sPolledActiveScheduler->ConstructL();
\r
248 CleanupStack::Pop();
\r
250 return sPolledActiveScheduler;
\r
253 void CPolledActiveScheduler::ConstructL()
\r
255 iPrivatePolledActiveScheduler = new(ELeave) CPrivatePolledActiveScheduler;
\r
256 iPrivatePolledActiveScheduler->Install(iPrivatePolledActiveScheduler);
\r
260 void CPolledActiveScheduler::Schedule()
\r
262 iPrivatePolledActiveScheduler->Schedule();
\r
265 CPolledActiveScheduler* CPolledActiveScheduler::Instance()
\r
267 // return (CPolledActiveScheduler*) CActiveScheduler::Current();
\r
268 return sPolledActiveScheduler;
\r