|
1 /* |
|
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Initial Contributors: |
|
9 * Nokia Corporation - initial contribution. |
|
10 * Contributors: |
|
11 * |
|
12 * Description: |
|
13 * MSRP Implementation |
|
14 * |
|
15 */ |
|
16 |
|
17 #ifndef CMSRPSERVERSUBSESSION_H_ |
|
18 #define CMSRPSERVERSUBSESSION_H_ |
|
19 |
|
20 #include <e32std.h> |
|
21 #include <e32base.h> |
|
22 #include <e32math.h> |
|
23 #include <in_sock.h> |
|
24 |
|
25 |
|
26 #include "MMSRPConnectionObserver.h" |
|
27 #include "MMSRPMessageObserver.h" |
|
28 #include "MSRPServerCommon.h" |
|
29 #include "CMSRPMessageHandler.h" |
|
30 |
|
31 const TInt KMSRPSessIdLength=12; |
|
32 |
|
33 // Forward Declarations |
|
34 class CMSRPServerSubSession; |
|
35 class CMSRPServerSession; |
|
36 class MMSRPConnectionManager; |
|
37 class CMSRPMessageBase; |
|
38 class MMSRPConnection; |
|
39 class MMSRPIncomingMessage; |
|
40 class CMSRPMessageHandler; |
|
41 class CMSRPFromToHeaderBase; |
|
42 class CMSRPToPathHeader; |
|
43 class CMSRPHeaderBase; |
|
44 |
|
45 class TStateBase; |
|
46 class CStateFactory; |
|
47 |
|
48 |
|
49 class CRMessageContainer: public CBase |
|
50 { |
|
51 public: |
|
52 |
|
53 CRMessageContainer(); |
|
54 ~CRMessageContainer(); |
|
55 TBool set(const RMessage2& aMessage); |
|
56 |
|
57 TInt CRMessageContainer::Write(TInt aParam,const TDesC8& aDes,TInt aOffset=0) const; |
|
58 void ReadL(TInt aParam,TDes8& aDes,TInt aOffset=0) const; |
|
59 |
|
60 void Complete(TInt aReason); |
|
61 |
|
62 TBool Check(); |
|
63 |
|
64 TBool iStatus; |
|
65 RMessage2 iMsg; |
|
66 |
|
67 }; |
|
68 |
|
69 |
|
70 template <class T> |
|
71 class CQueue : public CBase |
|
72 { |
|
73 public: |
|
74 inline CQueue(); |
|
75 virtual ~CQueue(){}; |
|
76 inline TBool Queue(T& element); |
|
77 inline T* DeQueue(); |
|
78 inline TBool isEmpty(); |
|
79 |
|
80 inline T* getHead(); |
|
81 |
|
82 virtual inline T* getMatch(T* aMatch); |
|
83 |
|
84 TInt inline Length(){ |
|
85 #ifdef _DEBUG |
|
86 if(0 == iQLenght && !iList.IsEmpty()) |
|
87 { |
|
88 MSRPLOG("CQueue::Lenght!! Problem!! in the queue lenght calculations"); |
|
89 } |
|
90 #endif |
|
91 return iQLenght; |
|
92 |
|
93 }; |
|
94 |
|
95 inline void CQueue<T>::Destroy(); |
|
96 |
|
97 protected: |
|
98 TInt iQLenght; |
|
99 |
|
100 TSglQue<T> iList; |
|
101 |
|
102 }; |
|
103 |
|
104 |
|
105 template <class T> |
|
106 CQueue<T>::CQueue(): iList(T::LinkOffset()),iQLenght(0){} |
|
107 |
|
108 template <class T> |
|
109 TBool CQueue<T>::Queue(T& element) |
|
110 { |
|
111 iList.AddLast(element); |
|
112 iQLenght++; |
|
113 return TRUE; |
|
114 } |
|
115 |
|
116 template <class T> |
|
117 T* CQueue<T>::DeQueue() |
|
118 { |
|
119 T* element = NULL; |
|
120 if(!(iList.IsEmpty())) |
|
121 { |
|
122 element = iList.First(); |
|
123 iList.Remove(*element); |
|
124 iQLenght--; |
|
125 } |
|
126 |
|
127 return element; |
|
128 } |
|
129 |
|
130 template <class T> |
|
131 TBool CQueue<T>::isEmpty() |
|
132 { |
|
133 return iList.IsEmpty(); |
|
134 } |
|
135 |
|
136 template <class T> |
|
137 T* CQueue<T>::getHead() |
|
138 { |
|
139 T* element = NULL; |
|
140 if(!(iList.IsEmpty())) |
|
141 { |
|
142 element = iList.First(); |
|
143 } |
|
144 return element; |
|
145 } |
|
146 |
|
147 template <class T> |
|
148 T* CQueue<T>::getMatch(T* aMatch) |
|
149 { |
|
150 aMatch; |
|
151 return NULL; |
|
152 } |
|
153 |
|
154 template<class T> |
|
155 inline void CQueue<T>::Destroy() |
|
156 { |
|
157 T* element = NULL; |
|
158 TSglQueIter<T> iter(iList); |
|
159 element = iter++; |
|
160 |
|
161 while(element) |
|
162 { |
|
163 iList.Remove(*element); |
|
164 delete element; |
|
165 element = iter++; |
|
166 iQLenght--; |
|
167 } |
|
168 |
|
169 } |
|
170 |
|
171 template<class T> |
|
172 class CQueueMsgHandlers : public CQueue<T> |
|
173 { |
|
174 public: |
|
175 CQueueMsgHandlers(); |
|
176 virtual ~CQueueMsgHandlers(){}; |
|
177 virtual inline T* getMatch(T*); |
|
178 |
|
179 virtual inline TBool explicitRemove(T* aElementToRemove); |
|
180 |
|
181 }; |
|
182 |
|
183 template<class T> |
|
184 CQueueMsgHandlers<T>::CQueueMsgHandlers() : CQueue<T>::CQueue(){} |
|
185 |
|
186 template<class T> |
|
187 T* CQueueMsgHandlers<T>::getMatch(T* aInCommingMsg) |
|
188 { |
|
189 // |
|
190 |
|
191 TSglQueIter<T> iterator(CQueue<T>::iList); |
|
192 iterator.SetToFirst(); |
|
193 T* iMatchingOwner; |
|
194 |
|
195 while((iMatchingOwner = iterator++)) |
|
196 { |
|
197 if(iMatchingOwner->IsOwnerOfResponse(*aInCommingMsg)) |
|
198 { |
|
199 return iMatchingOwner; |
|
200 } |
|
201 } |
|
202 |
|
203 return NULL; |
|
204 } |
|
205 |
|
206 template<class T> |
|
207 TBool CQueueMsgHandlers<T>::explicitRemove(T* aElementToRemove) |
|
208 { |
|
209 CQueue<T>::iList.Remove(*aElementToRemove); |
|
210 CQueue<T>::iQLenght--; |
|
211 return TRUE; |
|
212 |
|
213 } |
|
214 |
|
215 class CMSRPServerSubSession : public CBase, MMSRPConnectionObserver, MMSRPMessageObserver |
|
216 { |
|
217 public: |
|
218 |
|
219 enum TQueueType |
|
220 { |
|
221 TClientQueue, |
|
222 TInCommingMsgQueue |
|
223 }; |
|
224 |
|
225 static CMSRPServerSubSession* NewL( CMSRPServerSession& aServerSession, CStateFactory& aStateFactory ); |
|
226 |
|
227 static CMSRPServerSubSession* NewLC( CMSRPServerSession& aServerSession, CStateFactory& aStateFactory ); |
|
228 |
|
229 virtual ~CMSRPServerSubSession( ); |
|
230 |
|
231 TBool ServiceL( const RMessage2& aMessage ); |
|
232 |
|
233 // From MMSRPConnectionObserver |
|
234 void ConnectionStateL( TInt aNewState, TInt aStatus ); |
|
235 |
|
236 TBool MessageReceivedL( CMSRPMessageHandler* aMsg ); |
|
237 |
|
238 void UnclaimedMessageL( CMSRPMessageHandler* aMsg ); |
|
239 |
|
240 // From MMSRPMsgObserver |
|
241 void MessageSendCompleteL(); |
|
242 |
|
243 void MessageResponseSendCompleteL(CMSRPMessageHandler& aMsg); |
|
244 |
|
245 virtual void MessageSendProgressL(TInt aBytesSent, TInt aTotalBytes); |
|
246 |
|
247 virtual void MessageReceiveProgressL(TInt aBytesSent, TInt aTotalBytes); |
|
248 |
|
249 void WriterError(); |
|
250 |
|
251 CMSRPMessageHandler* ReceiveFileMsgHandler(); |
|
252 |
|
253 void NotifyFileReceiveResultToClientL(CMSRPMessageHandler *msgHandler); |
|
254 |
|
255 void NotifyFileSendResultToClientL(CMSRPMessageHandler *msgHandler); |
|
256 |
|
257 private: |
|
258 CMSRPServerSession& iServerSession; |
|
259 CMSRPServerSubSession( CMSRPServerSession& aServerSession, CStateFactory &aStateFactory); |
|
260 void ConstructL(); |
|
261 |
|
262 // ProcessEventL shall only take a event. The data associated with the event can be a |
|
263 // RMessage(Client to Server events), CSendBuffer(buffer being send out by connection manager), |
|
264 // CMSRPMessage(received message) or other such data. |
|
265 // The associated data is stored in the context and retrieved by the relevant state when needed. |
|
266 |
|
267 TBool CMSRPServerSubSession::ProcessEventL( TMSRPFSMEvent aEvent); |
|
268 |
|
269 HBufC8* CreateSubSessionIDL( ); |
|
270 |
|
271 void HandleLocalPathRequestL( const RMessage2& aMessage ); |
|
272 |
|
273 void HandleConnectRequestL( const RMessage2& aMessage ); |
|
274 |
|
275 void HandleListenConnectionsL( const RMessage2& aMessage ); |
|
276 void HandleListenMessagesL( const RMessage2& aMessage ); |
|
277 void HandleListenSendResultL( const RMessage2& aMessage ); |
|
278 |
|
279 void HandleSendMessageL( const RMessage2& aMessage ); |
|
280 |
|
281 void HandleCancelSendingL( const RMessage2& aMessage ); |
|
282 void HandleCancelReceivingL( const RMessage2& aMessage ); |
|
283 void HandleCancelSendRespListening( const RMessage2& aMessage ); |
|
284 |
|
285 MMSRPConnectionManager& ConnectionManager( ); |
|
286 |
|
287 void CompleteClient(TInt aReason); |
|
288 TInt Write(TInt aParam,const TDesC8& aDes); |
|
289 |
|
290 TBool QueueClientSendRequestsL(); |
|
291 |
|
292 TBool QueueSendMessages(CMSRPMessageHandler* aMessageHandlers); |
|
293 CMSRPMessageHandler* DeQueueSentMessage(); |
|
294 |
|
295 TBool QueueReceivedMessages(); |
|
296 |
|
297 // Utility functions. |
|
298 |
|
299 TBool sendResultToClientL(CMSRPMessageHandler *incommingMsgHandler); |
|
300 TBool sendMsgToClientL(CMSRPMessageHandler *incommingMsgHandler); |
|
301 TBool SendProgressToClientL(CMSRPMessageHandler *msgHandler); |
|
302 TBool ReceiveProgressToClientL(CMSRPMessageHandler *msgHandler); |
|
303 |
|
304 void ReadSendDataPckgL(); |
|
305 |
|
306 TBool listnerSetupComplete(); |
|
307 |
|
308 CMSRPServerSubSession::TQueueType getQToProcess(); |
|
309 |
|
310 TBool QueuesEmpty(); |
|
311 TBool informConnectionReadyToClient(); |
|
312 |
|
313 void QueueLog(); |
|
314 |
|
315 TBool checkMessageForSelfL(CMSRPMessageHandler *aMsgHandler); |
|
316 TBool matchSessionIDL(const CMSRPHeaderBase *aPathHeader, TBool local = TRUE); |
|
317 TPtrC8 extractSessionID(const TDesC8& aPathBuffer); |
|
318 |
|
319 CStateFactory& StateFactory(); |
|
320 |
|
321 private: |
|
322 |
|
323 // Session Data. |
|
324 HBufC8* iLocalSessionID; |
|
325 HBufC8* iRemoteSessionID; |
|
326 |
|
327 // Connection info bundle. |
|
328 TBuf8< KMaxLengthOfHost > iRemoteHost; |
|
329 TUint iRemotePort; |
|
330 TConnectionDirection iConnDirection; |
|
331 |
|
332 // Local Host info |
|
333 TBuf< KMaxLengthOfHost > iLocalHost; |
|
334 |
|
335 MMSRPConnection* iConnection; |
|
336 |
|
337 // connect package from the client |
|
338 TPckgBuf< TLocalPathMSRPData > iLocalPathMSRPDataPckg; |
|
339 TPckgBuf< TConnectMSRPData > iConnectMSRPdataPckg; |
|
340 |
|
341 // listen package from the client |
|
342 TPckgBuf< TListenMSRPData > iListenMSRPdataPckg; |
|
343 |
|
344 // send package to the client |
|
345 TPckgBuf< TSendMSRPData > iSendMSRPdataPckg; |
|
346 |
|
347 // result of sent messages package to the client |
|
348 TPckgBuf< TListenSendResultMSRPData > iSendResultListenMSRPDataPckg; |
|
349 |
|
350 // Temorary Event Data. |
|
351 const RMessage2* iClientMessage; |
|
352 CMSRPMessageHandler* iReceivedMsg; |
|
353 CMSRPMessageHandler* iReceivedResp; |
|
354 CMSRPMessageHandler* iReceiveFileMsgHdler; |
|
355 TBool iFileShare; //is previous state file share |
|
356 TBool iSendCompleteNotify; // |
|
357 TBool iReceiveCompleteNotify; |
|
358 TInt iBytesTransferred; |
|
359 TInt iTotalBytes; |
|
360 |
|
361 // Client Listners waiting to be completed. |
|
362 |
|
363 // Listner for response of Connect request. |
|
364 CRMessageContainer iConnectionListner; |
|
365 // Listner for response of Listen request(iMessage set as false) and also |
|
366 // listner for incomming messages(iMessage set as TRUE). |
|
367 CRMessageContainer iIncommingMessageListner; |
|
368 // Listner for Responses to sent messages. |
|
369 CRMessageContainer iResponseListner; |
|
370 |
|
371 CStateFactory& iStateFactory; // Not owned. |
|
372 TStateBase* iState; // Not owned. |
|
373 |
|
374 // The current message handler that is doing a MSRP Send and |
|
375 // for which the subsession has still not rerceived a sendmessagecomplete event. |
|
376 // Once the sendmessage completed is received the message handler is put on the |
|
377 // OutGoingMessage queue where it waits for a response to arrive. |
|
378 CMSRPMessageHandler *iCurrentMsgHandler; |
|
379 |
|
380 // Queues. |
|
381 CQueueMsgHandlers<CMSRPMessageHandler> iOutMsgQ; |
|
382 CQueueMsgHandlers<CMSRPMessageHandler> iInCommingMsgQ; |
|
383 CQueueMsgHandlers<CMSRPMessageHandler> iPendingSendMsgQ; |
|
384 CQueueMsgHandlers<CMSRPMessageHandler> iPendingForDeletionQ; |
|
385 |
|
386 friend class TStateBase; |
|
387 friend class TStateIdle; |
|
388 friend class TStateConnecting; |
|
389 friend class TStateActive; |
|
390 friend class TStateActiveSend; |
|
391 friend class TStateWaitForClient; |
|
392 friend class TStateFileShare; |
|
393 friend class TStateError; // Not a very good thing !! Need change. |
|
394 |
|
395 #ifdef __UT_TSTATEFACTORY_H__ |
|
396 friend class UT_TStateFactory; |
|
397 #endif |
|
398 |
|
399 }; |
|
400 |
|
401 #endif /* CMSRPSERVERSUBSESSION_H_ */ |