CActiveScheduler Class Reference

#include <e32base.h>

Link against: euser_v5.lib

class CActiveScheduler : public CBase

Inherits from

Nested Classes and Structures

  • CActiveScheduler::TLoop
Public Member Type Definitions
typedefTLoop * TLoopOwner
Public Member Functions
IMPORT_C voidAdd(CActive *)
IMPORT_C CActiveScheduler *Current()
virtual IMPORT_C voidError(TInt)
IMPORT_C voidHalt(TInt)
IMPORT_C voidInstall(CActiveScheduler *)
IMPORT_C CActiveScheduler *Replace(CActiveScheduler *)
IMPORT_C TBoolRunIfReady(TInt &, TInt)
IMPORT_C TIntStackDepth()
IMPORT_C voidStart()
IMPORT_C voidStop()
virtual IMPORT_C voidWaitForAnyRequest()
Protected Member Functions
virtual IMPORT_C TIntExtension_(TUint, TAny *&, TAny *)
TInt Level()
Inherited Functions
CBase::Delete(CBase *)
CBase::operator new(TUint)
CBase::operator new(TUint,TAny *)
CBase::operator new(TUint,TLeave)
CBase::operator new(TUint,TLeave,TUint)
CBase::operator new(TUint,TUint)

Detailed Description

Controls the handling of asynchronous requests as represented by active objects.

An active scheduler is used to schedule the sequence in which active object request completion events are handled by a single event-handling thread.

An active scheduler can be instantiated and used directly if either:

  • the RunL() function of all of its active objects is guaranteed not to leave, or

  • each of its active objects implements a suitable RunError() function to provide suitable cleanup

If any of the active scheduler's active objects does not provide a RunError() function, then a CActiveScheduler derived class must be defined and an implementation of the Error() function provided to perform the cleanup required.

There is one active scheduler per thread and the static functions provided by the class always refer to the current active scheduler.

See also: CActiveScheduler::Error CActive CActiveSchedulerWait

Member Type Definition Documentation

Typedef TLoopOwner

typedef TLoop *TLoopOwner

Constructor & Destructor Documentation

CActiveScheduler ( )


Constructs an active scheduler.

After construction, the scheduler should be installed.

See also: CActiveScheduler::Install

~CActiveScheduler ( )


Frees resources prior to destruction.

Specifically, it removes all active objects from the active scheduler's list of active objects.

An active scheduler should only be destroyed when the top-level call to Start() has returned.

See also: CActiveScheduler::Start CActiveScheduler::Stop

Member Function Documentation

Add ( CActive * )

IMPORT_C voidAdd(CActive *aActive)[static]

Adds the specified active object to the current active scheduler.

An active object can be removed from an active scheduler either by destroying the active object or by using its Deque() member function.

See also: CActive::Deque

aActivePointer to the active object to be added.
Panic Codes
E32USER-CBase41 if the active object aRequest has already been added to the current active scheduler.
E32USER-CBase48 if aRequest is NULL.
E32USER-CBase44 if the thread does not have an installed active scheduler.

Current ( )

IMPORT_C CActiveScheduler *Current()[static]

Gets a pointer to the currently installed active scheduler.

Return Value
A pointer to the active scheduler which is currently installed.

Error ( TInt )

IMPORT_C voidError(TIntaError)const [virtual]

Handles the result of a leave occurring in an active objects RunL() function.

An active scheduler always invokes an active objects RunL() function under a trap harness.

The default implementation must be replaced.

Any cleanup relevant to the possible causes of leaving should be performed. If Stop() or Halt() is called from within this function, the current wait loop terminates. This may be an appropriate response to catastrophic error conditions.

See also: CActive::RunL CActiveScheduler::Stop CActiveScheduler::Halt

aErrorThe leave code propagated from the active objects RunL() function
Panic Codes
E32USER-CBase47 if the default implementation is invoked.

Extension_ ( TUint, TAny *&, TAny * )

IMPORT_C TIntExtension_(TUintaExtensionId,
TAny *&a0,
TAny *a1
)[protected, virtual]

Extension function

Halt ( TInt )

