|
1 /* |
|
2 * Copyright (c) 2002-2005 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 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Header declaration |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 #ifndef SEN_CHUNK_H |
|
29 #define SEN_CHUNK_H |
|
30 |
|
31 // INCLUDES |
|
32 #include <e32base.h> |
|
33 #include <flogger.h> |
|
34 #include <f32file.h> |
|
35 |
|
36 #include <MSenMessage.h> |
|
37 #include <MSenProperties.h> |
|
38 |
|
39 // Min size for new RChunk allocations: |
|
40 const TInt KSenMinRChunkSize = 0x2750; // 10064 bytes |
|
41 // Max size for new RChunk allocations: |
|
42 const TInt KSenMaxRChunkSize = 0x400000; // 4194304 bytes |
|
43 |
|
44 |
|
45 // FORWARD DECLARE |
|
46 class CSenChunk; |
|
47 |
|
48 // CLASS DECLARATION |
|
49 class TChunkHeader |
|
50 /** |
|
51 * This class is set in the beginning of the RChunk. Class is used |
|
52 * to store header information. |
|
53 * |
|
54 * Note: All data in here must be 4-byte aligned (using dummy values |
|
55 * if needed) |
|
56 */ |
|
57 { |
|
58 public: |
|
59 /** |
|
60 * Getter for message class enumeration |
|
61 * @return message type enumeration |
|
62 * @see MSenMessage.h |
|
63 */ |
|
64 inline MSenMessage::TClass MessageType() const |
|
65 { |
|
66 return (MSenMessage::TClass)iMessageType; |
|
67 } |
|
68 |
|
69 /** |
|
70 * Setter for message class enumeration |
|
71 * @param aValue defines the message class type enumeration. |
|
72 * @see MSenMessage.h |
|
73 */ |
|
74 inline void SetMessageType(MSenMessage::TClass aType) |
|
75 { |
|
76 iMessageType = (TInt)aType; |
|
77 } |
|
78 |
|
79 /** |
|
80 * Getter for message direction enumeration |
|
81 * @return message type enumeration |
|
82 * @see MSenMessage.h |
|
83 */ |
|
84 inline MSenMessage::TDirection MessageDirection() const |
|
85 { |
|
86 return (MSenMessage::TDirection)iMessageDirection; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Setter for message direction enumeration |
|
91 * @param aValue defines the message class type enumeration. |
|
92 * @see MSenMessage.h |
|
93 */ |
|
94 inline void SetMessageDirection(MSenMessage::TDirection aDirection) |
|
95 { |
|
96 iMessageDirection = (TInt)aDirection; |
|
97 } |
|
98 |
|
99 /** |
|
100 * Getter to determine should init be done before sending the message. |
|
101 * @return ETrue if yes, otherwise EFalse. |
|
102 */ |
|
103 inline TBool DoInitBeforeSending() const |
|
104 { |
|
105 if ( iDoInitBeforeSending ) |
|
106 { |
|
107 return ETrue; |
|
108 } |
|
109 else |
|
110 { |
|
111 return EFalse; |
|
112 } |
|
113 } |
|
114 |
|
115 /** |
|
116 * Sets the flag indicating that init should be done |
|
117 * before sending the message |
|
118 * @param aValue if ETrue, init will be done before sending |
|
119 * if EFalse, init will not be done before sending |
|
120 */ |
|
121 inline void SetDoInitBeforeSending(TBool aValue) |
|
122 { |
|
123 if ( aValue ) |
|
124 { |
|
125 iDoInitBeforeSending = 1; |
|
126 } |
|
127 else |
|
128 { |
|
129 iDoInitBeforeSending = 0; |
|
130 } |
|
131 // iDoInitBeforeSending = aValue; |
|
132 } |
|
133 |
|
134 /** |
|
135 * Getter for (transport) properties type. |
|
136 * @return transport properties type |
|
137 * enumeration. Note: |
|
138 * ENotInUse means that transport |
|
139 * properties are not in use. |
|
140 * @see MSenProperties |
|
141 */ |
|
142 inline MSenProperties::TSenPropertiesClassType PropertiesType() const |
|
143 { |
|
144 return (MSenProperties::TSenPropertiesClassType)iPropertiesType; |
|
145 } |
|
146 |
|
147 /** |
|
148 * Sets the (transport) properties type enumeration |
|
149 * @param aType where ENotInUse indicates that |
|
150 * there are no associated properties, and all |
|
151 * the others point to a concrete properties |
|
152 * class. |
|
153 * @see MSenProperties |
|
154 */ |
|
155 inline void SetPropertiesType(MSenProperties::TSenPropertiesClassType aType) |
|
156 { |
|
157 iPropertiesType = (TInt)aType; |
|
158 } |
|
159 |
|
160 /** |
|
161 * Getter for descriptor count. |
|
162 * @return the descriptor count |
|
163 */ |
|
164 inline TInt DescriptorCount() const |
|
165 { |
|
166 return iDescriptorCount; |
|
167 } |
|
168 |
|
169 /** |
|
170 * Setter for descriptor count. |
|
171 * @param aCount is the descriptor count |
|
172 */ |
|
173 inline void SetDescriptorCount(TInt aCount) |
|
174 { |
|
175 iDescriptorCount = aCount; |
|
176 } |
|
177 |
|
178 /** |
|
179 * Getter for transaction id. |
|
180 * @return the transaction id |
|
181 */ |
|
182 inline TInt TransactionId() const |
|
183 { |
|
184 return iTransactionId; |
|
185 } |
|
186 |
|
187 /** |
|
188 * Setter for transaction id. |
|
189 * @param aID is the transaction id |
|
190 */ |
|
191 inline void SetTransactionId(TInt aId) |
|
192 { |
|
193 iTransactionId = aId; |
|
194 } |
|
195 |
|
196 /** |
|
197 * Getter for ctx id. |
|
198 * @return the ctx id |
|
199 */ |
|
200 inline TInt ContextId() const |
|
201 { |
|
202 return iContextId; |
|
203 } |
|
204 |
|
205 /** |
|
206 * Setter for ctx id. |
|
207 * @param aID is the ctx id |
|
208 */ |
|
209 inline void SetContextId(TInt aId) |
|
210 { |
|
211 iContextId = aId; |
|
212 } |
|
213 |
|
214 /** |
|
215 * Getter for pending transaction id. |
|
216 * @return the pending transaction id |
|
217 */ |
|
218 inline TInt PendingTransactionId() const |
|
219 { |
|
220 return iPendingTransactionId; |
|
221 } |
|
222 |
|
223 /** |
|
224 * Setter for pending transaction id. |
|
225 * @param aCount is the pending transaction id |
|
226 */ |
|
227 inline void SetPendingTransactionId(TInt aId) |
|
228 { |
|
229 iPendingTransactionId = aId; |
|
230 } |
|
231 |
|
232 private: |
|
233 /*MSenMessage::TClass*/ TInt iMessageType; |
|
234 /*MSenMessage::TDirection*/ TInt iMessageDirection; |
|
235 /*TBool*/ TInt iDoInitBeforeSending; |
|
236 /*MSenProperties::TSenPropertiesClassType*/ TInt iPropertiesType; |
|
237 TInt iDescriptorCount; |
|
238 TInt iTransactionId; |
|
239 TInt iPendingTransactionId; |
|
240 TInt iContextId; |
|
241 }; |
|
242 |
|
243 /** |
|
244 * Offset to the beginning of header |
|
245 */ |
|
246 const TInt KHeaderOffset = 0; |
|
247 |
|
248 /** |
|
249 * Offset to the beginning of data |
|
250 */ |
|
251 const TInt KDataOffset = KHeaderOffset + sizeof(TChunkHeader); |
|
252 |
|
253 // CLASS DECLARATION |
|
254 class CSenChunk : public CBase |
|
255 { |
|
256 /** |
|
257 * Helper class for storing RChunks |
|
258 */ |
|
259 public: |
|
260 /** |
|
261 * Two-phased constructor. |
|
262 * @since Series60 4.0 |
|
263 * @param aChunkName is the chunk name. |
|
264 * @return a new CSenChunk |
|
265 */ |
|
266 IMPORT_C static CSenChunk* NewL(const TDesC& aChunkName); |
|
267 |
|
268 /** |
|
269 * Two-phased constructor. |
|
270 * @since Series60 4.0 |
|
271 * @param aChunkName is the chunk name. |
|
272 * @return a new CSenChunk |
|
273 */ |
|
274 IMPORT_C static CSenChunk* NewLC(const TDesC& aChunkName); |
|
275 |
|
276 /** |
|
277 * Destructor. |
|
278 */ |
|
279 IMPORT_C ~CSenChunk(); |
|
280 |
|
281 /** |
|
282 * @since Series60 4.0 |
|
283 * @return a reference to internal chunk |
|
284 */ |
|
285 IMPORT_C RChunk& Chunk(); |
|
286 |
|
287 /** |
|
288 * @since Series60 4.0 |
|
289 * @return a pointer to ChunkName |
|
290 */ |
|
291 IMPORT_C TPtrC ChunkName() const; |
|
292 |
|
293 /** |
|
294 * Creates global protected RChunk inside CSenChunk |
|
295 * @since Series60 4.0 |
|
296 * @return KErrNone or some system-wide Symbian error codes. |
|
297 */ |
|
298 IMPORT_C TInt CreateChunk(); |
|
299 |
|
300 /** |
|
301 * Opens global protected RChunk inside CSenChunk |
|
302 * @since Series60 4.0 |
|
303 * @return KErrNone or some system-wide Symbian error codes. |
|
304 */ |
|
305 IMPORT_C TInt OpenChunk(); |
|
306 |
|
307 /** |
|
308 * Closes RChunk inside CSenChunk |
|
309 * @since Series60 4.0 |
|
310 */ |
|
311 IMPORT_C void CloseChunk(); |
|
312 |
|
313 /** |
|
314 * Changes the number of bytes committed to the internal chunk. |
|
315 * This value is always rounded up to the next nearest processor |
|
316 * page boundary. |
|
317 * This value is rounded up to KSenMinRChunkSize if value is |
|
318 * less than KSenMinRChunkSize. |
|
319 * @since Series60 4.0 |
|
320 * @param aNewSize The number of bytes to be committed to this chunk. |
|
321 * @return KErrNone or some system-wide Symbian error codes. |
|
322 */ |
|
323 IMPORT_C TInt AdjustChunk(TInt aNewSize); |
|
324 |
|
325 /** |
|
326 * @since Series60 4.0 |
|
327 * @return a header of the internal chunk |
|
328 */ |
|
329 IMPORT_C TChunkHeader& ChunkHeader(); |
|
330 |
|
331 /** |
|
332 * Stores given descriptor into internal chunk. |
|
333 * Internal chunk is tried to adjust so that given descriptor |
|
334 * fits into chunk. |
|
335 * @since Series60 4.0 |
|
336 * @param aDesc is the descriptor to store |
|
337 * @return KErrNone or some system-wide Symbian error codes. |
|
338 */ |
|
339 IMPORT_C TInt DescToChunk(const TDesC8& aDesc); |
|
340 |
|
341 /** |
|
342 * Stores given descriptor into internal chunk. |
|
343 * Internal chunk is tried to adjust so that given descriptor |
|
344 * fits into chunk. |
|
345 * @since Series60 4.0 |
|
346 * @param aDesc is the descriptor to store |
|
347 * @return KErrNone or some system-wide Symbian error codes. |
|
348 */ |
|
349 IMPORT_C TInt DescToChunk(const TDesC8& aDesc, TInt aIndex); |
|
350 |
|
351 /** |
|
352 * Changes the number of bytes committed to the internal chunk |
|
353 * and places a pointer to chunk to apAllocated. |
|
354 * Size is always rounded up to the next nearest processor |
|
355 * page boundary. |
|
356 * Size is rounded up to KSenMinRChunkSize if given size is |
|
357 * less than KSenMinRChunkSize. |
|
358 * @since Series60 4.0 |
|
359 * @param aSize The number of bytes to be committed to this chunk. |
|
360 * @param apAllocated |
|
361 * @return KErrNone or some system-wide Symbian error codes. |
|
362 */ |
|
363 IMPORT_C TInt AllocDescToChunk(TInt aSize, TPtr8*& apAllocated); |
|
364 |
|
365 /** |
|
366 * Stores given descriptors into internal chunk. |
|
367 * Internal chunk is tried to adjust so that both of the |
|
368 * given descriptors fit into chunk. |
|
369 * @since Series60 4.0 |
|
370 * @param aDesc is the first descriptor to store |
|
371 * @param aDesc2 is the second descriptor to store |
|
372 * @return KErrNone or some system-wide Symbian error codes. |
|
373 */ |
|
374 IMPORT_C TInt DescsToChunk(const TDesC8& aDesc, |
|
375 const TDesC8& aDesc2); |
|
376 |
|
377 /** |
|
378 * Gets stored descriptor in given index from internal chunk. |
|
379 * @since Series60 4.0 |
|
380 * @param aDesc will hold the pointer to descriptor in internal chunk |
|
381 * @param aIndex is the index of descriptor to get |
|
382 * @return KErrNone or some system-wide Symbian error codes. |
|
383 */ |
|
384 IMPORT_C TInt DescFromChunk(TPtrC8& aDesc, TInt aIndex = 0); |
|
385 |
|
386 /** |
|
387 * Gets stored descriptors from internal chunk. |
|
388 * @since Series60 4.0 |
|
389 * @param aDesc1 will hold the pointer to the first descriptor in internal chunk |
|
390 * @param aDesc2 will hold the pointer to the second descriptor in internal chunk |
|
391 * @return KErrNone or some system-wide Symbian error codes. |
|
392 */ |
|
393 IMPORT_C TInt DescsFromChunk(TPtrC8& aDesc1, TPtrC8& aDesc2); |
|
394 |
|
395 /** |
|
396 * Sets an internal chunk into TIpcArgs into given po. |
|
397 * @since Series60 4.0 |
|
398 * @param aArgs The IPC message arguments |
|
399 * @param aIndex An index value that identifies the slot in the array |
|
400 * of arguments into which the chunk is to be |
|
401 * placed. This must be a value in the range 0 to 3. |
|
402 */ |
|
403 IMPORT_C void ChunkToArgs(TIpcArgs& aArgs, TInt aIndex); |
|
404 |
|
405 /** |
|
406 * Opens internal chunk using a handle number sent by a client to a server. |
|
407 * This function is called by the server. |
|
408 * @since Series60 4.0 |
|
409 * @param aMessage Represents the contents of the client message |
|
410 * @param aIndex An index specifying which of the four message arguments |
|
411 * contains the handle number. |
|
412 * @return KErrNone or some system-wide Symbian error codes. |
|
413 */ |
|
414 IMPORT_C TInt OpenChunkFromRMsgL(const RMessage2& aMessage, TInt aIndex); |
|
415 |
|
416 /** |
|
417 * Opens internal chunk using a handle number returned by a server to a client. |
|
418 * This function is called by the client. |
|
419 * @since Series60 4.0 |
|
420 * @param aHandleOrError A handle-number, if zero or positive; |
|
421 * an error value, if negative. |
|
422 * @return KErrNone, if aHandle is a handle-number; |
|
423 * the value of aHandleOrError, otherwise.. |
|
424 */ |
|
425 IMPORT_C TInt OpenChunkFromHandleNumberL(TInt aHandleOrError); |
|
426 |
|
427 /** |
|
428 * Tests whether two CSenChunks are equal. |
|
429 * @since Series60 4.0 |
|
430 * @param aChunk The SenChunk to be compared with this SenChunk |
|
431 * @return True if the two SenChunks are equal. False if not. |
|
432 */ |
|
433 IMPORT_C TBool operator==(const CSenChunk& aChunk); |
|
434 |
|
435 /** |
|
436 * Sets the file logger used for debug messages. |
|
437 * @since Series60 4.0 |
|
438 * @param aLog is the file logger |
|
439 */ |
|
440 IMPORT_C void SetLogger(RFileLogger* aLog); |
|
441 |
|
442 /** |
|
443 * Gets the Rfile Pointer to CHUNK to send content by HTTP:POST |
|
444 * @since Series60 |
|
445 */ |
|
446 IMPORT_C RFile& RequestFileHandle(); |
|
447 |
|
448 /** |
|
449 * Sets the Rfile Pointer to CHUNK to send content by HTTP:POST |
|
450 * @since Series60 |
|
451 */ |
|
452 IMPORT_C void RequestFileHandle(RFile& aFile); |
|
453 |
|
454 protected: // Helper functions |
|
455 /** |
|
456 * @since Series60 4.0 |
|
457 * @return Pointer to the file logger |
|
458 */ |
|
459 IMPORT_C RFileLogger* Log() const; |
|
460 |
|
461 /** |
|
462 * Constructor. |
|
463 */ |
|
464 IMPORT_C CSenChunk(); |
|
465 |
|
466 private: |
|
467 /** |
|
468 * This private helper ensures that cast address is dividable by four (MANDATORY in ARMv5 environment, for example) |
|
469 */ |
|
470 TUint8* RoundToNextDividableByFourAddress(TUint8* aValue); |
|
471 |
|
472 |
|
473 /** |
|
474 * Basic ConstructL function |
|
475 * @since Series60 4.0 |
|
476 * @param aChunkName is the chunk name. |
|
477 */ |
|
478 void ConstructL(const TDesC& aChunkName); |
|
479 |
|
480 |
|
481 protected: // Data |
|
482 HBufC* ipChunkName; |
|
483 |
|
484 private: // Data |
|
485 RChunk iChunk; |
|
486 RFileLogger* iLog; |
|
487 RFile iFile; |
|
488 }; |
|
489 |
|
490 #endif //R_SEN_SERVICE_CONNECTION_H |