1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef APASERVERAPP_H
17 #define APASERVERAPP_H
23 // Server application client support
28 class RApaAppServiceBase : public RSessionBase
29 /** Server app connection and lifetime monitoring functionality.
31 This is the base class for all server application service client
32 support implementations.
34 The class is derived from by the UI framework and is further derived from
35 by service implementations.
37 Clients of these server application services will use these derived classes as
38 the interface to the server application implementations of the services.
42 @see REikAppServiceBase */
46 /** Constants defining the base IPC command ids usable by the system GUI and services. */
47 enum TApaAppServiceBaseCmdConstants
49 /** System GUI server app command IDs must start from this base. */
50 KSystemGuiCmdBase = 0x100,
51 /** Service specific command IDs must start from this base. */
52 KServiceCmdBase = 0x200
56 IMPORT_C void ConnectExistingAppL(const RApaAppServiceBase& aClient);
57 IMPORT_C void ConnectExistingAppL(const RApaAppServiceBase& aClient, const TSecurityPolicy& aSecurityPolicy);
58 IMPORT_C void ConnectExistingByNameL(const TDesC& aName);
59 IMPORT_C void ConnectExistingByNameL(const TDesC& aServerName, const TSecurityPolicy& aSecurityPolicy);
60 IMPORT_C void TransferExistingSessionL(RApaAppServiceBase& aClient);
61 IMPORT_C void Close(); //lint !e1511 Member hides non-virtual member
63 IMPORT_C void NotifyServerExit(TRequestStatus& aStatus) const;
64 IMPORT_C void CancelNotifyServerExit() const;
66 IMPORT_C TPtrC ServerName() const;
69 IMPORT_C RApaAppServiceBase();
72 IMPORT_C virtual void RApaAppServiceBase_Reserved1();
73 IMPORT_C virtual void RApaAppServiceBase_Reserved2();
75 /** Returns the UID of the service that this session provides an interface for.
76 Client side service implementations must implement this function to return
77 the UID for the service that they implement.
78 @return The UID of the service implemented by the derived class.*/
79 virtual TUid ServiceUid() const = 0;
83 void ConnectL(const TSecurityPolicy& aSecurityPolicy);
86 IMPORT_C virtual void ExtensionInterface(TUid aInterfaceId, TAny*& aImplementaion);
89 HBufC* iServerName; // owned
95 class MApaServerAppExitObserver
96 /** Interface for a class that wants to receive exit notification from
101 @see CApaServerAppExitMonitor*/
104 /** Receives server exit notification.
105 Implementers of this interface must override this function to
106 receive notification of server app exit reasons.
107 @param aReason The reason that the server app exited, this may be
108 a command ID from the UI if exit was triggered from the UI, or an error code
109 if the server app exited unexpectedly. */
110 virtual void HandleServerAppExit(TInt aReason) = 0;
112 IMPORT_C MApaServerAppExitObserver();
114 IMPORT_C virtual void MApaServerAppExitObserver_Reserved1();
115 IMPORT_C virtual void MApaServerAppExitObserver_Reserved2();
117 TInt iMApaServerAppExitObserver_Reserved1;
121 class CApaServerAppExitMonitor : public CActive
122 /** Helper class that monitors the lifetime of a server app
123 through a connected RApaAppServiceBase and reports server app exits
124 to a MApaServerAppExitObserver derived class.
128 @see RApaAppServiceBase
129 @see MApaServerAppExitObserver */
132 IMPORT_C static CApaServerAppExitMonitor* NewL(RApaAppServiceBase& aClient, MApaServerAppExitObserver& aObserver, TInt aPriority);
133 IMPORT_C static CApaServerAppExitMonitor* NewLC(RApaAppServiceBase& aClient, MApaServerAppExitObserver& aObserver, TInt aPriority);
134 IMPORT_C ~CApaServerAppExitMonitor();
137 CApaServerAppExitMonitor(RApaAppServiceBase& aClient, MApaServerAppExitObserver& aObserver, TInt aPriority);
139 private: // from CActive
142 TInt RunError(TInt aError);
145 RApaAppServiceBase& iClient;
146 MApaServerAppExitObserver& iObserver;
151 // Server application server support
154 /** Panic codes that the server application framework can generate.
155 @internalComponent */
156 enum TApaAppServerPanic
158 /** The IPC message ID used by the client is not recognised. */
159 EApaAppServerPanicIllegalFunction,
160 /** The client already has an active notification of server exit. */
161 EApaAppServerPanicNotifyExitActive,
162 /** The client has tried to connect an already connected session. */
163 EApaAppServerPanicClientAlreadyConnected
167 class CApaAppServiceBase : public CSession2
168 /** Base class for all service implementations.
169 Provides the basic IPC and security framework that server applications
170 can use to receive messages from their clients.
171 In a typical service implementation, a service support class
172 will be derived from this class, and the service implementation
173 will then be derived from the service support class.
175 Instances of this class are created by the server application
176 in its override of CApaAppServer::CreateServiceL().
181 @see CPolicyServer */
184 IMPORT_C CApaAppServiceBase();
185 IMPORT_C ~CApaAppServiceBase();
187 IMPORT_C virtual CPolicyServer::TCustomResult SecurityCheckL(const RMessage2& aMsg, TInt& aAction, TSecurityInfo& aMissing);
190 void SendAppServerExitNotification(TInt aExitReason);
192 protected: // from CSession2
193 IMPORT_C void CreateL();
194 IMPORT_C void ServiceL(const RMessage2& aMessage);
195 IMPORT_C void ServiceError(const RMessage2& aMessage,TInt aError);
196 IMPORT_C virtual TInt CountResources();
197 IMPORT_C virtual void Disconnect(const RMessage2& aMessage);
199 private: // Server exit notification handlers
200 void NotifyServerExit(const RMessage2& aMessage);
201 void CancelNotifyServerExit(const RMessage2& aMessage) const;
204 IMPORT_C virtual void ExtensionInterface(TUid aInterfaceId, TAny*& aImplementaion);
205 IMPORT_C virtual void CApaAppServiceBase_Reserved1();
206 IMPORT_C virtual void CApaAppServiceBase_Reserved2();
209 RMessagePtr2 iNotifyExitMsg;
214 class CApaAppServer : public CPolicyServer
215 /** Base class for all server application's servers.
216 Server applications must derive from this class to implement their
217 servers. These must be instantiated in an override of
218 CApaApplication::NewAppServerL().
219 The main task of this class is to create service implementations
220 that clients of a server app may connect to.
225 @see CPolicyServer */
228 IMPORT_C ~CApaAppServer();
229 IMPORT_C virtual void ConstructL(const TDesC& aFixedServerName);
231 IMPORT_C void NotifyServerExit(TInt aReason);
233 IMPORT_C virtual CApaAppServiceBase* CreateServiceL(TUid aServiceType) const;
234 IMPORT_C virtual TCustomResult CreateServiceSecurityCheckL(TUid aServiceType, const RMessage2& aMsg, TInt& aAction, TSecurityInfo& aMissing);
237 IMPORT_C CApaAppServer();
239 // From CPolicyServer
240 IMPORT_C TCustomResult CustomSecurityCheckL(const RMessage2& aMsg, TInt& aAction, TSecurityInfo& aMissing);
242 IMPORT_C virtual void DoConnect(const RMessage2& aMessage);
245 IMPORT_C CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
248 TUid ConnectMessageServiceUid(const RMessage2& aMsg) const;
251 IMPORT_C virtual void ExtensionInterface(TUid aInterfaceId, TAny*& aImplementaion);
253 IMPORT_C virtual void CApaAppServer_Reserved1();
254 IMPORT_C virtual void CApaAppServer_Reserved2();