Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Location: e32base.h
Link against: euser.lib

Class CActiveScheduler

CActiveScheduler

Support

Supported from 5.0

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:

or:

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.

Derivation

CActiveSchedulerControls the handling of asynchronous requests as represented by active objects
CBaseBase class for all classes to be instantiated on the heap

Defined in CActiveScheduler:
Add(), CActiveScheduler(), Current(), Error(), Install(), OnStarting(), OnStopping(), Replace(), RunIfReady(), Start(), Stop(), WaitForAnyRequest(), ~CActiveScheduler()

Inherited from CBase:
operator new()

See also:


Construction and destruction


CActiveScheduler()

CActiveScheduler();

Description

Constructs an active scheduler. After construction, the scheduler should be installed.

See also:


~CActiveScheduler()

~CActiveScheduler();

Description

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:

[Top]


Functions which can be overridden by derived class


WaitForAnyRequest()

virtual void WaitForAnyRequest();

Description

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:


Error()

virtual void Error(TInt anError) const;

Description

Handles the result of a leave occurring in an active object’s RunL() function. An active scheduler always invokes an active object’s RunL() function under a trap harness.

The default implementation raises an E32USER-CBase 47 panic and must be replaced. Any cleanup relevant to the possible causes of leaving should be performed. If Stop() is called from within this function, the current wait loop terminates. This may be an appropriate response to catastrophic error conditions.

Parameters

TInt anError

The leave code propagated from the active object’s RunL() function.

See also:


OnStarting()

private: virtual void OnStarting();

Support

Supported from 6.0

Description

Called when the Active Scheduler is started.

Derived classes can override this. The default implementation does nothing.


OnStopping()

private: virtual void OnStopping();

Support

Supported from 6.0

Description

Called when the Active Scheduler is stopped.

Derived classes can override this. The default implementation does nothing.

[Top]


Active scheduler administration


Install()

static void Install(CActiveScheduler* aScheduler);

Description

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.

Parameters

CActiveScheduler* aScheduler

A pointer to the active scheduler to be installed. If there is already an installed active scheduler, the function raises an E32USER-CBase 43 panic If NULL, the current active scheduler is uninstalled.


Add()

static void Add(CActive* anActive);

Description

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.

The thread must have an active scheduler installed, otherwise the function raises an E32USER-CBase 44 panic.

Parameters

CActive* anActive

Pointer to the active object to be added. The pointer must not be NULL, otherwise the function raises an E32USER-CBase 48 panic. This active object must not already have been added to the current active scheduler, otherwise the function raises an E32USER-CBase 41 panic.

See also:


Replace()

static CActiveScheduler* Replace(CActiveScheduler* aNewActiveScheduler);

Support

Supported from 6.0

Description

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

Parameters

aNewActiveScheduler

New active scheduler

Return value

CActiveScheduler*

Previous active scheduler

[Top]


Wait loop control


RunIfReady()

static TBool RunIfReady(TInt& aError, TInt aMinimumPriority);

Support

Supported from 6.0

Description

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

Parameters

aError

Error returned by called active object

aMinimumPriority

Minimum priority of active object to run

Return value

TBool

EFalse if no active object's RunL() function is run: i.e. if there are no active objects of priority aMinimumPriority or greater pending


Start()

static void Start();

Description

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:

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

Nested wait loops can also be started. Typically, a nested wait loop is used when the handling of a completed event in an active object requires processing further events from the other active objects before it can complete. This is a form of modal processing.

The thread must have an active scheduler installed, otherwise the function raises an E32USER-CBase 44 panic.

See also:


Stop()

static void Stop();

Description

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

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

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

See also:

[Top]


Accessors


Current()

static CActiveScheduler* Current();

Description

Returns a pointer to the currently installed active scheduler.

Return value

CActiveScheduler*

A pointer to the active scheduler which is currently installed.