|
1 // Copyright (c) 2005-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 // eintsockimpl.h |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #ifndef __EINTSOCKIMPL_H__ |
|
24 #define __EINTSOCKIMPL_H__ |
|
25 |
|
26 #include <e32std.h> |
|
27 #include <es_prot.h> |
|
28 #include <ss_std.h> |
|
29 #include <es_mbuf.h> |
|
30 #include "ss_eintsock_msgs.h" |
|
31 |
|
32 #include <comms-infras/ss_intsock.h> |
|
33 |
|
34 class CInternalServiceResolver; // not implemented as no-one wants it at the moment |
|
35 class CInternalConnection; // not implemented, as too dodgy to bypass multiplexing in esock without some serious thought |
|
36 |
|
37 class RInternalSocket; |
|
38 class TSockXferLength; |
|
39 class TTransportUserStorage; |
|
40 |
|
41 using namespace ESock; |
|
42 |
|
43 // This is not really a C type class. |
|
44 NONSHARABLE_CLASS(CIntSocketMessage) : public CBase, public AMessage |
|
45 { |
|
46 public: |
|
47 virtual void AcquireMessage ( AMessage* aMessage ); |
|
48 inline void SetMessage ( TEIntSockOpMsgWrapper& aMessage ); |
|
49 |
|
50 private: |
|
51 virtual TInt ReadDes(TInt aSrcParamIndex,TDes8 &aDes,TInt anOffset=0 ); |
|
52 virtual TInt ReadInt(TInt aSrcParamIndex); |
|
53 virtual TInt ReadMBuf(TInt aSrcParamIndex, RMBufChain& aBufChain); |
|
54 virtual void InitMBuf(TInt aParamIndex); |
|
55 virtual TInt WriteDes(TInt aDstParamIndex,const TDesC8& aDes,TInt anOffset=0); |
|
56 virtual TInt WriteMBuf(TInt aDstParamIndex,RMBufChain& aBufChain); |
|
57 |
|
58 virtual void CompleteMessage(TInt anError); |
|
59 virtual TBool IsNull (TInt aParamIndex); |
|
60 |
|
61 inline TEIntSockOpMsgWrapper& Message (); |
|
62 |
|
63 private: |
|
64 TEIntSockOpMsgWrapper iMessage; |
|
65 }; |
|
66 |
|
67 |
|
68 // A simple default security checker |
|
69 class TDefaultSecurityChecker : public MProvdSecurityChecker |
|
70 { |
|
71 public: |
|
72 TInt CheckPolicy (const TSecurityPolicy& /*aPolicy*/, const char * /*aDiagnostic*/) |
|
73 { |
|
74 return KErrNone; |
|
75 } |
|
76 }; |
|
77 |
|
78 // This class is needed for synchronous open |
|
79 NONSHARABLE_CLASS(CAsyncWaiter) : public CActive |
|
80 { |
|
81 public: |
|
82 static CAsyncWaiter* New (); |
|
83 ~CAsyncWaiter (); |
|
84 |
|
85 TInt StartAndWait (); |
|
86 |
|
87 protected: |
|
88 CAsyncWaiter (); |
|
89 |
|
90 // CActive |
|
91 void RunL (); |
|
92 void DoCancel (); |
|
93 }; |
|
94 |
|
95 |
|
96 NONSHARABLE_CLASS(CInternalSockSubSession) : public CBase, public MProvdSecurityChecker |
|
97 { |
|
98 public: |
|
99 class TParameters |
|
100 { |
|
101 public: |
|
102 TParameters(CommsFW::TWorkerId aClientWorkerId, CommsFW::MCommsTransportSender* aSender, TTransportUserStorage& aStorage, const Messages::TNodeId& aServerCookie, TRequestWrapper* aRequest /*TWorkerId aClientWorkerId, CommsFW::TWorkerId aServerWorkerId*/); |
|
103 public: |
|
104 TTransportUserStorage& iStorage; |
|
105 CommsFW::TWorkerId iClientWorkerId; |
|
106 Messages::TNodeId iServerCookie; |
|
107 |
|
108 // Used by the client for subsequent calls. Presumes client remains in same thread as when opened |
|
109 // RInternalSocket must be Transfer()'d if client thread changes |
|
110 CommsFW::MCommsTransportSender* iSender; |
|
111 TRequestWrapper* iRequest; |
|
112 }; |
|
113 |
|
114 IMPORT_C static void ProcessMessage(const Den::TWorkerTransportMsg& aMsg, TRequestWrapper& aRequest, TTransportUserStorage& aStorage, CommsFW::TWorkerId aPeerWorkerId); |
|
115 IMPORT_C static void OnPeerDeath(CommsFW::TWorkerId aPeer, TTransportUserStorage& aStorage); |
|
116 IMPORT_C static void Shutdown(TBool aAlreadyDead, TTransportUserStorage& aStorage); |
|
117 |
|
118 inline CommsFW::TWorkerId ClientWorkerId() const; |
|
119 inline CommsFW::TWorkerId ServerWorkerId() const; |
|
120 CommsFW::MCommsTransportSender* Sender() const; |
|
121 void SetSender(CommsFW::MCommsTransportSender* aSender); |
|
122 |
|
123 inline TInt SendReceiveMsg(Den::TWorkerTransportMsg& aMsg); |
|
124 inline void SendMsg(Den::TWorkerTransportMsg& aMsg); |
|
125 static TInt SendReceiveMsg(Den::TWorkerTransportMsg& aMsg, CommsFW::MCommsTransportSender* aSender, const Messages::TNodeId& aServerCookie); |
|
126 static void SendMsg(Den::TWorkerTransportMsg& aMsg, CommsFW::MCommsTransportSender* aSender, const Messages::TNodeId& aServerCookie); |
|
127 static TInt SendReceiveMsgAsync( Den::TWorkerTransportMsg& aMsg, CommsFW::MCommsTransportSender* aSender, const Messages::TNodeId& aServerCookie ); |
|
128 |
|
129 virtual void FinalCompleteAllBlockedMessages(TInt aResult) = 0; |
|
130 |
|
131 virtual TInt CheckPolicy(const TSecurityPolicy& /*aPolicy*/, const char* /*aDiagnostic*/); |
|
132 static TInt LinkOffset(); |
|
133 protected: |
|
134 typedef TDblQue<CInternalSockSubSession> TSubSessions; |
|
135 class TGlobals |
|
136 { |
|
137 public: |
|
138 TGlobals(); |
|
139 TSubSessions iSubSessions; |
|
140 }; |
|
141 |
|
142 CInternalSockSubSession(const TParameters& aParams); |
|
143 void ConstructL(const TParameters& aParams); |
|
144 |
|
145 static TGlobals* Globals(TTransportUserStorage& aStorage); |
|
146 |
|
147 static TSubSessions& SubSessions(TTransportUserStorage& aStorage); |
|
148 static void AddSubsession(TTransportUserStorage& aStorage, CInternalSockSubSession* aSubSession); |
|
149 static void ProcessMessageL(const Den::TWorkerTransportMsg& aMsg, TRequestWrapper& aRequest, TTransportUserStorage& aStorage, CommsFW::TWorkerId aPeerWorkerId); |
|
150 static TInt PerformOperationL(const TEIntSockMsg& aMsg, TRequestWrapper& aRequest); |
|
151 |
|
152 private: |
|
153 TInt iAccessCount; |
|
154 CommsFW::TWorkerId iClientWorkerId; |
|
155 // TWorkerId iServerWorkerId; |
|
156 Messages::TNodeId iServerCookie; |
|
157 CommsFW::MCommsTransportSender* iSender; // presumes client remains in same thread as when opened - safe for now |
|
158 protected: |
|
159 TDblQueLink iLink; |
|
160 CWorkerThread* iOwnerThread; |
|
161 }; |
|
162 |
|
163 |
|
164 NONSHARABLE_CLASS(CInternalSocketImpl) : public CInternalSockSubSession, public ASocket |
|
165 /** |
|
166 Implementation of RInternalSocket |
|
167 */ |
|
168 { |
|
169 typedef CInternalSockSubSession inherited; |
|
170 friend class CInternalSockSubSession; |
|
171 friend class ProtocolManager; |
|
172 private: |
|
173 // Various bits to create a new internal socket in different ways |
|
174 static CInternalSocketImpl* NewL ( const CInternalSockSubSession::TParameters& aParams ); |
|
175 static CInternalSocketImpl* NewL ( const CInternalSockSubSession::TParameters& aParams, TServerProtocolDesc* aServiceInfo, CProtocolBase* aProt ); |
|
176 ~CInternalSocketImpl(); |
|
177 |
|
178 virtual void FinalCompleteAllBlockedMessages(TInt aResult); |
|
179 |
|
180 void SetImpl ( CInternalSocketImpl*& aImpl ); |
|
181 |
|
182 virtual TDes8* BorrowTemporaryBuffer(TInt aSize); |
|
183 virtual TDes8* BorrowTemporaryBufferL(TInt aSize); |
|
184 private: |
|
185 CInternalSocketImpl(const CInternalSockSubSession::TParameters& aParams, TUint aSockType); |
|
186 void ConstructL(const TParameters& aParams, TServerProtocolDesc* aServiceInfo, CProtocolBase* aProt); |
|
187 void InitUserMessageL ( TSocketMessage aMessage ); |
|
188 |
|
189 void SendL ( TSockMess aWriteFunction, TEIntSockOpMsgWrapper& aMsg ); |
|
190 void RecvL ( TSockMess aReadFunction, TEIntSockOpMsgWrapper& aMsg ); |
|
191 void CancelOpen (); |
|
192 |
|
193 // From ASocket |
|
194 // ---------------- |
|
195 virtual void SetClosing(); |
|
196 virtual TBool IsClosing(); |
|
197 |
|
198 virtual void DontCompleteCurrentRequest(); |
|
199 |
|
200 virtual ASocket* InitiateAcceptingSocket(); |
|
201 virtual ASocket* GetAcceptingSocket(); |
|
202 |
|
203 virtual void SetReturn(TInt aReturnValue) const; |
|
204 |
|
205 virtual void GetOwnerInfo(TProcessId& aProcId, TSoOwnerInfo& aInfo, TThreadId& aThreadId); |
|
206 virtual TInt SecurityCheck(); |
|
207 |
|
208 virtual void CompleteFlowRequestMessage(TInt aErr); |
|
209 |
|
210 virtual void InitiateDestruction(); |
|
211 virtual TBool CloseSocket(); |
|
212 virtual void PanicSocketClient(TESockPanic aPanic); |
|
213 // -------------- |
|
214 |
|
215 TEIntSockOpMsgWrapper& GetMessage (TSocketMessage aMessage); |
|
216 TBool ShouldCompleteCurrentRequest () const; |
|
217 inline TInt Return () const; |
|
218 void AdoptFlowRequest ( TRequestWrapper& aRequest ); |
|
219 void SetCurrentMessage ( TEIntSockOpMsgWrapper& aIntSockMsg ); |
|
220 void CompleteCurrentRequest ( TBool aValue ); |
|
221 |
|
222 private: |
|
223 TBool iComplete:1; |
|
224 TBool iClosing:1; |
|
225 mutable TInt iReturn; |
|
226 |
|
227 TRequestWrapper iFlowRequest; |
|
228 CInternalSocketImpl** iImpl; // This will hold the reference to the pointer that RInternalSocket holds. |
|
229 // It will be set when the the internal socket is actuall created. in case of |
|
230 // an error it will be NULL and socket will do a self deletion. |
|
231 CProtocolBase* iProtocol; |
|
232 }; |
|
233 |
|
234 #include "ss_eintsockimpl.inl" |
|
235 |
|
236 #endif // __EINTSOCKIMPL_H__ |
|
237 |