epoc32/include/gsmustor.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Declares the classes TSAREntry and CSARStore
    15 // Abbreviations:
    16 // PDU - Packet Data Unit
    17 // SAR - Segmentation and Reassembly Store
    18 // SR  - Status Report
    19 // 
    20 //
    21 
    22 
    23 
    24 /**
    25  @file
    26 */
    27 
    28 #ifndef GSMUSTOR_H__
    29 #define GSMUSTOR_H__
    30 
    31 #include <e32base.h>
    32 #include <s32std.h>
    33 #include <s32file.h>
    34 #include <gsmumsg.h>
    35 #include <babackup.h>
    36 
    37 /**
    38  *  Filestore second UID for SAR stores.
    39  *  @publishedAll
    40  *  @released
    41  */
    42 const TUid KSARStoreUid={0x1000089d};
    43 
    44 //
    45 // forward declarations
    46 //
    47 class RReadStream;
    48 class RWriteStream;
    49 
    50 /**
    51  *  Provides generic information useful for the segmentation and reassembly of
    52  *  SMS messages and reassembly of WAP datagrams.
    53  *  
    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.
    57  *  
    58  *  Field for the segmentation store are:
    59  *  
    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
    70  *  
    71  *  Abstracts an entry which is stored in the CSARStore
    72  *  
    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
    75  *  the uses:
    76  *  
    77  *  Reassembly store:
    78  *  
    79  *  Data1: byte 3: bits7to4; byte 1: identifier1; byte 0: identifier2.
    80  *  
    81  *  Data2: Log server ID.
    82  *  
    83  *  Data3: byte 0: PDU type.
    84  *  
    85  *  Data4: SMS message storage .
    86  *  
    87  *  Segmentation store:
    88  *  
    89  *  Data1: bytes 3, 2: N delivered; byte 1,0 N failed.
    90  *  
    91  *  Data2: Log server ID.
    92  *  
    93  *  Data3: SMS submit validity period.
    94  *  
    95  *  Data4: byte 3,2 message PDU type; byte 1: reference1; byte 0: reference2.
    96  *  
    97  *  WAP reassembly store:
    98  *  
    99  *  Data1: to port.
   100  *  
   101  *  Data2: not used .
   102  *  
   103  *  Data3: not used.
   104  *  
   105  *  Data4: not used.
   106  *  
   107  *  <pre>
   108  *  
   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
   111  *  the uses:
   112  *  
   113  *  Reassembly Store:
   114  *  
   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  *  -----------------------------------------------------------------
   123  *  
   124  *  Segmentation Store:
   125  *  
   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  *  -----------------------------------------------------------------
   134  *  
   135  *  WAP Reassembly Store:
   136  *  
   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  *  -----------------------------------------------------------------
   145  *  
   146  *  </pre>
   147  *  
   148  *  @publishedAll
   149  *  @released 
   150  *
   151  */
   152 class TSAREntry
   153 	{
   154 public:
   155 	enum
   156 		{
   157 		ESmsSAREntryDescriptionLength=32
   158 		};
   159 public:
   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;
   168 
   169 	/**
   170 	 *  Gets the Log server ID field.
   171 	 *  
   172 	 *  	@return Log server ID field 
   173 	 */
   174 	inline TInt LogServerId() const {return iData2;}
   175 	/**
   176 	 *  Sets the Log server ID field.
   177 	 *  
   178 	 *  	@param aId Log server ID field 
   179 	 */
   180 	inline void SetLogServerId(TInt aId) {iData2 = aId;}
   181 
   182 	inline TPtrC Description1() const;
   183 	inline void SetDescription1(const TDesC& aDescription);
   184 	inline TPtrC Description2() const;
   185 	inline void SetDescription2(const TDesC& aDescription);
   186 
   187 	inline TInt Data3() const;
   188 	inline void SetData3(TInt aData);
   189 
   190 	inline const TTime& Time() const;
   191 	inline void SetTime(const TTime& aTime);
   192 
   193 	inline TStreamId DataStreamId() const;
   194 	inline void SetDataStreamId(TStreamId aStreamId);
   195 
   196 	IMPORT_C void InternalizeL(RReadStream& aStream);
   197 	IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
   198 
   199 private:
   200 	inline TBool IsDeleted() const;
   201 	inline void SetIsDeleted(TBool aIsDeleted);
   202 	inline TBool IsAdded() const;
   203 	inline void SetIsAdded(TBool aIsAdded);
   204 
   205 private:
   206 	enum TSAREntryFlags
   207 		{
   208 		ESAREntryIsDeleted=0x01, ///< indicates that this entry is deleted
   209 		ESAREntryIsAdded=0x02    ///< indicated that this entry is added
   210 		};
   211 private:
   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
   215 protected:
   216 	TInt iData1;     /// TODO should be TUint32
   217 	TInt iData2;     ///< Log server ID
   218 	TInt iData3;
   219 	TInt iData4;
   220 private:
   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;
   229 	};
   230 
   231 
   232 /**
   233  *  Abstraction of an SMS reassembly store entry for incoming SMS messages.
   234  *  
   235  *  This class should reflect parts of a complete SMS message to be stored in
   236  *  the reassembly store.
   237  *  @publishedAll
   238  *  @released 
   239  */
   240 class TSmsReassemblyEntry : public TSAREntry
   241 	{
   242 private:
   243 	enum
   244 		{
   245 		KMarkedAsPassedToClientFlag = 0x80000000,
   246 		KPduTypeMask = 0xFF,
   247 		KReassemblyEntryClear = 0x00
   248 		};
   249 
   250 public:
   251 	// iData1
   252 	/**
   253 	 *  Gets bits 7 to 4 from Data1 field.
   254 	 *  
   255 	 *  	@return Bits 7 to 4 of Data 1 
   256 	 */
   257 	inline TInt Bits7to4() const {return (iData1 >> 16) & 0xffff;}
   258 	/**
   259 	 *  Gets Identifier1 from Data1 field.
   260 	 *  
   261 	 *  	@return Identifier1 
   262 	 */
   263 	inline TInt Identifier1() const {return (iData1 >> 8) & 0xff;}
   264 	/**
   265 	 *  Gets Identifier2 from Data1 field.
   266 	 *  
   267 	 *  	@return Identifier2 
   268 	 */
   269 	inline TInt Identifier2() const {return (iData1 >> 0) & 0xff;}
   270 	inline void SetBits7to4andIdentifiers(TInt aBits7to4, TInt aId1, TInt aId2)
   271 	/**
   272 	 *  Sets bits 7 to 4, Identifier1, and Identifier2, in Data1 field.
   273 	 *  
   274 	 *  @param aBits7to4 Bits 7 to 4
   275 	 *  @param aId1 Identifier1
   276 	 *  	@param aId2 Identifier2 
   277 	 */
   278 	{iData1 = (TInt)((aBits7to4 << 16) | ((aId1 & 0xff)<< 8) | (aId2 & 0xff)); }
   279 
   280 	// iData3
   281 	/**
   282 	 *  Gets PDU type.
   283 	 *  
   284 	 *  	@return PDU type 
   285 	 */
   286 	inline CSmsPDU::TSmsPDUType PduType() const {return (CSmsPDU::TSmsPDUType)(iData3 & 0xff);} // 8 bits
   287 	/**
   288 	 *  Sets PDU type.
   289 	 *  
   290 	 *  	@param aPduType PDU type 
   291 	 */
   292 	inline void SetPduType(CSmsPDU::TSmsPDUType aPduType) {iData3 = (iData3 & ~KPduTypeMask) | (TInt)(aPduType & KPduTypeMask);}
   293 
   294 	/**
   295 	 *  Tests if Passed To Client flag is set.
   296 	 *  
   297 	 *  	@return True if Passed To Client flag is set. 
   298 	 */
   299 	inline TBool PassedToClient() const {return (iData3 & KMarkedAsPassedToClientFlag) ? ETrue:EFalse;}
   300 	/**
   301 	 *  Sets Passed To Client flag.
   302 	 *  
   303 	 *  	@param aPassed True if Passed To Client flag is set. 
   304 	 */
   305 	inline void SetPassedToClient(TBool aPassed) {iData3 = (iData3 & ~KMarkedAsPassedToClientFlag) | (aPassed ? KMarkedAsPassedToClientFlag : KReassemblyEntryClear);}
   306 
   307 	// iData4
   308 	/**
   309 	 *  Gets storage information.
   310 	 *  
   311 	 *  	@return Storage information 
   312 	 */
   313 	inline CSmsMessage::TMobileSmsStorage Storage() const {return (CSmsMessage::TMobileSmsStorage)(iData4 & 0xff);}
   314 	/**
   315 	 *  Sets storage information.
   316 	 *  
   317 	 *  	@param aStorage Storage information 
   318 	 */
   319 	inline void SetStorage(CSmsMessage::TMobileSmsStorage aStorage) {iData4 = (CSmsMessage::TMobileSmsStorage)aStorage;}
   320 	};
   321 
   322 
   323 /**
   324  *  Abstraction of an SMS segmentation store entry for outgoing SMS messages.
   325  *  
   326  *  This class should reflect parts of a complete SMS message to be stored in
   327  *  the segmentation store.
   328  *  @publishedAll
   329  *  @released 
   330  */
   331 class TSmsSegmentationEntry : public TSAREntry
   332 	{
   333 public:
   334 	// iData1
   335 	/**
   336 	 *  Gets number of delivered PDUs.
   337 	 *  
   338 	 *  	@return Number of delivered PDUs 
   339 	 */
   340 	inline TInt Delivered() const {return (iData1 >> 16);}
   341 	/**
   342 	 *  Gets number of permanently failed PDUs.
   343 	 *  
   344 	 *  	@return Number of permanently failed PDUs 
   345 	 */
   346 	inline TInt Failed() const {return (iData1 & 0xffff);}
   347 	inline void SetDeliveredAndFailed(TInt aDelivered, TInt aFailed)
   348 	/**
   349 	 *  Sets the number of delivered and failed PDUs.
   350 	 *  
   351 	 *  @param aDelivered Number of delivered PDUs
   352 	 *  	@param aFailed Number of permanently failed PDUs 
   353 	 */
   354 		{iData1 = ((aDelivered << 16) | (aFailed & 0xffff));}
   355 
   356 	// iData3
   357 	/**
   358 	 *  Gets the Validity Period.
   359 	 *  
   360 	 *  	@return Validity Period 
   361 	 */
   362 	inline TInt ValidityPeriod() const {return (iData3); }
   363 	/**
   364 	 *  Sets the Validity Period.
   365 	 *  
   366 	 *  	@param aValPer Validity Period 
   367 	 */
   368 	inline void SetValidityPeriod(TInt aValPer) {iData3 = aValPer; }
   369 
   370 	// iData4
   371 	/**
   372 	 *  Tests if a status report is expected.
   373 	 *  
   374 	 *  	@return True if a status report is expected 
   375 	 */
   376 	inline TBool ExpectStatusReport() const {return (((iData4 >> 24) & 0x01) == 0x01); }
   377 	/**
   378 	 *  Gets the type of the PDU.
   379 	 *  
   380 	 *  	@return Type of the PDU 
   381 	 */
   382 	inline CSmsPDU::TSmsPDUType PduType() const {return (CSmsPDU::TSmsPDUType)((iData4 >> 16) & 0xff); }
   383 	/**
   384 	 *  Gets the message reference (low byte).
   385 	 *  
   386 	 *  	@return Message reference (low byte) 
   387 	 */
   388 	inline TInt Reference1() const {return ((iData4 >> 8) & 0xff); }
   389 	/**
   390 	 *  Gets the message reference (high byte).
   391 	 *  
   392 	 *  	@return Message reference (high byte) 
   393 	 */
   394 	inline TInt Reference2() const {return ((iData4 >> 0) & 0xff); }
   395 	inline void SetPduTypeAndRefs(TBool aSR, TInt aPduType, TInt aRef1, TInt aRef2)
   396 	/**
   397 	 *  Sets status report flag, PDU type, and message references.
   398 	 *  
   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) 
   403 	 */
   404 		{iData4 = (((aSR & 0x01) << 24) | (aPduType << 16) | ((aRef1 & 0xff ) << 8) | (aRef2 & 0xff));}
   405 	};
   406 
   407 
   408 /**
   409  *  Abstraction of a WAP reassembly store entry.
   410  *  This class should reflect a complete WAP message.
   411  *  @publishedAll
   412  *  @released
   413  */
   414 class TWapReassemblyEntry : public TSAREntry
   415 	{
   416 public:
   417 	/**
   418 	 *  Gets the destination port number.
   419 	 *  
   420 	 *  	@return Destination port number 
   421 	 */
   422 	inline TInt ToPort() const {return iData1;}
   423 	/**
   424 	 *  Sets the destination port number.
   425 	 *  
   426 	 *  	@param aToPort Destination port number 
   427 	 */
   428 	inline void SetToPort(TInt aToPort){iData1 = aToPort;}
   429 	};
   430 
   431 /**
   432  *  Controls the segmentation and reassembly (SAR) store, used for SMS segmentation
   433  *  and reassembly, and WAP reassembly.
   434  *  @publishedAll
   435  *  @released 
   436  */
   437 class CSARStore : public CBase
   438 	{
   439 public:
   440 	IMPORT_C void OpenL(const TDesC& aFullName,const TUid& aThirdUid);
   441 	IMPORT_C void Close();
   442 	IMPORT_C void CompactL();
   443 
   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);
   448 
   449 	IMPORT_C void BeginTransactionLC();
   450 	IMPORT_C void CommitTransactionL(); //Pops this off this cleanup stack and commits iFileStore
   451 	void Revert();
   452 
   453 	inline RFs& FileSession() const;
   454 	inline TBool InTransaction()const;
   455 	IMPORT_C void DoOpenL();
   456 	IMPORT_C void PrivatePath(TDes& aPath);
   457 
   458 
   459 protected:
   460 	IMPORT_C CSARStore(RFs& aFs);
   461 	IMPORT_C ~CSARStore();
   462 
   463 	IMPORT_C CFileStore& FileStore();
   464 	IMPORT_C const CFileStore& FileStore() const;
   465 
   466 	IMPORT_C void AddEntryL(const TSAREntry& aEntry);
   467 	IMPORT_C void ChangeEntryL(TInt aIndex,const TSAREntry& aNewEntry);
   468 
   469 	IMPORT_C TStreamId ExtraStreamId() const;
   470 	IMPORT_C void SetExtraStreamIdL(const TStreamId& aExtraStreamId);
   471 
   472 private:
   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();
   479 
   480 private:
   481 	enum
   482 		{
   483 		KNumStoreCommitsBeforeCompaction=16
   484 		};
   485 
   486 protected:
   487 	RFs& iFs;                             ///< File server handle.
   488 private:
   489 
   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
   495 	TUid iThirdUid;
   496 	TBool iInTransaction;					///< For debugging purposes to ensure only one transaction at a time
   497 	};
   498 
   499 /**
   500  *  Closes all SAR stores if a backup event starts.
   501  *  
   502  *  This is internal and not intended for use.
   503  *  @publishedAll
   504  *  @released 
   505  */
   506 class CGsmuBackupObserver : public CBase, MBackupOperationObserver
   507 	{
   508 	public:
   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);
   513 
   514 	private:
   515 		CGsmuBackupObserver();
   516 		void ConstructL();
   517 		void HandleBackupOperationEventL(const TBackupOperationAttributes& aBackupOperationAttributes);
   518 
   519 		CBaBackupSessionWrapper* iBackup;
   520 		RPointerArray<CSARStore> iSARStores;
   521 	};
   522 
   523 #include "gsmustor.inl"
   524 
   525 #endif // !defined GSMUSTOR_H__