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
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
36 CBase(const CBase&);
\r
37 CBase& operator=(const CBase&);
\r
38 IMPORT_C static TAny* newL(TUint aSize);
\r
41 class CActive : public CBase
\r
48 EPriorityStandard=0,
\r
49 EPriorityUserInput=10,
\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
61 IMPORT_C CActive(TInt aPriority);
\r
62 IMPORT_C void SetActive();
\r
64 virtual void DoCancel() =0;
\r
65 virtual void RunL() =0;
\r
66 IMPORT_C virtual TInt RunError(TInt aError);
\r
68 TRequestStatus iStatus;
\r
72 friend class CActiveScheduler;
\r
73 // friend class CServer;
\r
74 friend class CPrivatePolledActiveScheduler; // added
\r
77 class CActiveScheduler : public CBase
\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
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
100 // private interface used through by CActiveSchedulerWait objects
\r
101 friend class CActiveSchedulerWait;
\r
102 static void OwnedStart(CActiveSchedulerWait& aOwner);
\r
104 inline TInt Level() const {return(iLevel);}
\r
107 TPriQue<CActive> iActiveQ;
\r
110 class TCleanupItem;
\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
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
134 //#define friend friend class CPrivatePolledActiveScheduler; friend
\r
138 * This will change the:
\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
144 //#define DoStart() DoStart(); friend class CPrivatePolledActiveScheduler;
\r
145 //#include <e32base.h>
\r
146 #include "PolledAS.h"
\r
149 class CPrivatePolledActiveScheduler : public CActiveScheduler
\r
157 void CPrivatePolledActiveScheduler::Schedule()
\r
159 TDblQueIter<CActive> q(iActiveQ);
\r
166 if (pR->IsActive() && pR->iStatus!=KRequestPending)
\r
168 pR->iActive=EFalse;
\r
169 TRAPD(r,pR->RunL());
\r
179 CPolledActiveScheduler::~CPolledActiveScheduler()
\r
181 delete iPrivatePolledActiveScheduler;
\r
184 //static CPolledActiveScheduler* sPolledActiveScheduler = NULL;
\r
185 CPolledActiveScheduler* CPolledActiveScheduler::NewL()
\r
187 //sPolledActiveScheduler =
\r
188 CPolledActiveScheduler* self = new(ELeave)CPolledActiveScheduler;
\r
189 CleanupStack::PushL(self);
\r
190 self->ConstructL();
\r
191 CleanupStack::Pop();
\r
195 void CPolledActiveScheduler::ConstructL()
\r
197 iPrivatePolledActiveScheduler = new(ELeave) CPrivatePolledActiveScheduler;
\r
198 iPrivatePolledActiveScheduler->Install(iPrivatePolledActiveScheduler);
\r
202 void CPolledActiveScheduler::Schedule()
\r
204 iPrivatePolledActiveScheduler->Schedule();
\r
208 CPolledActiveScheduler* CPolledActiveScheduler::Instance()
\r
210 // return (CPolledActiveScheduler*) CActiveScheduler::Current();
\r
211 return sPolledActiveScheduler;
\r