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