CAsyncRequest Class Reference

class CAsyncRequest : public CActive

An outstanding request on the server side. A subclass should be created for each type of outstanding request.

This class is implemented as an active object, because it is anticipated that some asynchronous requests can be implemented simply by completing the client request when a TRequestStatus completes. The implementor can override this behavior by re-implementing RunL, e.g. to free some resources before completing the request. If they do so, they must call CompleteAndMarkForDeletion to complete the client request and mark this object for deletion (alternatively they can simply call CAsyncRequest::RunL from their RunL).

This class cannot, however, anticipate the cancellation mechanism. The implementor must implement DoCancel for that. DoCancel should not delete the client request or mark this object for deletion.

When the implementor has allocated an instance of this class, they must add it to the session by calling CAsyncRequest::TransferToScsFrameworkL. The second-phase constructor must not leave between that and calling SetActive.

These objects are cancelled and destroyed when the client-side session / subsession sends a cancel command.

CScsSession::AddAsyncRequestL

Inherits from

Constructor & Destructor Documentation

CAsyncRequest(CScsSession *, CScsSubsession *, const RMessage2 &)

IMPORT_CCAsyncRequest(CScsSession *aSession,
CScsSubsession *aSubsession,
const RMessage2 &aMessage
)

Record the session, subsession, and function associated with this request. These are required to complete or to cancel the request later.

Adds this object to the active scheduler.

Parameters

CScsSession * aSessionSession used to launch this request.
CScsSubsession * aSubsessionSubsession on which this request is queued. This should be NULL if the request is relative to a session, instead of a subsession
const RMessage2 & aMessageHandle to the kernel-side request object, which will be completed later.

Member Functions Documentation

CancelCompleteAndMarkForDeletion()

voidCancelCompleteAndMarkForDeletion()

Cancel this asynchronous request and complete the client request with KErrCancel. On exit, this object has been marked for deletion.

CompleteAndMarkForDeletion(TInt)

IMPORT_C voidCompleteAndMarkForDeletion(TIntaError)[protected]

Completes the client-side request associated with this asynchronous request and marks this object for deletion.

If the error was because the client passed a bad descriptor then panick the client instead of completing the request for consistency with synchronous requests.

Parameters

TInt aErrorError code with which the client request will be completed.

DoCleanup()

IMPORT_C voidDoCleanup()[virtual]

This virtual function is called whenever the SCS needs to cancel an operation.

If the asynchronous request implementation ALWAYS has an internal request active for the duration of the client request, then this default implementation can be used, which simply calls CActive::Cancel which will call the derived classe's DoCancel (if, and only if the object IsActive).

A more complex case is where the asynchronous requests may enter an internal queue where the client request is (obviously still active), but the derived class has not outstanding request. In this case the default implementation will cause a HANG, because Cancel will not call DoCancel if the object is not active...

In the generic case, the derived class should provide an overload for the Cleanup method. This function should call Cancel to cancel any outstanding operation, then perform whatever other cleanup is required to cleanup the request (closing handles, removing from queues etc). The framework will then complete the client request.

nb. The destructor of the CAsyncRequest may not run until sometime after the client request has been completed.

MarkForDeletion()

voidMarkForDeletion()

Mark this outstanding request for deletion, so it is cleaned up when the cleanup AO runs.

RunError(TInt)

IMPORT_C TIntRunError(TIntaError)[protected, virtual]

Override CActive by completing the request with the supplied error code and marking this object for deletion. The default implementation of RunL cannot leave, but the subclass may override it with a more complex implementation.

Parameters

TInt aErrorError code with which aError left.

RunL()

IMPORT_C voidRunL()[protected, virtual]

Implement CActive by completing the server client's request status with the AO error code, i.e. iStatus. This function also marks this object for deletion.

If a subclass overrides this implementation then it must call CompleteAndMarkForDeletion itself to complete the client-side request.

CompleteAndMarkForDeletion

TransferToScsFrameworkL()

IMPORT_C voidTransferToScsFrameworkL()

Adds this asynchronous request to the global collection. This should be called after the subclass has performed its own initialization, but before the active request has been set up.

Member Data Documentation

TInt iFunction

TInt iFunction

Identifies outstanding request.

const RMessagePtr2 iMessagePtr2

const RMessagePtr2iMessagePtr2

Outstanding message to complete.

CScsSession * iSession

CScsSession *iSession

Session on which this request is queued. NULL if completed.

CScsSubsession * iSubsession

CScsSubsession *iSubsession

Subsession on which this request is queued. NULL if session-relative.