This document describes how to maintain an outstanding request from an active scheduler.
It is possible to maintain an outstanding request from the active scheduler, by overriding the CActiveScheduler::WaitForAnyRequest() function.
In this case, it is useful for the active scheduler to have a data member which points to the active object for which it will maintain an outstanding request. Implement the active scheduler as follows:
class CExampleScheduler : public CActiveScheduler { public: void Error (TInt aError) const; void WaitForAnyRequest(); void SetActiveObject(CActiveConsole* aActiveConsole); private: CActiveConsole* iActiveConsole; };
void CExampleScheduler::SetActiveObject(CActiveConsole* aActiveConsole) { iActiveConsole = aActiveConsole; }
where iActiveConsole is a pointer to an active object, initialized by call to SetActiveObject() during the construction of the controlling active object:
void CMessageKeyProcessor::ConstructL() { CActiveScheduler::Add(this); (CExampleScheduler*)(CActiveScheduler::Current())->SetActiveObject(this); }
Now override CActiveScheduler::WaitForAnyRequest() :
void CExampleScheduler::WaitForAnyRequest() { if (!(iActiveConsole->IsActive())) { iActiveConsole->RequestCharacter(); } CActiveScheduler::WaitForAnyRequest(); }
The state of the active request flag is examined and a request is not issued if it is active. This check is important because the function may be called as a result of other active objects completing (for example, a timed messenger) and in these cases it would be inappropriate to renew the keyboard service request.
It is no longer necessary to call RequestCharacter() either before starting the active scheduler, or as part of key processing.
The static function CActiveScheduler::Current() is used to fetch a pointer to the currently installed active scheduler (in this example, an object of type CExampleScheduler ). This is necessary in order to access the SetActiveObject() member function of CExampleScheduler .
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.