iaupdate/IAD/updater/updaterfiles/src/iaupdateridentifier.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   CIAUpdaterIdentifier
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "iaupdateridentifier.h"
       
    22 
       
    23 
       
    24 // This constant will be used to check if the IAD application
       
    25 // and iaupdater are using the same version of the file. If the versions
       
    26 // differ, then this may require additional checking in the future versions
       
    27 // when data is internalized. For example, IAD may give old version data 
       
    28 // for iaupdater during self update just after iaupdater has been updated
       
    29 // and IAD is itself updated after that.
       
    30 const TInt KVersion( 1 );
       
    31 
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CIAUpdaterIdentifier::NewL
       
    35 //
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 EXPORT_C CIAUpdaterIdentifier* CIAUpdaterIdentifier::NewL()
       
    39     {
       
    40     CIAUpdaterIdentifier* self =
       
    41         CIAUpdaterIdentifier::NewLC();
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45 
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CIAUpdaterIdentifier::NewLC
       
    49 //
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 EXPORT_C CIAUpdaterIdentifier* CIAUpdaterIdentifier::NewLC()
       
    53     {
       
    54     CIAUpdaterIdentifier* self =
       
    55         new( ELeave) CIAUpdaterIdentifier();
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     return self;    
       
    59     }
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CIAUpdaterIdentifier::CIAUpdaterIdentifier
       
    64 //
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CIAUpdaterIdentifier::CIAUpdaterIdentifier()
       
    68 : CBase(),
       
    69   iUid( TUid::Null() )
       
    70     {
       
    71     }
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CIAUpdaterIdentifier::ConstructL
       
    76 //
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CIAUpdaterIdentifier::ConstructL()
       
    80     {
       
    81     }
       
    82 
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CIAUpdaterIdentifier::~CIAUpdaterIdentifier
       
    86 //
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 EXPORT_C CIAUpdaterIdentifier::~CIAUpdaterIdentifier()
       
    90     {
       
    91     Reset();
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CIAUpdaterIdentifier::Reset
       
    97 //
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 EXPORT_C void CIAUpdaterIdentifier::Reset()
       
   101     {
       
   102     iUid = TUid::Null();
       
   103     
       
   104     delete iId;
       
   105     iId = NULL;
       
   106     
       
   107     delete iNamespace;
       
   108     iNamespace = NULL;    
       
   109     }
       
   110 
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CIAUpdaterIdentifier::Id
       
   114 //
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 EXPORT_C const TDesC& CIAUpdaterIdentifier::Id() const
       
   118     {
       
   119     if ( !iId )
       
   120         {
       
   121         return KNullDesC;
       
   122         }
       
   123         
       
   124     return *iId;
       
   125     }
       
   126     
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CIAUpdaterIdentifier::SetIdL
       
   130 //
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 EXPORT_C void CIAUpdaterIdentifier::SetIdL( const TDesC& aId )
       
   134     {
       
   135     HBufC* tmp( aId.AllocL() );
       
   136     delete iId;
       
   137     iId = tmp;
       
   138     }
       
   139     
       
   140     
       
   141 // -----------------------------------------------------------------------------
       
   142 // CIAUpdaterIdentifier::Namespace
       
   143 //
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 EXPORT_C const TDesC& CIAUpdaterIdentifier::Namespace() const
       
   147     {
       
   148     if ( !iNamespace )
       
   149         {
       
   150         return KNullDesC;
       
   151         }
       
   152     
       
   153     return *iNamespace;
       
   154     }
       
   155     
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CIAUpdaterIdentifier::SetNamespaceL
       
   159 //
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 EXPORT_C void CIAUpdaterIdentifier::SetNamespaceL( const TDesC& aNamespace )
       
   163     {
       
   164     HBufC* tmp( aNamespace.AllocL() );
       
   165     delete iNamespace;
       
   166     iNamespace = tmp;
       
   167     }
       
   168     
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CIAUpdaterIdentifier::Uid
       
   172 //
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C const TUid& CIAUpdaterIdentifier::Uid() const
       
   176     {
       
   177     return iUid;
       
   178     }
       
   179 
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CIAUpdaterIdentifier::SetUid
       
   183 //
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 EXPORT_C void CIAUpdaterIdentifier::SetUid( const TUid& aUid )
       
   187     {
       
   188     iUid.iUid = aUid.iUid;
       
   189     }
       
   190 
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CIAUpdaterIdentifier::SetUid
       
   194 //
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 EXPORT_C void CIAUpdaterIdentifier::SetUid( const TInt aUid )
       
   198     {
       
   199     iUid.iUid = aUid;
       
   200     }
       
   201 
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CIAUpdaterIdentifier::InternalizeL
       
   205 //
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 EXPORT_C void CIAUpdaterIdentifier::InternalizeL( RReadStream& aStream )
       
   209 	{
       
   210 	// If you make changes here, 
       
   211 	// remember to update ExternalizeL accordingly!!!
       
   212 
       
   213     TInt version( aStream.ReadInt32L() );
       
   214 
       
   215     // Notice! In the future, some checking maybe required here
       
   216     // to be sure that file version is correct and the data can be
       
   217     // internalized correctly between different versions.
       
   218     if ( version != KVersion )
       
   219         {
       
   220         // For now, just leave with the corrupt error.
       
   221         User::Leave( KErrCorrupt );
       
   222         }
       
   223 	
       
   224     TInt length( aStream.ReadInt32L() );
       
   225     HBufC* tmpId( NULL );
       
   226     if ( length > 0 )
       
   227         {
       
   228         tmpId = HBufC::NewLC( length );
       
   229         TPtr idPtr( tmpId->Des() );
       
   230         aStream.ReadL( idPtr, length );        
       
   231         }
       
   232 
       
   233     length = aStream.ReadInt32L();
       
   234     HBufC* tmpNamespace( NULL );
       
   235     if ( length > 0 )
       
   236         {
       
   237         tmpNamespace = HBufC::NewLC( length );
       
   238         TPtr namespacePtr( tmpNamespace->Des() );
       
   239         aStream.ReadL( namespacePtr, length );        
       
   240         }
       
   241 
       
   242     TInt tmpUid( aStream.ReadInt32L() );
       
   243 
       
   244     if ( tmpNamespace )
       
   245         {
       
   246         CleanupStack::Pop( tmpNamespace );        
       
   247         }
       
   248 
       
   249     if ( tmpId )
       
   250         {
       
   251         CleanupStack::Pop( tmpId );        
       
   252         }
       
   253     
       
   254     delete iId;
       
   255     iId = tmpId;
       
   256 
       
   257     delete iNamespace;
       
   258     iNamespace = tmpNamespace;   
       
   259 
       
   260     iUid.iUid = tmpUid;
       
   261 	}
       
   262 
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CIAUpdaterIdentifier::ExternalizeL
       
   266 //
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 EXPORT_C void CIAUpdaterIdentifier::ExternalizeL( RWriteStream& aStream )
       
   270 	{
       
   271 	// If you make changes here, 
       
   272 	// remember to update InternalizeL accordingly!!!
       
   273 
       
   274     aStream.WriteInt32L( KVersion );
       
   275 
       
   276     TInt length( Id().Length() );
       
   277     aStream.WriteInt32L( length );
       
   278     if ( length > 0 )
       
   279         {
       
   280         aStream.WriteL( Id(), length );        
       
   281         }
       
   282 
       
   283     length = Namespace().Length();
       
   284     aStream.WriteInt32L( length );
       
   285     if ( length > 0 )
       
   286         {
       
   287         aStream.WriteL( Namespace(), length );        
       
   288         }
       
   289     
       
   290 	aStream.WriteInt32L( iUid.iUid );
       
   291 	}