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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.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
38 * Filestore second UID for SAR stores.
42 const TUid KSARStoreUid={0x1000089d};
45 // forward declarations
51 * Provides generic information useful for the segmentation and reassembly of
52 * SMS messages and reassembly of WAP datagrams.
54 * The constituent parts of both concatenated SMS messages and concatenated 7-bit
55 * WAP datagrams contain a reference, the total number of parts and the index
56 * of the part in the complete message or datagram.
58 * Field for the segmentation store are:
60 * Reference - concatenation reference
61 * Total - total number of PDUs in SMS message
62 * Count - number of PDUs sent
63 * Data1 - total PDUs delivered<<16 and failed
64 * Data2 - log server id
65 * Data3 - validity period
66 * Data4 - type and min and max message reference
67 * Description1 - first 32 characters from buffer
68 * Description2 - original address
69 * Time - time on SMS message
71 * Abstracts an entry which is stored in the CSARStore
73 * The data stored in Data1-4 has a different meaning depending on if it is used
74 * by the Reassembly store or the Segmentation store. The lists below detail
79 * Data1: byte 3: bits7to4; byte 1: identifier1; byte 0: identifier2.
81 * Data2: Log server ID.
83 * Data3: byte 0: PDU type.
85 * Data4: SMS message storage .
89 * Data1: bytes 3, 2: N delivered; byte 1,0 N failed.
91 * Data2: Log server ID.
93 * Data3: SMS submit validity period.
95 * Data4: byte 3,2 message PDU type; byte 1: reference1; byte 0: reference2.
97 * WAP reassembly store:
109 * The data stored in Data1-4 has a different meaning depending on if it is used
110 * by the Reassembly store or the Segmentation store. The tables below detail
115 * -----------------------------------------------------------------
116 * | member | 3 | 2 | 1 | 0 |
117 * -----------------------------------------------------------------
118 * | iData1 | bits7to4 | identifier1 | identifier2 |
119 * | iData2 | Log server ID |
120 * | iData3 | | PDU type |
121 * | iData4 | SMS message storage |
122 * -----------------------------------------------------------------
124 * Segmentation Store:
126 * -----------------------------------------------------------------
127 * | member | 3 | 2 | 1 | 0 |
128 * -----------------------------------------------------------------
129 * | iData1 | N delivered | N failed |
130 * | iData2 | Log server ID |
131 * | iData3 | SMS submit validity period |
132 * | iData4 | message PDU type | reference1 | reference2 |
133 * -----------------------------------------------------------------
135 * WAP Reassembly Store:
137 * -----------------------------------------------------------------
138 * | member | 3 | 2 | 1 | 0 |
139 * -----------------------------------------------------------------
140 * | iData1 | to port |
141 * | iData2 | not used |
142 * | iData3 | not used |
143 * | iData4 | not used |
144 * -----------------------------------------------------------------
157 ESmsSAREntryDescriptionLength=32
160 IMPORT_C TSAREntry();
161 inline TInt Reference() const;
162 inline void SetReference(TInt aReference);
163 inline TInt Total() const;
164 inline void SetTotal(TInt aTotal);
165 inline TInt Count() const;
166 inline void SetCount(TInt aCount);
167 inline TBool IsComplete() const;
170 * Gets the Log server ID field.
172 * @return Log server ID field
174 inline TInt LogServerId() const {return iData2;}
176 * Sets the Log server ID field.
178 * @param aId Log server ID field
180 inline void SetLogServerId(TInt aId) {iData2 = aId;}
182 inline TPtrC Description1() const;
183 inline void SetDescription1(const TDesC& aDescription);
184 inline TPtrC Description2() const;
185 inline void SetDescription2(const TDesC& aDescription);
187 inline TInt Data3() const;
188 inline void SetData3(TInt aData);
190 inline const TTime& Time() const;
191 inline void SetTime(const TTime& aTime);
193 inline TStreamId DataStreamId() const;
194 inline void SetDataStreamId(TStreamId aStreamId);
196 IMPORT_C void InternalizeL(RReadStream& aStream);
197 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
200 inline TBool IsDeleted() const;
201 inline void SetIsDeleted(TBool aIsDeleted);
202 inline TBool IsAdded() const;
203 inline void SetIsAdded(TBool aIsAdded);
208 ESAREntryIsDeleted=0x01, ///< indicates that this entry is deleted
209 ESAREntryIsAdded=0x02 ///< indicated that this entry is added
212 TInt iReference; ///< concatenation reference
213 TInt iTotal; ///< total number of PDUs in this SMS message
214 TInt iCount; ///< number of PDUs sent/received for this SMS message
216 TInt iData1; /// TODO should be TUint32
217 TInt iData2; ///< Log server ID
221 TBuf<ESmsSAREntryDescriptionLength> iDescription1; ///< first 32 characters from buffer
222 TBuf<ESmsSAREntryDescriptionLength> iDescription2; ///< original address
223 TTime iTime; ///< time when message was sent/received
224 TStreamId iDataStreamId;
225 TInt iFlags; // Not externalized
226 friend class CSARStore;
227 friend class CSmsPermanentFileStore;
228 friend class CPreallocatedFile;
233 * Abstraction of an SMS reassembly store entry for incoming SMS messages.
235 * This class should reflect parts of a complete SMS message to be stored in
236 * the reassembly store.
240 class TSmsReassemblyEntry : public TSAREntry
245 KMarkedAsPassedToClientFlag = 0x80000000,
247 KReassemblyEntryClear = 0x00
253 * Gets bits 7 to 4 from Data1 field.
255 * @return Bits 7 to 4 of Data 1
257 inline TInt Bits7to4() const {return (iData1 >> 16) & 0xffff;}
259 * Gets Identifier1 from Data1 field.
261 * @return Identifier1
263 inline TInt Identifier1() const {return (iData1 >> 8) & 0xff;}
265 * Gets Identifier2 from Data1 field.
267 * @return Identifier2
269 inline TInt Identifier2() const {return (iData1 >> 0) & 0xff;}
270 inline void SetBits7to4andIdentifiers(TInt aBits7to4, TInt aId1, TInt aId2)
272 * Sets bits 7 to 4, Identifier1, and Identifier2, in Data1 field.
274 * @param aBits7to4 Bits 7 to 4
275 * @param aId1 Identifier1
276 * @param aId2 Identifier2
278 {iData1 = (TInt)((aBits7to4 << 16) | ((aId1 & 0xff)<< 8) | (aId2 & 0xff)); }
286 inline CSmsPDU::TSmsPDUType PduType() const {return (CSmsPDU::TSmsPDUType)(iData3 & 0xff);} // 8 bits
290 * @param aPduType PDU type
292 inline void SetPduType(CSmsPDU::TSmsPDUType aPduType) {iData3 = (iData3 & ~KPduTypeMask) | (TInt)(aPduType & KPduTypeMask);}
295 * Tests if Passed To Client flag is set.
297 * @return True if Passed To Client flag is set.
299 inline TBool PassedToClient() const {return (iData3 & KMarkedAsPassedToClientFlag) ? ETrue:EFalse;}
301 * Sets Passed To Client flag.
303 * @param aPassed True if Passed To Client flag is set.
305 inline void SetPassedToClient(TBool aPassed) {iData3 = (iData3 & ~KMarkedAsPassedToClientFlag) | (aPassed ? KMarkedAsPassedToClientFlag : KReassemblyEntryClear);}
309 * Gets storage information.
311 * @return Storage information
313 inline CSmsMessage::TMobileSmsStorage Storage() const {return (CSmsMessage::TMobileSmsStorage)(iData4 & 0xff);}
315 * Sets storage information.
317 * @param aStorage Storage information
319 inline void SetStorage(CSmsMessage::TMobileSmsStorage aStorage) {iData4 = (CSmsMessage::TMobileSmsStorage)aStorage;}
324 * Abstraction of an SMS segmentation store entry for outgoing SMS messages.
326 * This class should reflect parts of a complete SMS message to be stored in
327 * the segmentation store.
331 class TSmsSegmentationEntry : public TSAREntry
336 * Gets number of delivered PDUs.
338 * @return Number of delivered PDUs
340 inline TInt Delivered() const {return (iData1 >> 16);}
342 * Gets number of permanently failed PDUs.
344 * @return Number of permanently failed PDUs
346 inline TInt Failed() const {return (iData1 & 0xffff);}
347 inline void SetDeliveredAndFailed(TInt aDelivered, TInt aFailed)
349 * Sets the number of delivered and failed PDUs.
351 * @param aDelivered Number of delivered PDUs
352 * @param aFailed Number of permanently failed PDUs
354 {iData1 = ((aDelivered << 16) | (aFailed & 0xffff));}
358 * Gets the Validity Period.
360 * @return Validity Period
362 inline TInt ValidityPeriod() const {return (iData3); }
364 * Sets the Validity Period.
366 * @param aValPer Validity Period
368 inline void SetValidityPeriod(TInt aValPer) {iData3 = aValPer; }
372 * Tests if a status report is expected.
374 * @return True if a status report is expected
376 inline TBool ExpectStatusReport() const {return (((iData4 >> 24) & 0x01) == 0x01); }
378 * Gets the type of the PDU.
380 * @return Type of the PDU
382 inline CSmsPDU::TSmsPDUType PduType() const {return (CSmsPDU::TSmsPDUType)((iData4 >> 16) & 0xff); }
384 * Gets the message reference (low byte).
386 * @return Message reference (low byte)
388 inline TInt Reference1() const {return ((iData4 >> 8) & 0xff); }
390 * Gets the message reference (high byte).
392 * @return Message reference (high byte)
394 inline TInt Reference2() const {return ((iData4 >> 0) & 0xff); }
395 inline void SetPduTypeAndRefs(TBool aSR, TInt aPduType, TInt aRef1, TInt aRef2)
397 * Sets status report flag, PDU type, and message references.
399 * @param aSR True if a status report is expected
400 * @param aPduType Type of the PDU
401 * @param aRef1 Message reference (low byte)
402 * @param aRef2 Message reference (high byte)
404 {iData4 = (((aSR & 0x01) << 24) | (aPduType << 16) | ((aRef1 & 0xff ) << 8) | (aRef2 & 0xff));}
409 * Abstraction of a WAP reassembly store entry.
410 * This class should reflect a complete WAP message.
414 class TWapReassemblyEntry : public TSAREntry
418 * Gets the destination port number.
420 * @return Destination port number
422 inline TInt ToPort() const {return iData1;}
424 * Sets the destination port number.
426 * @param aToPort Destination port number
428 inline void SetToPort(TInt aToPort){iData1 = aToPort;}
432 * Controls the segmentation and reassembly (SAR) store, used for SMS segmentation
433 * and reassembly, and WAP reassembly.
437 class CSARStore : public CBase
440 IMPORT_C void OpenL(const TDesC& aFullName,const TUid& aThirdUid);
441 IMPORT_C void Close();
442 IMPORT_C void CompactL();
444 IMPORT_C const CArrayFix<TSAREntry>& Entries() const;
445 IMPORT_C void PurgeL(const TTimeIntervalMinutes& aTimeIntervalMinutes,TBool aPurgeIncompleteOnly);
446 IMPORT_C void PurgeL(TInt aKSegmentationLifetimeMultiplier,TBool aPurgeIncompleteOnly);
447 IMPORT_C void DeleteEntryL(TInt aIndex);
449 IMPORT_C void BeginTransactionLC();
450 IMPORT_C void CommitTransactionL(); //Pops this off this cleanup stack and commits iFileStore
453 inline RFs& FileSession() const;
454 inline TBool InTransaction()const;
455 IMPORT_C void DoOpenL();
456 IMPORT_C void PrivatePath(TDes& aPath);
460 IMPORT_C CSARStore(RFs& aFs);
461 IMPORT_C ~CSARStore();
463 IMPORT_C CFileStore& FileStore();
464 IMPORT_C const CFileStore& FileStore() const;
466 IMPORT_C void AddEntryL(const TSAREntry& aEntry);
467 IMPORT_C void ChangeEntryL(TInt aIndex,const TSAREntry& aNewEntry);
469 IMPORT_C TStreamId ExtraStreamId() const;
470 IMPORT_C void SetExtraStreamIdL(const TStreamId& aExtraStreamId);
473 void DoDeleteEntryL(TInt aIndex); // Deletes stream but doesn't call iFileStore->CommitL()
474 void InternalizeEntryArrayL();
475 void ExternalizeEntryArrayL();
476 void DoCommitAndCompactL();
477 void RemoveDeletedEntries();
478 void ReinstateDeletedEntries();
483 KNumStoreCommitsBeforeCompaction=16
487 RFs& iFs; ///< File server handle.
490 CFileStore* iFileStore; ///< pointer to the file store
491 CArrayFixFlat<TSAREntry> iEntryArray; ///< array of SAR entries
492 TStreamId iExtraStreamId; ///< used for any other data that needs persisting
493 TInt iCommitCount; ///< counts number of Commit's - used for CompactL
494 TPtrC iFullName; ///< holds the name of the File Store
496 TBool iInTransaction; ///< For debugging purposes to ensure only one transaction at a time
500 * Closes all SAR stores if a backup event starts.
502 * This is internal and not intended for use.
506 class CGsmuBackupObserver : public CBase, MBackupOperationObserver
509 IMPORT_C static CGsmuBackupObserver* NewL();
510 IMPORT_C ~CGsmuBackupObserver();
511 IMPORT_C void AddSARStoreL(CSARStore& aSARStore);
512 IMPORT_C void RemoveSARStore(const CSARStore& aSARStore);
515 CGsmuBackupObserver();
517 void HandleBackupOperationEventL(const TBackupOperationAttributes& aBackupOperationAttributes);
519 CBaBackupSessionWrapper* iBackup;
520 RPointerArray<CSARStore> iSARStores;
523 #include "gsmustor.inl"
525 #endif // !defined GSMUSTOR_H__