IMPORT_C voidHalt(TIntaExitCode)const

Unilaterally terminates the current scheduler loop.

This causes the current scheduler loop to stop, whether it was started using CActiveSchedulerWait::Start() or CActiveScheduler::Start(). It can also trigger a leave from Start() if an exit code is provided. If the current level has already been stopped, then this still records the exit code.

aExitCodeIf non-zero, the reason code reported by Start().

Install ( CActiveScheduler * )

IMPORT_C voidInstall(CActiveScheduler *aScheduler)[static]

Installs the specified active scheduler as the current active scheduler.

The installed active scheduler now handles events for this thread.

The current active scheduler can be uninstalled by passing a NULL pointer.

aSchedulerA pointer to the active scheduler to be installed. If this is NULL, the current active scheduler is uninstalled.
Panic Codes
E32USER-CBase43 if If there is already an installed active scheduler.

Level ( )

TInt Level()const [protected, inline]

DeprecatedUse the StackDepth() function instead.

Gets the scheduler's level of nestedness.

See also: StackDepth()

Return Value
The level of nestedness.

Replace ( CActiveScheduler * )

IMPORT_C CActiveScheduler *Replace(CActiveScheduler *aNewActiveScheduler)[static]

Allows the current active scheduler to be replaced, while retaining its active objects.

aNewActiveSchedulerThe new active scheduler.
Return Value
Previous active scheduler.

RunIfReady ( TInt &, TInt )

IMPORT_C TBoolRunIfReady(TInt &aError,


Causes the RunL() function of at most one pending active object of priority aMinimumPriority or greater to be run.

aErrorError returned by called active object.
aMinimumPriorityMinimum priority of active object to run.
Return Value
EFalse if no active object's RunL() function was run, i.e. if there were no active objects of priority aMinimumPriority or greater pending.

StackDepth ( )

IMPORT_C TIntStackDepth()const

Gets the current number of nested wait loops.

Return Value
The number of nested calls to Start().

Start ( )

IMPORT_C voidStart()[static]

Starts a new wait loop under the control of the current active scheduler.

At least one active object, with an outstanding request, must be added to the scheduler before the wait loop is started, otherwise no events will occur and the thread will hang, or any events that do occur will be counted as stray signals, raising a panic.

While Start() is executing, user code runs only:

1. in the RunL() function of active objects known to the current active scheduler

2. in the RunError() function of an active object that leaves from its RunL()

3. in the current active schedulers Error() function, if an active objects RunError() returns an error code.

Start() returns only when a corresponding Stop() or Halt() is issued.

Although this can be used to start a nested wait loop, this API is deprecated for that specific functionality, and a CActiveSchedulerWait object should be used instead.

(Note that a nested wait loop is used when the handling of a completed event in an active object requires the processing of further events from the other active objects before it can complete. This is a form of modal processing.)

See also: CActiveScheduler::Stop CActiveScheduler::Halt CActive::RunL CActive::RunError CActiveScheduler::Error CActiveSchedulerWait

Panic Codes
E32USER-CBase44 if the thread does not have an active scheduler installed.

Stop ( )

IMPORT_C voidStop()[static]

Stops the wait loop started by the most recent call to Start().

Typically, this is called by the RunL() of one of the schedulers active objects. When this RunL() finishes, the schedulers wait loop terminates, i.e. it does not wait for the completion of the next request.

It will not stop a wait loop started by a call to CActiveSchedulerWait::Start().

Stop() may also be called from Error().

Note that stopping a nested wait loop is deprecated using this functionality, use a CActiveSchedulerWait object instead.

See also: CActiveSchedulerWait::Start CActive::RunL CActiveSchedulerWait::Error CActiveSchedulerWait::AsyncStop

WaitForAnyRequest ( )

IMPORT_C voidWaitForAnyRequest()[virtual]

Wait for an asynchronous request to complete.

The default implementation just calls User::WaitForAnyRequest().

Derived classes can replace this. Typically, this would be done to implement code for maintaining an outstanding request; this would be followed by a call to User::WaitForAnyRequest().

See also: User::WaitForAnyRequest