1 // Copyright (c) 1999-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Declares the classes TSAREntry and CSARStore
16 // PDU - Packet Data Unit
17 // SAR - Segmentation and Reassembly Store
36 * Filestore second UID for SAR stores.
40 const TUid KSARStoreUid={0x1000089d};
43 // forward declarations
49 * Provides generic information useful for the segmentation and reassembly of
50 * SMS messages and reassembly of WAP datagrams.
52 * The constituent parts of both concatenated SMS messages and concatenated 7-bit
53 * WAP datagrams contain a reference, the total number of parts and the index
54 * of the part in the complete message or datagram.
56 * Field for the segmentation store are:
58 * Reference - concatenation reference
59 * Total - total number of PDUs in SMS message
60 * Count - number of PDUs sent
61 * Data1 - total PDUs delivered<<16 and failed
62 * Data2 - log server id
63 * Data3 - validity period
64 * Data4 - type and min and max message reference
65 * Description1 - first 32 characters from buffer
66 * Description2 - original address
67 * Time - time on SMS message
69 * Abstracts an entry which is stored in the CSARStore
71 * The data stored in Data1-4 has a different meaning depending on if it is used
72 * by the Reassembly store or the Segmentation store. The lists below detail
77 * Data1: byte 3: bits7to4; byte 1: identifier1; byte 0: identifier2.
79 * Data2: Log server ID.
81 * Data3: byte 0: PDU type.
83 * Data4: SMS message storage .
87 * Data1: bytes 3, 2: N delivered; byte 1,0 N failed.
89 * Data2: Log server ID.
91 * Data3: SMS submit validity period.
93 * Data4: byte 3,2 message PDU type; byte 1: reference1; byte 0: reference2.
95 * WAP reassembly store:
107 * The data stored in Data1-4 has a different meaning depending on if it is used
108 * by the Reassembly store or the Segmentation store. The tables below detail
113 * -----------------------------------------------------------------
114 * | member | 3 | 2 | 1 | 0 |
115 * -----------------------------------------------------------------
116 * | iData1 | bits7to4 | identifier1 | identifier2 |
117 * | iData2 | Log server ID |
118 * | iData3 | | PDU type |
119 * | iData4 | SMS message storage |
120 * -----------------------------------------------------------------
122 * Segmentation Store:
124 * -----------------------------------------------------------------
125 * | member | 3 | 2 | 1 | 0 |
126 * -----------------------------------------------------------------
127 * | iData1 | N delivered | N failed |
128 * | iData2 | Log server ID |
129 * | iData3 | SMS submit validity period |
130 * | iData4 | message PDU type | reference1 | reference2 |
131 * -----------------------------------------------------------------
133 * WAP Reassembly Store:
135 * -----------------------------------------------------------------
136 * | member | 3 | 2 | 1 | 0 |
137 * -----------------------------------------------------------------
138 * | iData1 | to port |
139 * | iData2 | not used |
140 * | iData3 | not used |
141 * | iData4 | not used |
142 * -----------------------------------------------------------------
155 ESmsSAREntryDescriptionLength=32
158 IMPORT_C TSAREntry();
159 inline TInt Reference() const;
160 inline void SetReference(TInt aReference);
161 inline TInt Total() const;
162 inline void SetTotal(TInt aTotal);
163 inline TInt Count() const;
164 inline void SetCount(TInt aCount);
165 inline TBool IsComplete() const;
168 * Gets the Log server ID field.
170 * @return Log server ID field
172 inline TInt LogServerId() const {return iData2;}
174 * Sets the Log server ID field.
176 * @param aId Log server ID field
178 inline void SetLogServerId(TInt aId) {iData2 = aId;}
180 inline TPtrC Description1() const;
181 inline void SetDescription1(const TDesC& aDescription);
182 inline TPtrC Description2() const;
183 inline void SetDescription2(const TDesC& aDescription);
185 inline TInt Data3() const;
186 inline void SetData3(TInt aData);
188 inline const TTime& Time() const;
189 inline void SetTime(const TTime& aTime);
191 inline TStreamId DataStreamId() const;
192 inline void SetDataStreamId(TStreamId aStreamId);
194 IMPORT_C void InternalizeL(RReadStream& aStream);
195 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
198 inline TBool IsDeleted() const;
199 inline void SetIsDeleted(TBool aIsDeleted);
200 inline TBool IsAdded() const;
201 inline void SetIsAdded(TBool aIsAdded);
206 ESAREntryIsDeleted=0x01, //< indicates that this entry is deleted
207 ESAREntryIsAdded=0x02 //< indicated that this entry is added
210 TInt iReference; //< concatenation reference
211 TInt iTotal; //< total number of PDUs in this SMS message
212 TInt iCount; //< number of PDUs sent/received for this SMS message
214 TInt iData1; // TODO should be TUint32
215 TInt iData2; //< Log server ID
219 TBuf<ESmsSAREntryDescriptionLength> iDescription1; //< first 32 characters from buffer
220 TBuf<ESmsSAREntryDescriptionLength> iDescription2; //< original address
221 TTime iTime; //< time when message was sent/received
222 TStreamId iDataStreamId;
223 TInt iFlags; // Not externalized
224 friend class CSARStore;
225 friend class CSmsPermanentFileStore;
226 friend class CPreallocatedFile;
231 * Abstraction of an SMS reassembly store entry for incoming SMS messages.
233 * This class should reflect parts of a complete SMS message to be stored in
234 * the reassembly store.
238 class TSmsReassemblyEntry : public TSAREntry
243 KMarkedAsPassedToClientFlag = 0x80000000,
245 KReassemblyEntryClear = 0x00
251 * Gets bits 7 to 4 from Data1 field.
253 * @return Bits 7 to 4 of Data 1
255 inline TInt Bits7to4() const {return (iData1 >> 16) & 0xffff;}
257 * Gets Identifier1 from Data1 field.
259 * @return Identifier1
261 inline TInt Identifier1() const {return (iData1 >> 8) & 0xff;}
263 * Gets Identifier2 from Data1 field.
265 * @return Identifier2
267 inline TInt Identifier2() const {return (iData1 >> 0) & 0xff;}
268 inline void SetBits7to4andIdentifiers(TInt aBits7to4, TInt aId1, TInt aId2)
270 * Sets bits 7 to 4, Identifier1, and Identifier2, in Data1 field.
272 * @param aBits7to4 Bits 7 to 4
273 * @param aId1 Identifier1
274 * @param aId2 Identifier2
276 {iData1 = (TInt)((aBits7to4 << 16) | ((aId1 & 0xff)<< 8) | (aId2 & 0xff)); }
284 inline CSmsPDU::TSmsPDUType PduType() const {return (CSmsPDU::TSmsPDUType)(iData3 & 0xff);} // 8 bits
288 * @param aPduType PDU type
290 inline void SetPduType(CSmsPDU::TSmsPDUType aPduType) {iData3 = (iData3 & ~KPduTypeMask) | (TInt)(aPduType & KPduTypeMask);}
293 * Tests if Passed To Client flag is set.
295 * @return True if Passed To Client flag is set.
297 inline TBool PassedToClient() const {return (iData3 & KMarkedAsPassedToClientFlag) ? ETrue:EFalse;}
299 * Sets Passed To Client flag.
301 * @param aPassed True if Passed To Client flag is set.
303 inline void SetPassedToClient(TBool aPassed) {iData3 = (iData3 & ~KMarkedAsPassedToClientFlag) | (aPassed ? KMarkedAsPassedToClientFlag : KReassemblyEntryClear);}
307 * Gets storage information.
309 * @return Storage information
311 inline CSmsMessage::TMobileSmsStorage Storage() const {return (CSmsMessage::TMobileSmsStorage)(iData4 & 0xff);}
313 * Sets storage information.
315 * @param aStorage Storage information
317 inline void SetStorage(CSmsMessage::TMobileSmsStorage aStorage) {iData4 = (CSmsMessage::TMobileSmsStorage)aStorage;}
322 * Abstraction of an SMS segmentation store entry for outgoing SMS messages.
324 * This class should reflect parts of a complete SMS message to be stored in
325 * the segmentation store.
329 class TSmsSegmentationEntry : public TSAREntry
334 * Gets number of delivered PDUs.
336 * @return Number of delivered PDUs
338 inline TInt Delivered() const {return (iData1 >> 16);}
340 * Gets number of permanently failed PDUs.
342 * @return Number of permanently failed PDUs
344 inline TInt Failed() const {return (iData1 & 0xffff);}
345 inline void SetDeliveredAndFailed(TInt aDelivered, TInt aFailed)
347 * Sets the number of delivered and failed PDUs.
349 * @param aDelivered Number of delivered PDUs
350 * @param aFailed Number of permanently failed PDUs
352 {iData1 = ((aDelivered << 16) | (aFailed & 0xffff));}
356 * Gets the Validity Period.
358 * @return Validity Period
360 inline TInt ValidityPeriod() const {return (iData3); }
362 * Sets the Validity Period.
364 * @param aValPer Validity Period
366 inline void SetValidityPeriod(TInt aValPer) {iData3 = aValPer; }
370 * Tests if a status report is expected.
372 * @return True if a status report is expected
374 inline TBool ExpectStatusReport() const {return (((iData4 >> 24) & 0x01) == 0x01); }
376 * Gets the type of the PDU.
378 * @return Type of the PDU
380 inline CSmsPDU::TSmsPDUType PduType() const {return (CSmsPDU::TSmsPDUType)((iData4 >> 16) & 0xff); }
382 * Gets the message reference (low byte).
384 * @return Message reference (low byte)
386 inline TInt Reference1() const {return ((iData4 >> 8) & 0xff); }
388 * Gets the message reference (high byte).
390 * @return Message reference (high byte)
392 inline TInt Reference2() const {return ((iData4 >> 0) & 0xff); }
393 inline void SetPduTypeAndRefs(TBool aSR, TInt aPduType, TInt aRef1, TInt aRef2)
395 * Sets status report flag, PDU type, and message references.
397 * @param aSR True if a status report is expected
398 * @param aPduType Type of the PDU
399 * @param aRef1 Message reference (low byte)
400 * @param aRef2 Message reference (high byte)
402 {iData4 = (((aSR & 0x01) << 24) | (aPduType << 16) | ((aRef1 & 0xff ) << 8) | (aRef2 & 0xff));}
407 * Abstraction of a WAP reassembly store entry.
408 * This class should reflect a complete WAP message.
412 class TWapReassemblyEntry : public TSAREntry
416 * Gets the destination port number.
418 * @return Destination port number
420 inline TInt ToPort() const {return iData1;}
422 * Sets the destination port number.
424 * @param aToPort Destination port number
426 inline void SetToPort(TInt aToPort){iData1 = aToPort;}
430 * Controls the segmentation and reassembly (SAR) store, used for SMS segmentation
431 * and reassembly, and WAP reassembly.
435 class CSARStore : public CBase
438 IMPORT_C void OpenL(const TDesC& aFullName,const TUid& aThirdUid);
439 IMPORT_C void Close();
440 IMPORT_C void CompactL();
442 IMPORT_C const CArrayFix<TSAREntry>& Entries() const;
443 IMPORT_C void PurgeL(const TTimeIntervalMinutes& aTimeIntervalMinutes,TBool aPurgeIncompleteOnly);
444 IMPORT_C void PurgeL(TInt aKSegmentationLifetimeMultiplier,TBool aPurgeIncompleteOnly);
445 IMPORT_C void DeleteEntryL(TInt aIndex);
447 IMPORT_C void BeginTransactionLC();
448 IMPORT_C void CommitTransactionL(); //Pops this off this cleanup stack and commits iFileStore
451 inline RFs& FileSession() const;
452 inline TBool InTransaction()const;
453 IMPORT_C void DoOpenL();
454 IMPORT_C void PrivatePath(TDes& aPath);
458 IMPORT_C CSARStore(RFs& aFs);
459 IMPORT_C ~CSARStore();
461 IMPORT_C CFileStore& FileStore();
462 IMPORT_C const CFileStore& FileStore() const;
464 IMPORT_C void AddEntryL(const TSAREntry& aEntry);
465 IMPORT_C void ChangeEntryL(TInt aIndex,const TSAREntry& aNewEntry);
467 IMPORT_C TStreamId ExtraStreamId() const;
468 IMPORT_C void SetExtraStreamIdL(const TStreamId& aExtraStreamId);
471 void DoDeleteEntryL(TInt aIndex); // Deletes stream but doesn't call iFileStore->CommitL()
472 void InternalizeEntryArrayL();
473 void ExternalizeEntryArrayL();
474 void DoCommitAndCompactL();
475 void RemoveDeletedEntries();
476 void ReinstateDeletedEntries();
481 KNumStoreCommitsBeforeCompaction=16
485 RFs& iFs; //< File server handle.
486 /** Maximum number of SMS messages that can be stored in segmentation store.*/
487 TInt iMaxmumNumberOfMessagesInSegmentationStore;
491 CFileStore* iFileStore; //< pointer to the file store
492 CArrayFixSeg<TSAREntry> iEntryArray; //< array of SAR entries
493 TStreamId iExtraStreamId; //< used for any other data that needs persisting
494 TInt iCommitCount; //< counts number of Commit's - used for CompactL
495 TPtrC iFullName; //< holds the name of the File Store
497 TBool iInTransaction; //< For debugging purposes to ensure only one transaction at a time
501 * Closes all SAR stores if a backup event starts.
503 * This is internal and not intended for use.
507 class CGsmuBackupObserver : public CBase, MBackupOperationObserver
510 IMPORT_C static CGsmuBackupObserver* NewL();
511 IMPORT_C ~CGsmuBackupObserver();
512 IMPORT_C void AddSARStoreL(CSARStore& aSARStore);
513 IMPORT_C void RemoveSARStore(const CSARStore& aSARStore);
516 CGsmuBackupObserver();
518 void HandleBackupOperationEventL(const TBackupOperationAttributes& aBackupOperationAttributes);
520 CBaBackupSessionWrapper* iBackup;
521 RPointerArray<CSARStore> iSARStores;
524 #include "gsmustor.inl"
526 #endif // !defined GSMUSTOR_H__