datacommsserver/esockserver/test/protocols/ipc/IPC_MAIN.H
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 1997-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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #if !defined(__IPC_MAIN_H__)
       
    17 #define __IPC_MAIN_H__
       
    18 
       
    19 #include <es_sock.h>
       
    20 #include <es_prot.h>
       
    21 #include <e32base_private.h>
       
    22 
       
    23 class CIpcProtocolFamily: public CProtocolFamilyBase
       
    24 /**
       
    25 @internalComponent
       
    26 */
       
    27 	{
       
    28 private:
       
    29 	CIpcProtocolFamily();	
       
    30 public:
       
    31 	static CIpcProtocolFamily * NewL();
       
    32 	TInt Install();
       
    33 	TInt Remove();
       
    34 	CProtocolBase * NewProtocolL(TUint aSockType,TUint aProtocol);
       
    35 	TUint ProtocolList(TServerProtocolDesc *& aProtocolList);
       
    36 	};
       
    37 
       
    38 class CIpcProvdBase;
       
    39 class CIpcProtocolHolder : public CBase
       
    40 /**
       
    41 @internalComponent
       
    42 */
       
    43 	{
       
    44 friend class CIpcProtocol;
       
    45 private:
       
    46 	CIpcProtocolHolder();
       
    47 public:
       
    48 	static CIpcProtocolHolder* NewL();
       
    49 // Protocol internal functions.
       
    50 	void SocketRemoved(TInt aPort);
       
    51 	TInt GetNextFreePort();
       
    52 	TInt CheckAndAllocatePortNumber(TInt aPort);
       
    53 	void Add(CIpcProvdBase* aSAP);
       
    54 	CIpcProvdBase* FindPeerForConnection(TInt aPort);
       
    55 	~CIpcProtocolHolder();
       
    56 private:
       
    57 	TDblQue<CIpcProvdBase> iSAPs;
       
    58 	TInt iNumSockets;
       
    59 	CBitMapAllocator* iPortNumbers;
       
    60 	};
       
    61 
       
    62 class CIpcProtocol: public CProtocolBase
       
    63 /**
       
    64 @internalComponent
       
    65 */
       
    66 	{
       
    67 public:
       
    68 	virtual ~CIpcProtocol();
       
    69 	static CIpcProtocol *NewL(TInt aProtocol);
       
    70 
       
    71 // Calls from the socket server which we implement
       
    72 	CServProviderBase *NewSAPL(TUint aProtocol);
       
    73 	void InitL(TDesC& aTag);
       
    74 	void StartL(void);
       
    75 	TBool CanCreateSockets();
       
    76 	void Identify(TServerProtocolDesc *)const;
       
    77 
       
    78 // Calls from the socket server which we don't implement
       
    79 	virtual CHostResolvProvdBase *NewHostResolverL();
       
    80 	virtual CServiceResolvProvdBase *NewServiceResolverL();
       
    81 	virtual CNetDBProvdBase* NewNetDatabaseL();
       
    82 
       
    83 // Calls from the socket server and other protocols which we just panic
       
    84 	void BindL(CProtocolBase *aProtocol, TUint anId);
       
    85 	virtual void BindToL(CProtocolBase *protocol);
       
    86 	TInt Send(RMBufChain &,CProtocolBase* aSourceProtocol);
       
    87 	void Process(RMBufChain &,CProtocolBase* aSourceProtocol);
       
    88 	TInt Send(TDes8 &, TSockAddr *to,TSockAddr *from,CProtocolBase* aSourceProtocol);
       
    89 	void Process(TDes8 & ,TSockAddr *from,TSockAddr *to,CProtocolBase* aSourceProtocol);
       
    90 	TInt GetOption(TUint level,TUint name,TDes8 &anOption,CProtocolBase* aSourceProtocol);
       
    91 	TInt SetOption(TUint level,TUint name,const TDesC8& option,CProtocolBase* aSourceProtocol);
       
    92 	void Error(TInt anError,CProtocolBase* aSourceProtocol);
       
    93 private:
       
    94 	CIpcProtocol(TInt aProtocol);
       
    95 private:
       
    96 	TInt iProtocol;
       
    97 	CIpcProtocolHolder* iStreamProtocolSAPs;
       
    98 	};
       
    99 
       
   100 class CIpcProvdBase : public CServProviderBase
       
   101 /**
       
   102 @internalComponent
       
   103 */
       
   104 	{
       
   105 friend class CIpcProtocolHolder;
       
   106 public:
       
   107 	enum TIpcProvdState {ECreated=0,EConnected,EWaitingConnect,EDisconnected};
       
   108 	virtual void RemName(TSockAddr &anAddr)const;
       
   109 	virtual void LocalName(TSockAddr &anAddr)const;
       
   110 	virtual TInt SetLocalName(TSockAddr &anAddr);
       
   111 	virtual TInt SetRemName(TSockAddr& anAddr);
       
   112 	virtual TInt GetOption(TUint level,TUint name,TDes8 &anOption)const;
       
   113 	virtual TInt SetOption(TUint level,TUint name,const TDesC8 &anOption);
       
   114 	virtual void AutoBind( void );
       
   115 	virtual void Ioctl(TUint level,TUint name,TDes8 *anOption);
       
   116 	virtual void CancelIoctl(TUint aLevel,TUint aName);
       
   117 	virtual TInt PassiveOpen(TUint aQue,const TDesC8 &aConnectionData);
       
   118 	virtual void Shutdown(TCloseType option,const TDesC8 &aDisconnectData);
       
   119 	virtual void ActiveOpen(const TDesC8 &aConnectionData);
       
   120 	virtual ~CIpcProvdBase();
       
   121 	virtual void Start();
       
   122 	virtual void ActiveOpen(void);
       
   123 	virtual void Shutdown(TCloseType option);
       
   124 	virtual TInt PassiveOpen(TUint aQue);
       
   125 	virtual void Disconnect();
       
   126 	void Connected(CIpcProvdBase& aSocket);
       
   127 // Pure virtual
       
   128 	virtual CIpcProvdBase* GetCloneSocket()=0;
       
   129 	virtual void NewData(TInt aLen)=0;
       
   130 	virtual void CanSend()=0;
       
   131 protected:
       
   132 	CIpcProvdBase(CIpcProtocolHolder* aProtocol);
       
   133 protected:
       
   134 	TIpcProvdState iState;
       
   135 	CIpcProtocolHolder* iProtocol;
       
   136 	TInt iLocalAddr;
       
   137 	TInt iRemoteAddr;
       
   138 	CIpcProvdBase* iConnection;
       
   139 public:
       
   140 	TDblQueLink iLink;
       
   141 	};
       
   142 
       
   143 class CIpcStreamProvd : public CIpcProvdBase
       
   144 /**
       
   145 @internalComponent
       
   146 */
       
   147 	{
       
   148 public:
       
   149 	void NewData(TInt aLen);
       
   150 	void CanSend();
       
   151 	virtual TUint Write(const TDesC8& aDesc,TUint options, TSockAddr* anAddr=NULL);
       
   152 	virtual void GetData(TDes8 &aDesc,TUint options,TSockAddr *anAddr=NULL);
       
   153 	static CIpcStreamProvd* NewL(CIpcProtocolHolder* aProtocol);
       
   154 	virtual CIpcProvdBase* GetCloneSocket();
       
   155 private:
       
   156 	CIpcStreamProvd(CIpcProtocolHolder* aProtocol);
       
   157 	CCirBuffer iBuffer;
       
   158 	};
       
   159 
       
   160 /**
       
   161 @internalComponent
       
   162 */
       
   163 enum TIPCProtPanic
       
   164 	{
       
   165 	ECantBind,
       
   166 	ECantBindTo,
       
   167 	ESendCallCantBind,
       
   168 	EProcessCallCantBind,
       
   169 	EErrorUpCallCantBind,
       
   170 	ESetOptionCallCantBind,
       
   171 	EGetOptionCallCantBind,
       
   172 	ECantCreateNetDatabase,
       
   173 	ECantCreateServiceResolver,
       
   174 	ECantCreateHostResolver,
       
   175 	EBadWriteCall,
       
   176 	EBadGetDataCall,
       
   177 	EReadGetTooMuch,
       
   178 	ECloseWithoutDeleteingAllSockets,
       
   179 	EBMABroken
       
   180 	};
       
   181 
       
   182 /**
       
   183 @internalComponent
       
   184 */
       
   185 void Panic(TIPCProtPanic aPanic);
       
   186 
       
   187 #endif