commands/testexecute/ProxyServer.h
changeset 5 9c58252c6740
equal deleted inserted replaced
4:c061fa280d92 5:9c58252c6740
       
     1 // ProxyServer.h
       
     2 // 
       
     3 // Copyright (c) 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 #ifndef PROXYSERVER_H
       
    13 #define PROXYSERVER_H
       
    14 
       
    15 #include <fshell/memoryaccess.h>
       
    16 #include <e32base.h>
       
    17 
       
    18 class CProxySession;
       
    19 
       
    20 class MMessageHandler
       
    21 	{
       
    22 public:
       
    23 	virtual TBool HandleMessageL(CProxySession* aSession, const RMessage2& aMessage)=0;
       
    24 	};
       
    25 
       
    26 NONSHARABLE_CLASS(CProxyServer) : public CServer2
       
    27 	{
       
    28 public:
       
    29 	static CProxyServer* NewInSeparateThreadL(const TDesC& aServerToReplace, MMessageHandler* aHandler=NULL);
       
    30 	void Destroy(); // This should be used instead of delete - the server object has to be destroyed from the thread in which it was started
       
    31 	MMessageHandler* Handler() const;
       
    32 
       
    33 protected:
       
    34 	CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
       
    35 
       
    36 private:
       
    37 	~CProxyServer();
       
    38 	CProxyServer(const TDesC& aServerToReplace, MMessageHandler* aHandler);
       
    39 	void ConstructL();
       
    40 	void ThreadConstructL();
       
    41 	static TInt StartServerThreadFunction(TAny* aSelf);
       
    42 	void ServerThreadRunL();
       
    43 	static TInt Shutdown(TAny* aSelf);
       
    44 
       
    45 private:
       
    46 	RMemoryAccess iMemAccess;
       
    47 	TBool iProxying;
       
    48 	TName iServerName;
       
    49 	TName iRealServerName;
       
    50 	RThread iServerThread;
       
    51 	MMessageHandler* iHandler;
       
    52 	CAsyncCallBack* iShutdownCallback;
       
    53 	};
       
    54 
       
    55 class RUnderlyingSession : public RSessionBase
       
    56 	{
       
    57 public:
       
    58 	friend class CProxySession;
       
    59 	friend class CAsyncWaiter;
       
    60 	};
       
    61 
       
    62 NONSHARABLE_CLASS(CProxySession) : public CSession2
       
    63 	{
       
    64 public:
       
    65 	void ConstructL(const TDesC& aServerName, const TVersion& aVersion);
       
    66 	void ForwardUnhandledMessageL(const RMessage2& aMessage);
       
    67 	void ForwardMessageArgsL(const RMessage2& aMessage, const TIpcArgs& aArgs);
       
    68 
       
    69 protected:
       
    70 	void ServiceL(const RMessage2 &aMessage);
       
    71 	void Disconnect(const RMessage2 &aMessage);
       
    72 
       
    73 private:
       
    74 	CProxyServer& Server();
       
    75 	const CProxyServer& Server() const;
       
    76 
       
    77 private:
       
    78 	RUnderlyingSession iSession;
       
    79 	};
       
    80 
       
    81 
       
    82 #endif