Declaring a Window Server Event-Handling Class

The following example demonstrates how to declare an active object Window Server event handling class.

Variant: ScreenPlay and non-ScreenPlay. Target audience: Application developers.

The steps are:

  • Provide a CActive::RunL() function to handle the completion of an asynchronous request—that is, the event being received.

  • Provide a CActive::DoCancel() function to implement a cancellation request.

  • Provide a function, here called IssueRequest(), to issue a request to the Window Server for events.

  • Create a TWsEvent object to store the events.

/* An active object that wraps a Window Server session.
   An event being received causes RunL() to be called,
   where the event is processed. */

class CExampleWsClient : public CActive

    // Active object protocol
    void RunL ();
    void DoCancel();

    // Issue request to Window Server for events


    // Access to Window Server session 
    RWsSession& iWs;

    // Access to screen device 
    CWsScreenDevice& iScreen;

    // Window server general event
    TWsEvent iWsEvent;

Issuing a request to the Window Server

Once the active object has been constructed, a request can be issued. In the following code fragment, the active object provides the function IssueRequest() to invoke the encapsulated event request function. Pass the a TRequestStatus object, iStatus, to the EventReady() function to request Window Server events from the iWs Window Server session.

Use the CActive::SetActive() function, to indicate that the active object is currently active.

/* Request Window Server events */
void CExampleWsClient::IssueRequest()
    iWs.EventReady(&iStatus;); // request an event
    SetActive(); // so we're now active

Related concepts