Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

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



Location: e32base.h
Link against: euser.lib

Class CActive

CActive

Support

Supported from 5.0

Description

The core class of the active object abstraction. It encapsulates both the issuing of a request to an asynchronous service provider and the handling of completed requests. An application can have one or more active objects whose processing is controlled by an active scheduler.

Derivation

CActiveThe core class of the active object abstraction
CBaseBase class for all classes to be instantiated on the heap

Defined in CActive:
CActive(), Cancel(), Deque(), DoCancel(), EPriorityHigh, EPriorityIdle, EPriorityLow, EPriorityStandard, EPriorityUserInput, IsActive(), IsAdded(), Priority(), RunError(), RunL(), SetActive(), SetPriority(), TPriority, iStatus, ~CActive()

Inherited from CBase:
operator new()

See also:


Construction and destruction


CActive()

protected: CActive(TInt aPriority);

Description

Constructs the active object with the specified priority.

Derived classes must define and implement a constructor through which the priority can be specified. A typical implementation calls this active object constructor through a constructor initialization list.

Parameters

TInt aPriority

An integer specifying the priority of this active object. CActive::TPriority defines a standard set of priorities.


~CActive()

~CActive();

Description

Frees resources prior to destruction. Specifically, it removes this active object from the active scheduler’s list of active objects.

The active object must not have an outstanding request when the destructor is called, otherwise an E32USER-CBase 40 panic is raised.

Typically, a derived class calls Cancel() in its destructor.

See also:

[Top]


State of the active object


IsActive()

TBool IsActive() const;

Description

Determines whether the active object has a request outstanding.

A request is outstanding when:

Return value

TBool

True, if a request is outstanding; false, otherwise


SetActive()

protected: void SetActive();

Description

Indicates that the active object has issued a request and that it is now outstanding. Derived classes must call this function after issuing a request.

A request is automatically marked as complete (i.e. it is no longer outstanding) by:

or

See also:


IsAdded()

TBool IsAdded() const;

Description

Determines whether the active object has been added to the active scheduler’s list of active objects.

If the active object has not been added to a scheduler, it cannot handle the completion of any request. No request should be issued until the active object has been added to a scheduler because completion of that request generates what appears to be a stray signal.

Use the active object function Deque() to remove the active object from the scheduler.

Return value

TBool

True, if the active object has been added to an active scheduler; false, otherwise.

See also:

[Top]


Active object priority


SetPriority()

void SetPriority(TInt aPriority);

Description

Sets the priority of the active object.

The function raises an E32USER-CBase 50 panic if it is called while a request is outstanding.

Parameters

TInt aPriority

An integer specifying the new priority of this active object. CActive::TPriority defines a standard set of priorities.


Priority()

TInt Priority() const;

Description

Returns the priority of the active object.

Return value

TInt

The active object’s priority value.

[Top]


Run protocol


RunL()

protected: virtual void RunL() = 0;

Description

Handles an active object’s request completion event.

A derived class must provide an implementation to handle the completed request. If appropriate, it may issue another request.

The function is called by the active scheduler when a request completion event occurs, i.e. after the active scheduler’sWaitForAnyRequest()function completes.

Before calling this active object’s RunL() function, the active scheduler has:

RunL() runs under a trap harness in the active scheduler. If it leaves, then the active scheduler calls RunError() to handle the leave.

Note that once the active scheduler’s Start()function has been called, all user code is run under one of the program's active object's RunL()or RunError()functions.

See also:

[Top]


Error handling


RunError()

virtual TInt RunError(TInt aError);

Support

Supported from 6.0

Description

Handles a leave occurring in the request completion event handlerRunL().

The active scheduler calls this function if this active object'sRunL() function leaves. This gives this active object the opportunity to perform any necessary cleanup.

A derived class implementation should handle the leave and returnKErrNone. Returning any other value results in the active scheduler function CActiveScheduler::Error() being called.

The default implementation simply returns the leave code.

Note that if the active scheduler is to handle the error, a suitably derived CActiveScheduler::Error() function must be supplied.

Parameters

TInt aError

The leave code

Return value

TInt

The default implementation returns aError. A derived class implementation should return KErrNone, if it handles the leave; otherwise it should return any suitable value to cause the handling of the error to be propagated back to the active scheduler.

See also:

[Top]


Cancel protocol


Cancel()

void Cancel();

Description

Cancels the wait for completion of an outstanding request. If there is no request outstanding, then the function does nothing.

If there is an outstanding request, the function:

See also:


DoCancel()

protected: virtual void DoCancel() =0

Description

Implements cancellation of an outstanding request. This function is called as part of the active object’s Cancel().

It must call the appropriate cancel function offered by the active object’s asynchronous service provider. The asynchronous service provider’s cancel is expected to act immediately.

DoCancel() must not wait for event completion; this is handled byCancel().

See also:


Deque()

void Deque();

Description

Removes the active object from the active scheduler’s list of active objects.

Before being removed from the active scheduler’s list, the function cancels any outstanding request.

See also:

[Top]


Data members


iStatus

TRequestStatus iStatus

Description

The request status associated with an asynchronous request. This is passed as a parameter to all asynchronous service providers.

The active scheduler uses this to check whether the active object’s request has completed.

The function can use the completion code to judge the success or otherwise of the request.

[Top]


Enumerations


Enum TPriority

TPriority

Description

Defines standard priorities for active objects.

EPriorityIdle

A low priority, useful for active objects representing background processing

EPriorityLow

A priority higher than EPriorityIdle but lower thanEPriorityStandard

EPriorityStandard

Most active objects will have this priority.

EPriorityUserInput

A priority higher than EPriorityStandard; useful for active objects handling user input.

EPriorityHigh

A priority higher than EPriorityUserInput