|
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 CMSRPMESSAGEHANDLER_H_ |
|
18 #define CMSRPMESSAGEHANDLER_H_ |
|
19 |
|
20 // INCLUDES |
|
21 #include <e32base.h> |
|
22 #include <f32file.h> |
|
23 |
|
24 #include "MSRPCommon.h" |
|
25 #include "MMSRPMessageHandler.h" |
|
26 #include "MMSRPIncomingMessage.h" |
|
27 #include "MMSRPOutgoingMessage.h" |
|
28 #include "MMSRPWriterObserver.h" |
|
29 #include "CMSRPMessageChunkState.h" |
|
30 |
|
31 // Forward declarations |
|
32 class MMSRPMessageHandler; |
|
33 class MMSRPIncomingMessage; |
|
34 class MMSRPOutgoingMessage; |
|
35 class MMSRPWriterObserver; |
|
36 class MMSRPMessageObserver; |
|
37 class CMSRPMessage; |
|
38 class CMSRPResponse; |
|
39 class CMSRPReport; |
|
40 class CMSRPMessageBase; |
|
41 class RStringF; |
|
42 |
|
43 // Constants |
|
44 const TInt KMaxBufferSize = 2500; |
|
45 const TInt KSmallBuffer = 1024; |
|
46 const TInt KMaxChunkReadSize = 65000; |
|
47 // Class declaration |
|
48 |
|
49 /* MSRP Message handler |
|
50 * |
|
51 */ |
|
52 |
|
53 class CMSRPMessageHandler : public CBase, public MMSRPMessageHandler, |
|
54 public MMSRPIncomingMessage, public MMSRPOutgoingMessage, |
|
55 public MMSRPWriterObserver |
|
56 { |
|
57 public: |
|
58 |
|
59 enum TMSRPMessageState |
|
60 { |
|
61 EIdle, |
|
62 EInProgress, |
|
63 EChunkSent, |
|
64 EMessageSent, |
|
65 EWaitingForResponse, |
|
66 EWaitingForReport, |
|
67 EMessageDone |
|
68 }; |
|
69 |
|
70 /* Two-Phased constructor |
|
71 * |
|
72 */ |
|
73 static CMSRPMessageHandler* NewL( MMSRPMessageObserver* aMessageObserver, |
|
74 const TDesC8& aMessage ); |
|
75 |
|
76 static CMSRPMessageHandler* NewLC( MMSRPMessageObserver* aMessageObserver, |
|
77 const TDesC8& aMessage ); |
|
78 |
|
79 static CMSRPMessageHandler* NewL( TMSRPMessageType aMessageType ); |
|
80 |
|
81 static CMSRPMessageHandler* NewLC( TMSRPMessageType aMessageType ); |
|
82 |
|
83 /** |
|
84 * Destructor. |
|
85 */ |
|
86 ~CMSRPMessageHandler(); |
|
87 |
|
88 static TInt LinkOffset(); |
|
89 TSglQueLink iLink; |
|
90 |
|
91 public: // From base classes |
|
92 |
|
93 // From MMSRPWriterObserver |
|
94 TWriteStatus GetSendBufferL( TPtrC8& aData, TBool aInterrupt ); |
|
95 |
|
96 MMSRPWriterObserver::TMsgStatus WriteDoneL( TInt aStatus ); |
|
97 |
|
98 // From MMSRPMessageHandler |
|
99 void AddHeaderL( TMsrpHeaderType aHeaderType, TPtrC8& aHeaderValue, |
|
100 TPtrC8& aHeaderTypeAndValue ); |
|
101 |
|
102 void AddContentL( TPtrC8& aContent ); |
|
103 |
|
104 void SetTransactionId( TPtrC8& aTransactionId ); |
|
105 |
|
106 void SetStatusOfResponseL( TPtrC8& aStatusCode, TPtrC8& aStatusMessage ); |
|
107 |
|
108 void EndOfMessageL( TMsrpMsgEndStatus aStatus ); |
|
109 |
|
110 // From MMSRPIncomingMessage |
|
111 TMSRPMessageType MessageType( ); |
|
112 |
|
113 CMSRPMessage* GetIncomingMessage( ); |
|
114 |
|
115 TBool SendResponseL( MMSRPMessageObserver* aMessageObserver, |
|
116 MMSRPConnection& aConnection, TUint aResponseCode ); |
|
117 |
|
118 TDesC8& TransactionId( ); |
|
119 |
|
120 CMSRPResponse* GetIncomingResponse( ); |
|
121 |
|
122 // From MMSRPOutgoingMessage |
|
123 void SendMessageL( MMSRPConnection& aConnection ); |
|
124 |
|
125 TBool IsOwnerOfResponse( MMSRPIncomingMessage& aIncomingMessage ); |
|
126 |
|
127 TBool ConsumeResponseL( MMSRPIncomingMessage& aIncomingMessage ); |
|
128 |
|
129 TBool IsMessageComplete(); |
|
130 |
|
131 TBool GetSendResultL( TUint &aErrorCode, HBufC8* &aMessageId ); |
|
132 |
|
133 void SendFileL( MMSRPConnection& aConnection ); |
|
134 |
|
135 void ConsumeFileResponseL( MMSRPIncomingMessage& aIncomingMessage ); |
|
136 |
|
137 |
|
138 |
|
139 TBool IsInFile(); |
|
140 |
|
141 void ReceiveFileL( ); |
|
142 |
|
143 TBool FileTransferComplete( ); |
|
144 |
|
145 void WritetoFileL(CMSRPMessageHandler *aIncomingMsgHandler ); |
|
146 |
|
147 void UpdateResponseStateL(CMSRPMessageHandler *incomingMsgHandler); |
|
148 |
|
149 TBool IfResponseReqL(); |
|
150 private: |
|
151 // Constructor |
|
152 CMSRPMessageHandler( MMSRPMessageObserver* aMessageObserver ); |
|
153 |
|
154 CMSRPMessageHandler( ); |
|
155 |
|
156 void ConstructL( const TDesC8& aMessage ); |
|
157 |
|
158 void ConstructL( TMSRPMessageType aMessageType ); |
|
159 |
|
160 // Member Functions |
|
161 void CreateByteRangeHeaderL(); |
|
162 |
|
163 void CreateTransactionId(); |
|
164 |
|
165 void WriteInitialLineToBufferL(); |
|
166 |
|
167 void WriteHeadersToBufferL(); |
|
168 |
|
169 void WriteContentToBuffer(); |
|
170 |
|
171 void WriteFileContentToBufferL(); |
|
172 |
|
173 void WriteEndLineToBuffer(TMsrpMsgEndStatus = EMessageEnd ); |
|
174 |
|
175 TInt ExtractByteRangeParams( TDesC8& aHeaderValue, TInt& aStartPos, |
|
176 TInt& aEndPos, TInt& aTotal ); |
|
177 |
|
178 RStringF GetStatusStringL( TUint aStatusCode ); |
|
179 |
|
180 TUint CheckValidityOfMessage( TMSRPMessageType aMessageType, |
|
181 CMSRPMessageBase* aMessage ); |
|
182 |
|
183 TInt FillFileBufferL(); |
|
184 |
|
185 void SendFileChunkL( MMSRPConnection& aConnection ); |
|
186 |
|
187 |
|
188 |
|
189 void SendFileStateL( TInt aBytes ); |
|
190 |
|
191 void ReceiveFileStateL( TInt aBytes ); |
|
192 |
|
193 void WriteChunkToFileL(const TDesC8& aFileChunk ,TDesC8& aTransactionId); |
|
194 private: |
|
195 |
|
196 // Server interface |
|
197 MMSRPMessageObserver* iMSRPMessageObserver; |
|
198 |
|
199 // Transaction Id |
|
200 TBuf8< KMaxLengthOfTransactionIdString > iTransactionId; |
|
201 |
|
202 // MSRP Message |
|
203 CMSRPMessage* iMessage; |
|
204 |
|
205 // MSRP response; |
|
206 CMSRPResponse* iResponse; |
|
207 |
|
208 TBool iResponseNeeded; |
|
209 |
|
210 RBuf8 iBuffer; |
|
211 |
|
212 TPtrC8 iContentPtr; |
|
213 |
|
214 TBool iWriteDone; |
|
215 |
|
216 TMSRPMessageType iActiveMsgType; |
|
217 |
|
218 TMSRPMessageState iState; |
|
219 |
|
220 TMsrpMsgEndStatus iMsgEndStatus; |
|
221 |
|
222 /* For File Use Case */ |
|
223 TBool isFile; |
|
224 RFile iFile; |
|
225 RFs iFs; |
|
226 TInt iFileSize; |
|
227 |
|
228 TBool iInterrupt; |
|
229 HBufC8* iFileBuffer; |
|
230 TBool iFileTransferComplete; |
|
231 RPointerArray <CMSRPMessageChunkState> iChunkList; |
|
232 TInt iBufPosInFile; //file buffer start pos in file |
|
233 TInt iEndPosInBuffer; |
|
234 TInt iStartPosInBuffer; |
|
235 TInt iFileBytesSent; |
|
236 |
|
237 TBool iProgress; |
|
238 TInt iNotifiedBytes; |
|
239 TInt iPendingBytes; |
|
240 }; |
|
241 |
|
242 #endif /* CMSRPMESSAGEHANDLER_H_ */ |