+++ /dev/null
-/*******************************************************************\r
- *\r
- * File: PolledAS.cpp\r
- *\r
- * Author: Peter van Sebille (peter@yipton.net)\r
- *\r
- * (c) Copyright 2002, Peter van Sebille\r
- * All Rights Reserved\r
- *\r
- *******************************************************************/\r
-\r
-/*\r
- * Oh Lord, forgive me for I have sinned.\r
- * In their infinite wisdom, Symbian Engineers have decided that\r
- * the Active Scheduler's queue of Active Objects is private\r
- * and no getters are provided... sigh.\r
- * This mere mortal will have to excercise the power of C pre-processor \r
- * once more to circumvent the will of the gods.\r
- */\r
-\r
-\r
-#include <e32std.h>\r
-\r
-// from e32base.h\r
-class CBase\r
- {\r
-public:\r
- IMPORT_C virtual ~CBase();\r
- inline TAny* operator new(TUint aSize,TAny *aBase) {Mem::FillZ(aBase,aSize);return(aBase);}\r
- IMPORT_C TAny* operator new(TUint aSize);\r
- inline TAny* operator new(TUint aSize, TLeave) {return newL(aSize);}\r
- IMPORT_C TAny* operator new(TUint aSize,TUint anExtraSize);\r
-protected:\r
- IMPORT_C CBase();\r
-private:\r
- CBase(const CBase&);\r
- CBase& operator=(const CBase&);\r
- IMPORT_C static TAny* newL(TUint aSize);\r
- };\r
-\r
-class CActive : public CBase\r
- {\r
-public:\r
-enum TPriority\r
- {\r
- EPriorityIdle=-100,\r
- EPriorityLow=-20,\r
- EPriorityStandard=0,\r
- EPriorityUserInput=10,\r
- EPriorityHigh=20,\r
- };\r
-public:\r
- IMPORT_C ~CActive();\r
- IMPORT_C void Cancel();\r
- IMPORT_C void Deque();\r
- IMPORT_C void SetPriority(TInt aPriority);\r
- inline TBool IsActive() const {return(iActive);}\r
- inline TBool IsAdded() const {return(iLink.iNext!=NULL);}\r
- inline TInt Priority() const {return iLink.iPriority;}\r
-protected:\r
- IMPORT_C CActive(TInt aPriority);\r
- IMPORT_C void SetActive();\r
-// Pure virtual\r
- virtual void DoCancel() =0;\r
- virtual void RunL() =0;\r
- IMPORT_C virtual TInt RunError(TInt aError);\r
-public:\r
- TRequestStatus iStatus;\r
-private:\r
- TBool iActive;\r
- TPriQueLink iLink;\r
- friend class CActiveScheduler;\r
-// friend class CServer;\r
- friend class CPrivatePolledActiveScheduler; // added\r
- };\r
-\r
-//\r
-class CActiveScheduler : public CBase\r
- {\r
-public:\r
- IMPORT_C CActiveScheduler();\r
- IMPORT_C ~CActiveScheduler();\r
- IMPORT_C static void Install(CActiveScheduler* aScheduler);\r
- IMPORT_C static CActiveScheduler* Current();\r
- IMPORT_C static void Add(CActive* anActive);\r
- IMPORT_C static void Start();\r
- IMPORT_C static void Stop();\r
- IMPORT_C static TBool RunIfReady(TInt& aError, TInt aMinimumPriority);\r
- IMPORT_C static CActiveScheduler* Replace(CActiveScheduler* aNewActiveScheduler);\r
- IMPORT_C virtual void WaitForAnyRequest();\r
- IMPORT_C virtual void Error(TInt anError) const;\r
-private:\r
- void DoStart();\r
- IMPORT_C virtual void OnStarting();\r
- IMPORT_C virtual void OnStopping();\r
- IMPORT_C virtual void Reserved_1();\r
- IMPORT_C virtual void Reserved_2();\r
- friend class CPrivatePolledActiveScheduler; // added\r
-protected:\r
- inline TInt Level() const;\r
-private:\r
- TInt iLevel;\r
- TPriQue<CActive> iActiveQ;\r
- };\r
-\r
-class TCleanupItem;\r
-class CleanupStack\r
- {\r
-public:\r
- IMPORT_C static void PushL(TAny* aPtr);\r
- IMPORT_C static void PushL(CBase* aPtr);\r
- IMPORT_C static void PushL(TCleanupItem anItem);\r
- IMPORT_C static void Pop();\r
- IMPORT_C static void Pop(TInt aCount);\r
- IMPORT_C static void PopAndDestroy();\r
- IMPORT_C static void PopAndDestroy(TInt aCount);\r
- IMPORT_C static void Check(TAny* aExpectedItem);\r
- inline static void Pop(TAny* aExpectedItem);\r
- inline static void Pop(TInt aCount, TAny* aLastExpectedItem);\r
- inline static void PopAndDestroy(TAny* aExpectedItem);\r
- inline static void PopAndDestroy(TInt aCount, TAny* aLastExpectedItem);\r
- };\r
-\r
-\r
-/*\r
- * This will declare CPrivatePolledActiveScheduler as a friend\r
- * of all classes that define a friend. CPrivatePolledActiveScheduler needs to\r
- * be a friend of CActive\r
- */\r
-//#define friend friend class CPrivatePolledActiveScheduler; friend\r
-\r
-\r
-/*\r
- * This will change the:\r
- * void DoStart();\r
- * method in CActiveScheduler to:\r
- * void DoStart(); friend class CPrivatePolledActiveScheduler;\r
- * We need this to access the private datamembers in CActiveScheduler.\r
- */\r
-//#define DoStart() DoStart(); friend class CPrivatePolledActiveScheduler;\r
-//#include <e32base.h>\r
-#include "PolledAS.h"\r
-\r
-\r
-class CPrivatePolledActiveScheduler : public CActiveScheduler\r
-{\r
-public:\r
- void Schedule();\r
-};\r
-\r
-\r
-\r
-void CPrivatePolledActiveScheduler::Schedule()\r
-{\r
- TDblQueIter<CActive> q(iActiveQ);\r
- q.SetToFirst();\r
- FOREVER\r
- {\r
- CActive *pR=q++;\r
- if (pR)\r
- {\r
- if (pR->IsActive() && pR->iStatus!=KRequestPending)\r
- {\r
- pR->iActive=EFalse;\r
- TRAPD(r,pR->RunL());\r
- break;\r
- }\r
- }\r
- else\r
- break;\r
- }\r
-}\r
-\r
-\r
-CPolledActiveScheduler::~CPolledActiveScheduler()\r
-{\r
- delete iPrivatePolledActiveScheduler;\r
-}\r
-\r
-//static CPolledActiveScheduler* sPolledActiveScheduler = NULL;\r
-CPolledActiveScheduler* CPolledActiveScheduler::NewL()\r
-{\r
- //sPolledActiveScheduler = \r
- CPolledActiveScheduler* self = new(ELeave)CPolledActiveScheduler;\r
- CleanupStack::PushL(self);\r
- self->ConstructL();\r
- CleanupStack::Pop();\r
- return self;\r
-}\r
-\r
-void CPolledActiveScheduler::ConstructL()\r
-{\r
- iPrivatePolledActiveScheduler = new(ELeave) CPrivatePolledActiveScheduler;\r
- iPrivatePolledActiveScheduler->Install(iPrivatePolledActiveScheduler);\r
-}\r
-\r
-\r
-void CPolledActiveScheduler::Schedule()\r
-{\r
- iPrivatePolledActiveScheduler->Schedule();\r
-}\r
-\r
-/*\r
-CPolledActiveScheduler* CPolledActiveScheduler::Instance()\r
-{\r
-// return (CPolledActiveScheduler*) CActiveScheduler::Current();\r
- return sPolledActiveScheduler;\r
-}\r
-*/\r