Create the service class

Create the server service support class, derived from CApaAppServiceBase or a suitable System-GUI specialization of this class. This class adapts the IPC protocol to a set of virtual functions which the server application can override to implement the service. This class has the following responsibilities:

  • Receiving and decoding the IPC messages from the client

  • Defining and calling virtual functions which the server application can override to implement the service

  • Checking all parameters sent from the client for validity

  • Supporting the security policy of the server application for this service.

This example shows a server-side service support class for a chat service. This class implements the code necessary for sending messages to the client, but provides a pure virtual Receive() function for the server application to implement its own handling of messages received from the client.

class CChatService : public CApaAppServiceBase
    {
    public:
        CChatService();
        ~CChatService();
        void Send(const TDesC& aMessage);
        virtual void Receive(TDes& aMessage) = 0;
    private:
        void ServiceL(const RMessage2& aMessage);
        TBool ReceivePending() const;
    private:
        RMessagePtr2 iReceiveMsg;
        TInt iReceiveLen;
    };