messagingappbase/obexmtms/obexmtm/obexutil/source/obexHeader.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2001-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 // $Workfile: obexHeader.cpp $
       
    15 // $Author: Stevep $
       
    16 // $Revision: 11 $
       
    17 // $Date: 25/03/02 10:57 $
       
    18 // 
       
    19 //
       
    20 
       
    21 //class include
       
    22 #include <obexheader.h>
       
    23 //system includes
       
    24 #include <msvstore.h>   //CMsvStore, RMsvWriteStream, RMsvReadStream
       
    25 
       
    26 //user includes
       
    27 #include <obexinternalutils.h>
       
    28 
       
    29 EXPORT_C CObexMtmHeader::CObexMtmHeader(TUid aStreamUid, TInt32 aStreamVersion) :
       
    30 	iStreamUid (aStreamUid),
       
    31 	iStreamVersion(aStreamVersion)	
       
    32 
       
    33 /**
       
    34 Default constructor, which assigns the TUid for the stream and stream version
       
    35 
       
    36   @param aStreamUid Uid of the header stream--specified in the derived class
       
    37   @param aStreamVersion Version number for the stream, must be specified in the derived classes 
       
    38   and incremented each time a new version of the stream is implemented.
       
    39 */
       
    40 	{
       
    41 	}
       
    42 EXPORT_C void CObexMtmHeader::BaseConstructL()
       
    43 /**
       
    44  * Leaving constructor, which must be called by the base classes to initialise the HBufC members
       
    45  */
       
    46 	{
       
    47 	iName = HBufC::NewL(0);
       
    48 	iSubject = HBufC::NewL(0);
       
    49 	iType = HBufC8::NewL(0);
       
    50 	iTarget = HBufC8::NewL(0);
       
    51 	iConnectionID = HBufC8::NewL(0);
       
    52 	}
       
    53 
       
    54 EXPORT_C CObexMtmHeader::~CObexMtmHeader()
       
    55 /**
       
    56 * Destructor which deletes all of the HBufC members
       
    57 */
       
    58 	{
       
    59 	delete iName;
       
    60 	delete iSubject;
       
    61 	delete iType;
       
    62 	delete iTarget;
       
    63 	delete iConnectionID;
       
    64 	}
       
    65 
       
    66 
       
    67 EXPORT_C void CObexMtmHeader::SetTime(const TTime& aTime)
       
    68 /**
       
    69  * Sets the Time header value
       
    70  * @param aTime The new Time header value
       
    71  */
       
    72 	{
       
    73 	iTime = aTime;
       
    74 	}
       
    75 
       
    76 EXPORT_C const TTime& CObexMtmHeader::Time() const
       
    77 /**
       
    78  * Returns the Time header value
       
    79  * @return Time header value
       
    80  */
       
    81 	{
       
    82 	return iTime;
       
    83 	}
       
    84 
       
    85 
       
    86 EXPORT_C void CObexMtmHeader::SetLength(TInt aLength)
       
    87 /**
       
    88  *Sets the Length header value
       
    89  * @param aLength The new Length header value
       
    90  */
       
    91 	{
       
    92 	iLength = aLength;
       
    93 	}
       
    94 
       
    95 EXPORT_C TInt CObexMtmHeader::Length() const
       
    96 /**
       
    97 * Returns the Length header value
       
    98 * @return Length header value
       
    99 */
       
   100 	{
       
   101 	return iLength;
       
   102 	}
       
   103 
       
   104 
       
   105 EXPORT_C TPtrC CObexMtmHeader::Name() const
       
   106 /**
       
   107 * Returns the Name header value.
       
   108 * @return The Name header value. This will be a zero-length descriptor if this Name has not been set.
       
   109 */
       
   110     {
       
   111     return TPtrC(*iName);
       
   112     }
       
   113 
       
   114 EXPORT_C void CObexMtmHeader::SetNameL(const TDesC& aName)
       
   115 /**
       
   116 * Sets the Name header value.
       
   117 * @param aName The new Name header value
       
   118 * @leave KErrXXX Standard EPOC error codes if allocation of a buffer to hold the Name header fails.
       
   119 */
       
   120     {
       
   121     delete iName;
       
   122     iName = NULL;
       
   123     iName = aName.AllocL();
       
   124     }
       
   125 
       
   126 
       
   127 EXPORT_C TPtrC CObexMtmHeader::Subject() const
       
   128 /**
       
   129 * Returns the Subject header value.
       
   130 * @return The Subject header value. This will be a zero-length descriptor if this Subject has not been set.
       
   131 */
       
   132     {
       
   133     return TPtrC(*iSubject);
       
   134     }
       
   135 
       
   136 EXPORT_C void CObexMtmHeader::SetSubjectL(const TDesC& aSubject)
       
   137 /**
       
   138 * Sets the Subject header value.
       
   139 *
       
   140 * @param aName The new Subject header value
       
   141 * @leave KErrXXX Standard EPOC error codes if allocation of a buffer to hold the Subject header fails.
       
   142 */
       
   143     {
       
   144     delete iSubject;
       
   145     iSubject = NULL;
       
   146     iSubject = aSubject.AllocL();
       
   147     }
       
   148 
       
   149 
       
   150 EXPORT_C TPtrC8 CObexMtmHeader::Type() const
       
   151 /**
       
   152 * Returns the Type header value.
       
   153 * @return The Type header value. This will be a zero-length descriptor if this Type has not been set.
       
   154 */
       
   155     {
       
   156     return TPtrC8(*iType);
       
   157     }
       
   158 
       
   159 EXPORT_C void CObexMtmHeader::SetTypeL(const TDesC8& aType)
       
   160 /**
       
   161 * Sets the Type header value.
       
   162 *
       
   163 * @param aType The new Type header value
       
   164 * @leave KErrXXX Standard EPOC error codes if allocation of a buffer to hold the Type header fails.
       
   165 */
       
   166     {
       
   167     delete iType;
       
   168     iType = NULL;
       
   169     iType = aType.AllocL();
       
   170     }
       
   171 
       
   172 
       
   173 EXPORT_C TPtrC8 CObexMtmHeader::ConnectionID() const
       
   174 /**
       
   175 * Returns the ConnectionID header value.
       
   176 * @return The ConnectionID header value. This will be a zero-length descriptor if this ConnectionID has not been set.
       
   177 */
       
   178     {
       
   179     return TPtrC8(*iConnectionID);
       
   180     }
       
   181 
       
   182 EXPORT_C void CObexMtmHeader::SetConnectionIDL(const TDesC8& aConnectionID)
       
   183 /**
       
   184 * Sets the ConnectionID header value.
       
   185 * 
       
   186 * @param ConnectionID The new ConnectionID header value
       
   187 * @leave KErrXXX Standard EPOC error codes if allocation of a buffer to hold the ConnectionID header fails.
       
   188 */
       
   189     {
       
   190     delete iConnectionID;
       
   191     iConnectionID = NULL;
       
   192     iConnectionID = aConnectionID.AllocL();
       
   193     }
       
   194 
       
   195 
       
   196 EXPORT_C TPtrC8 CObexMtmHeader::Target() const
       
   197 /**
       
   198 * Returns the Target header value.
       
   199 * @return The Target header value. This will be a zero-length descriptor if this Target has not been set.
       
   200 */
       
   201     {
       
   202     return TPtrC8(*iTarget);
       
   203     }
       
   204 
       
   205 EXPORT_C void CObexMtmHeader::SetTargetL(const TDesC8& aTarget)
       
   206 /**
       
   207 * Sets the ConnectionID header value.
       
   208 * 
       
   209 * @param ConnectionID The new Target header value
       
   210 * @leave KErrXXX Standard EPOC error codes if allocation of a buffer to hold the Target header fails.
       
   211 */
       
   212     {
       
   213     delete iTarget;
       
   214     iTarget = NULL;
       
   215     iTarget = aTarget.AllocL();
       
   216     }
       
   217 
       
   218 
       
   219 
       
   220 EXPORT_C void CObexMtmHeader::StoreL(CMsvStore& aStore) const
       
   221 /**
       
   222  * Creates a stream in aStore and externalises this object to it.
       
   223  *
       
   224  *
       
   225  * @param aStore The store to which this object is to be stored. Note this must be open with write access or 
       
   226  *  this function will leave.
       
   227  * @leave KErrXXX Standard EPOC stream leave codes.
       
   228  * @leave KErrAccessDenied aStore is not opened with write access.
       
   229  */
       
   230     {
       
   231     RMsvWriteStream out;
       
   232     out.AssignLC(aStore, iStreamUid); 
       
   233     
       
   234     ExternalizeL(out);
       
   235 
       
   236     out.CommitL();//Commit the stream, but not the store.  The store will be committed by
       
   237                   //the owning class that's passed the store into this method.
       
   238     out.Close(); // make sure we close the stream
       
   239     
       
   240     CleanupStack::PopAndDestroy();
       
   241     }
       
   242 
       
   243 EXPORT_C void CObexMtmHeader::RestoreL(const CMsvStore& aStore)
       
   244 /**
       
   245  * Opens a stream in aStore and internalises this object from it.
       
   246  * @param aStore The store from which this object is to be restored. Note this must be open with read or 
       
   247  *  read/write access or this function will leave.
       
   248  * @leave KErrXXX Standard EPOC stream leave codes. 
       
   249  * @leave KErrAccessDenied aStore is not opened with read access.
       
   250  */
       
   251     {
       
   252     RMsvReadStream in;
       
   253     in.OpenLC(aStore, iStreamUid); 
       
   254 
       
   255     InternalizeL(in);
       
   256 
       
   257     in.Close();// make sure we close the stream
       
   258     CleanupStack::PopAndDestroy();
       
   259     }
       
   260 
       
   261 EXPORT_C void CObexMtmHeader::BaseExternalizeL(RMsvWriteStream& aWriteStream) const
       
   262 /**
       
   263  * Externalizes CObexMtmHeader object to a stream. Must be called by the derived class BEFORE 
       
   264  * that class externalizes
       
   265  *
       
   266  * @param aWriteStream The stream to be written to
       
   267  * @leave KErrXXX Standard EPOC stream leave codes
       
   268  */
       
   269     {
       
   270     // N.B. THE STREAM VERSION NUMBER MUST BE WRITTEN FIRST
       
   271     aWriteStream.WriteInt32L(KObexMessageStreamVersion);
       
   272 
       
   273     //TTime
       
   274     aWriteStream << iTime.Int64();
       
   275 
       
   276     //TInt
       
   277     aWriteStream.WriteInt32L(iLength);
       
   278 
       
   279     //HBufC
       
   280     ObexInternalUtils::ExternalizeL(iName, aWriteStream);
       
   281     ObexInternalUtils::ExternalizeL(iSubject, aWriteStream);
       
   282 
       
   283     //HBufC8
       
   284     ObexInternalUtils::ExternalizeL(iConnectionID, aWriteStream);
       
   285     ObexInternalUtils::ExternalizeL(iType, aWriteStream);
       
   286     ObexInternalUtils::ExternalizeL(iTarget, aWriteStream);
       
   287     }
       
   288 
       
   289 EXPORT_C void CObexMtmHeader::BaseInternalizeL( RMsvReadStream& aReadStream)
       
   290 /**
       
   291  * Internalizes the CObexMtmHeader object from a stream.Must be called by the derived class BEFORE 
       
   292  * that class internalizes
       
   293  *
       
   294  * @param aReadStream The stream to be read from
       
   295  * @leave KErrXXX Standard EPOC stream leave codes
       
   296  */
       
   297     {
       
   298 
       
   299     //CDesCArrays get reset by ::InternalizeL and are passed by reference, so they shouldn't be deleted
       
   300 
       
   301 
       
   302     const TInt32 STREAM_VERSION = aReadStream.ReadInt32L();
       
   303 
       
   304     switch (STREAM_VERSION)
       
   305         {
       
   306         case 1:
       
   307             {
       
   308             //TTime
       
   309             TInt64 time; 
       
   310             aReadStream >> time;
       
   311             iTime = time; 
       
   312 
       
   313             //TInt
       
   314             iLength = aReadStream.ReadInt32L();
       
   315 
       
   316             //HBufC 
       
   317             ObexInternalUtils::InternalizeL(iName, aReadStream);
       
   318             ObexInternalUtils::InternalizeL(iSubject, aReadStream);
       
   319 
       
   320 			//HBufC8
       
   321             ObexInternalUtils::InternalizeL(iConnectionID, aReadStream);
       
   322             ObexInternalUtils::InternalizeL(iType, aReadStream);
       
   323             ObexInternalUtils::InternalizeL(iTarget, aReadStream);
       
   324 
       
   325             break;
       
   326             }
       
   327 
       
   328         default:
       
   329 			ObexInternalUtils::Panic(ObexInternalUtils::EObexBadStreamVersion);
       
   330             break;
       
   331         }
       
   332     }
       
   333 
       
   334 
       
   335