TRequestStatus
A request status object is used to carry the completion status of an asynchronous request.
Typically, an asynchronous request is made by an active object, an
instance of a CActive
derived class, to a service provider. When
an asynchronous request completes, the service provider stores a completion
code in the request status object and signals the caller’s thread. When
the active object handles the completed request, it can check the completion
code.
The request status object is always a data member of the active object.
class CMyActive : public CAvctive
{
void RunL();
void IssueRequest();
...
TRequestStatus iStatus;
RTimer iTimer;
}
The active object does not need to initialise the request status
object in any way; it simply passes it to the service provider’s request
function when making the request. The service provider is responsible for
changing the completion code; in particular it sets the code to
KRequestPending
before initiating the request. For example:
void CMyActive::IssueRequest()
{
timer.CreateLocal(); // created for this thread
...
timer.After(iStatus,5000000); // Notification after 5 seconds
SetActive();
...
}
The active object’s completed request handler, i.e. its
RunL()
function can check the completion code as the code
fragments show. While not particularly useful for timers, it shows the general
principle:
//
// Extracting the completion code value
//
void RunL()
{
...
User::LeaveIfError(iStatus.Int());// leave on bad return code
...
}
//
// Using a comparison operator
//
void RunL()
{
...
if (iStatus == KErrCancel);// check for a specific value
...
}