Symbian OS中的Client/Server机制分析
2010-09-06 08:10:00 来源:WEB开发网IMPORT_C virtual ~CSession2() =0;
public:
inline const CServer2* Server() const;
IMPORT_C void ResourceCountMarkStart();
IMPORT_C void ResourceCountMarkEnd(const RMessage2& aMessage);
IMPORT_C virtual TInt CountResources();
/**
Handles the servicing of a client request that has been passed to the server.
This function must be implemented in a derived class. The details of the request are contained within the message.
@param aMessage The message containing the details of the client request.
*/
virtual void ServiceL(const RMessage2& aMessage) =0;
IMPORT_C virtual void ServiceError(const RMessage2& aMessage,TInt aError);
...
...
};
virtual void ServiceL(const RMessage2& aMessage) =0;
这个是纯虚函数,所以派生类必须做实现。当Client在建立了和Server的连接后,会通过某个接口向Server发送数据请求等操作,Server端的Session的虚函数ServiceL()会被调用,在参数RMessage2中会包括Client的请求信息。根据 aMessage.Function()的值做相应的处理。处理完后调用aMessage.Complete( KErrNone );来告知Client处理结束了,通常是增加请求线程上的信号量来告诉Client请求的完成。
既然,Server端有个Session,那么Client端也有个相应的Session了,答案是肯定的。它就是RSessionBase ,它是Client端的Session句柄,通过这个Client端的接口就可以和Server通信了。
/**
Clients normally define and implement a derived class to provide a richer interface.
*/
class RSessionBase : public RHandleBase
{
friend class RSubSessionBase;
。。。
IMPORT_C TInt Open(RMessagePtr2 aMessage,TInt aParam,TOwnerType aType=EOwnerProcess);
IMPORT_C TInt Open(RMessagePtr2 aMessage,TInt aParam,const TSecurityPolicy& aServerPolicy,TOwnerType aType=EOwnerProcess);
IMPORT_C TInt Open(TInt aArgumentIndex, TOwnerType
更多精彩
赞助商链接