39 class CMSRPReport; |
38 class CMSRPReport; |
40 class CMSRPMessageBase; |
39 class CMSRPMessageBase; |
41 class RStringF; |
40 class RStringF; |
42 |
41 |
43 // Constants |
42 // Constants |
44 const TInt KMaxBufferSize = 2500; |
43 //const TInt KMaxBufferSize = 2500; |
|
44 const TInt KMaxBufferSize = 10000; |
45 const TInt KSmallBuffer = 1024; |
45 const TInt KSmallBuffer = 1024; |
46 const TInt KMaxChunkReadSize = 65000; |
46 const TInt KMaxChunkReadSize = 65000; |
47 // Class declaration |
47 // Class declaration |
48 |
48 |
49 /* MSRP Message handler |
49 /* |
50 * |
50 * MSRP message handler class. Each MSRP message creates an instance of this class |
|
51 * THis class handles both incoming and outgoing messages |
51 */ |
52 */ |
52 |
|
53 class CMSRPMessageHandler : public CBase, public MMSRPMessageHandler, |
53 class CMSRPMessageHandler : public CBase, public MMSRPMessageHandler, |
54 public MMSRPIncomingMessage, public MMSRPOutgoingMessage, |
54 public MMSRPIncomingMessage, public MMSRPOutgoingMessage, |
55 public MMSRPWriterObserver |
55 public MMSRPWriterObserver |
56 { |
56 { |
57 public: |
57 public: |
58 |
58 |
59 enum TMSRPMessageState |
59 enum TMSRPMessageState |
60 { |
60 { |
61 EIdle, |
61 EIdle, // 0 |
62 EInProgress, |
62 EInProgress, // 1 |
63 EChunkSent, |
63 EChunkSent, // 2 |
64 EMessageSent, |
64 EMessageSent, // 3 |
65 EWaitingForResponse, |
65 ETerminated , // 4 |
66 EWaitingForReport, |
66 EWaitingForResponse, // 5 |
67 EMessageDone |
67 EWaitingForReport, // 6 |
68 }; |
68 EMessageDone // 7 |
69 |
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 |
70 |
202 // MSRP Message |
71 /* Two-Phased constructor |
203 CMSRPMessage* iMessage; |
72 * |
204 |
73 */ |
205 // MSRP response; |
74 static CMSRPMessageHandler* NewL( MMSRPMessageObserver* aMessageObserver, |
206 CMSRPResponse* iResponse; |
75 const TDesC8& aMessage ); |
207 |
76 |
208 TBool iResponseNeeded; |
77 static CMSRPMessageHandler* NewLC( MMSRPMessageObserver* aMessageObserver, |
209 |
78 const TDesC8& aMessage ); |
210 RBuf8 iBuffer; |
79 |
211 |
80 static CMSRPMessageHandler* NewL( TMSRPMessageType aMessageType ); |
212 TPtrC8 iContentPtr; |
81 |
213 |
82 static CMSRPMessageHandler* NewLC( TMSRPMessageType aMessageType ); |
214 TBool iWriteDone; |
83 |
215 |
84 /** |
216 TMSRPMessageType iActiveMsgType; |
85 * Destructor. |
217 |
86 */ |
218 TMSRPMessageState iState; |
87 ~CMSRPMessageHandler(); |
219 |
88 |
220 TMsrpMsgEndStatus iMsgEndStatus; |
89 static TInt LinkOffset(); |
221 |
90 TSglQueLink iLink; |
222 /* For File Use Case */ |
91 |
223 TBool isFile; |
92 /** |
224 RFile iFile; |
93 * Get message id of the current message |
225 RFs iFs; |
94 * @return message id of the message, ownership is transferred |
226 TInt iFileSize; |
95 */ |
227 |
96 HBufC8* MessageIdLC( ); |
228 TBool iInterrupt; |
97 |
229 HBufC8* iFileBuffer; |
98 /** |
230 TBool iFileTransferComplete; |
99 * Get currently received bytes in this message handler |
231 RPointerArray <CMSRPMessageChunkState> iChunkList; |
100 * @param aBytesTransferred number of transferred bytes |
232 TInt iBufPosInFile; //file buffer start pos in file |
101 * @param aTotalBytes total size of data |
233 TInt iEndPosInBuffer; |
102 */ |
234 TInt iStartPosInBuffer; |
103 void CurrentReceiveProgress( TInt& aBytesTransferred, TInt& aTotalBytes ); |
235 TInt iFileBytesSent; |
104 |
236 |
105 /** |
237 TBool iProgress; |
106 * Get currently transferred bytes in this message handler |
238 TInt iNotifiedBytes; |
107 * @param aBytesTransferred number of transferred bytes |
239 TInt iPendingBytes; |
108 * @param aTotalBytes total size of data |
|
109 */ |
|
110 void CurrentSendProgress( TInt& aBytesTransferred, TInt& aTotalBytes ); |
|
111 |
|
112 /** |
|
113 * Sets the message observer entoty |
|
114 * @param aMessageObserver MMSRPMessageObserver |
|
115 */ |
|
116 void SetMessageObserver( MMSRPMessageObserver* aMessageObserver ); |
|
117 |
|
118 /** |
|
119 * Checks whether we are sending or receiving a message with this handler |
|
120 * @return true if we are sending a message |
|
121 */ |
|
122 TBool IsSending( ); |
|
123 |
|
124 /** |
|
125 * returns the temporary file name |
|
126 * @return temporary filename which contains incoming data |
|
127 */ |
|
128 TFileName& TemporaryFileName( ); |
|
129 |
|
130 /** |
|
131 * Set the temporary file name. Used when message is divided to multiple chunks |
|
132 * @param afilename temporary File name |
|
133 */ |
|
134 void SetTemporaryFileName( TFileName aFileName ); |
|
135 |
|
136 /** |
|
137 * Response is no longer needed, it can be deleted |
|
138 */ |
|
139 void ResponseHandled( ); |
|
140 |
|
141 /** |
|
142 * Terminates the receiving of message |
|
143 * @param aConnection connection instance |
|
144 * @param aMessageObserver observer for completed send response |
|
145 */ |
|
146 void TerminateReceiving( MMSRPMessageObserver* aMessageObserver, |
|
147 MMSRPConnection& aConnection ); |
|
148 |
|
149 /** |
|
150 * Terminates the sending of message |
|
151 */ |
|
152 void TerminateSending( ); |
|
153 |
|
154 /** |
|
155 * Returns true if message sending or receiving is terminated |
|
156 * @return true if FS is terminated |
|
157 */ |
|
158 TBool IsTransmissionTerminated( ); |
|
159 |
|
160 /** |
|
161 * Returns true if REPORT response was requested |
|
162 * @return true if REPORT must be sent |
|
163 */ |
|
164 TBool IsReportNeeded( ); |
|
165 |
|
166 public: // From base classes |
|
167 |
|
168 // From MMSRPWriterObserver |
|
169 const TDesC8& GetSendBufferL( TWriteStatus& aStatus, TBool aInterrupt ); |
|
170 |
|
171 MMSRPWriterObserver::TMsgStatus WriteDoneL( TInt aStatus ); |
|
172 |
|
173 // From MMSRPMessageHandler |
|
174 void AddHeaderL( TMsrpHeaderType aHeaderType, TPtrC8& aHeaderValue, |
|
175 TPtrC8& aHeaderTypeAndValue ); |
|
176 |
|
177 void AddContentL( TPtrC8& aContent, TBool aByteRangeFound = EFalse ); |
|
178 |
|
179 void SetTransactionId( TDesC8& aTransactionId ); |
|
180 |
|
181 void SetStatusOfResponseL( TPtrC8& aStatusCode, TPtrC8& aStatusMessage ); |
|
182 |
|
183 void EndOfMessageL( TMsrpMsgEndStatus aStatus ); |
|
184 TBool CheckMessageChunkL( CMSRPMessageHandler& aOtherMessage ); |
|
185 |
|
186 public: // From MMSRPIncomingMessage |
|
187 TMSRPMessageType MessageType( ); |
|
188 CMSRPMessage* GetIncomingMessage( ) const; |
|
189 void SendResponseL( MMSRPMessageObserver* aMessageObserver, |
|
190 MMSRPConnection& aConnection, TUint aResponseCode ); |
|
191 TBool SendReportL( MMSRPMessageObserver* aMessageObserver, |
|
192 MMSRPConnection& aConnection, TUint aStatusCode ); |
|
193 TDesC8& TransactionId( ); |
|
194 CMSRPResponse* GetIncomingResponse( ) const; |
|
195 CMSRPReport* GetIncomingReport( ) const; |
|
196 |
|
197 public: // From MMSRPOutgoingMessage |
|
198 |
|
199 void SendMessageL( MMSRPConnection& aConnection ); |
|
200 TBool IsOwnerOfResponse( MMSRPIncomingMessage& aIncomingMessage ); |
|
201 TUint ConsumeResponseL( MMSRPIncomingMessage& aIncomingMessage ); |
|
202 TBool IsMessageComplete(); |
|
203 TUint GetSendResultL( HBufC8* &aMessageId ); |
|
204 TBool IsFailureHeaderPartial(); |
|
205 |
|
206 private: |
|
207 // Constructor |
|
208 CMSRPMessageHandler( MMSRPMessageObserver* aMessageObserver ); |
|
209 |
|
210 CMSRPMessageHandler( ); |
|
211 |
|
212 void ConstructL( const TDesC8& aMessage ); |
|
213 |
|
214 void ConstructL( TMSRPMessageType aMessageType ); |
|
215 |
|
216 // Member Functions |
|
217 void CreateByteRangeHeaderL(); |
|
218 |
|
219 void CreateTransactionIdL(); |
|
220 |
|
221 void WriteInitialLineToBufferL(); |
|
222 |
|
223 void WriteHeadersToBufferL(); |
|
224 |
|
225 void WriteContentToBuffer(); |
|
226 |
|
227 void WriteFileContentToBufferL(); |
|
228 |
|
229 void WriteEndLineToBuffer(TMsrpMsgEndStatus = EMessageEnd ); |
|
230 |
|
231 TInt ExtractByteRangeParams( TDesC8& aHeaderValue, TInt& aStartPos, |
|
232 TInt& aEndPos, TInt& aTotal ); |
|
233 |
|
234 RStringF GetStatusStringL( TUint aStatusCode ); |
|
235 |
|
236 TUint CheckValidityOfMessage( TMSRPMessageType aMessageType, |
|
237 CMSRPMessageBase* aMessage ); |
|
238 |
|
239 TInt FillFileBufferL(); |
|
240 |
|
241 /* |
|
242 * Opens temporary file. Name of the file is save to iTempFileName |
|
243 * and Rfile is in iTempFile |
|
244 */ |
|
245 void CreateTemporaryFileL( ); |
|
246 |
|
247 /* |
|
248 * Opens temporary file. Name of the file is save to iTempFileName |
|
249 * and Rfile is in iTempFile |
|
250 * @param aFilename filename to open |
|
251 */ |
|
252 void OpenTemporaryFileL( const TDesC& aFilename ); |
|
253 |
|
254 /* |
|
255 * Writes the given buffer to a file |
|
256 * @param aBuffer buffer to be written into the file |
|
257 */ |
|
258 void WriteMessageToFileL( TDesC8& aBuffer ); |
|
259 |
|
260 /* |
|
261 * The message continues and a new segment of the message is being |
|
262 * written to the end of file. |
|
263 * @param aBuffer buffer to be written into the file |
|
264 */ |
|
265 void AppendMessageToFileL( TDesC8& aBuffer ); |
|
266 |
|
267 private: |
|
268 |
|
269 // Server interface |
|
270 MMSRPMessageObserver* iMSRPMessageObserver; |
|
271 |
|
272 // array of sent chunks, transaction id is saved from |
|
273 // sent chunks |
|
274 RPointerArray< HBufC8 > iSentChunks; |
|
275 |
|
276 // MSRP Report |
|
277 CMSRPReport* iReport; |
|
278 |
|
279 // MSRP response; |
|
280 CMSRPResponse* iResponse; |
|
281 |
|
282 // MSRP message |
|
283 CMSRPMessage* iMessage; |
|
284 |
|
285 TBool iResponseNeeded; |
|
286 |
|
287 RBuf8 iBuffer; |
|
288 |
|
289 TPtrC8 iContentPtr; |
|
290 |
|
291 TBool iWriteDone; |
|
292 |
|
293 TMSRPMessageType iActiveMsgType; |
|
294 |
|
295 TMSRPMessageState iState; |
|
296 |
|
297 |
|
298 /* For File Use Case */ |
|
299 RFile iFile; |
|
300 RFs iFs; |
|
301 TInt iFileSize; |
|
302 TBool isSending; |
|
303 |
|
304 TBool iInterrupt; |
|
305 HBufC8* iFileBuffer; |
|
306 TBool iFileTransferComplete; |
|
307 TInt iBufPosInFile; //file buffer start pos in file |
|
308 TInt iEndPosInBuffer; |
|
309 TInt iStartPosInBuffer; |
|
310 TInt iFileBytesSent; |
|
311 TBool iTerminateReceiving; |
|
312 TBool iTerminateSending; |
|
313 |
|
314 TInt iNotifiedBytes; |
|
315 TInt iPendingBytes; |
|
316 |
|
317 /// temporary file name which is used |
|
318 TFileName iTempFileName; |
|
319 |
|
320 /// file for incoming data, owned |
|
321 RFile* iTempFile; |
|
322 |
|
323 // number of bytes currently transmitted or received |
|
324 TInt iCurrentNumberOfBytes; |
|
325 |
|
326 // current message chunk status |
|
327 TMsrpMsgEndStatus iMessageEnding; |
240 }; |
328 }; |
241 |
329 |
242 #endif /* CMSRPMESSAGEHANDLER_H_ */ |
330 #endif /* CMSRPMESSAGEHANDLER_H_ */ |