iaupdate/IAD/tools/src/iaupdatetools.cpp
branchRCL_3
changeset 66 8b7f4e561641
parent 0 ba25891c3a9e
equal deleted inserted replaced
65:7333d7932ef7 66:8b7f4e561641
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:   This module contains the implementation of IAUpdateTools functions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #include <s32mem.h>
       
    24 #include <iaupdateparameters.h>
       
    25 
       
    26 #include "iaupdatetools.h"
       
    27 #include "iaupdatedebug.h"
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // IAUpdateTools::ExternalizeParametersL
       
    31 // 
       
    32 // -----------------------------------------------------------------------------
       
    33 // 
       
    34 EXPORT_C void IAUpdateTools::ExternalizeParametersL( HBufC8*& aTarget,
       
    35                                                      const CIAUpdateParameters& aSource )
       
    36     {
       
    37     IAUPDATE_TRACE("[IAUPDATE] IAUpdateTools::ExternalizeParametersL begin");
       
    38     // Notice!
       
    39     // If you make changes here. Also, remember to make corresponding
       
    40     // changes to the InternalizeParametersL
       
    41 
       
    42     // The size of the buffer will contain:
       
    43     // - 1 TInt for UIDs,
       
    44     // - 1 TBool for ShowProgress boolean
       
    45     // - 1 TUint for importance
       
    46     // - 1 TUint for type
       
    47     // - 1 TBool for Refresh boolean
       
    48     
       
    49     // - 3 TInt for descriptor lengths
       
    50     // --> bytes for 5 + 3 = 8 TInt values are needed 
       
    51     //     (sizeof( TInt ) * KNumberOfTInts)
       
    52     // - 3 descriptor TDesC texts
       
    53     const TInt KNumberOfTInts( 8 );
       
    54 
       
    55     // Notice, that because descriptor texts that are included
       
    56     // here are TDesC, their Size-information has to be used
       
    57     // instead of Length.
       
    58     HBufC8* tmp = 
       
    59         HBufC8::NewLC( sizeof( TInt ) * KNumberOfTInts
       
    60                        + aSource.SearchCriteria().Size()
       
    61                        + aSource.CommandLineExecutable().Size()
       
    62                        + aSource.CommandLineArguments().Size() );
       
    63 
       
    64     // Create stream that uses the buffer created above.
       
    65     // By using the stream, the values are easier to insert into the buffer.
       
    66     TPtr8 ptr( tmp->Des() );    
       
    67     RDesWriteStream stream( ptr );
       
    68     CleanupClosePushL( stream );
       
    69 
       
    70     // These are integers for uids
       
    71     IAUPDATE_TRACE_1("[IAUPDATE] uid: %x", aSource.Uid().iUid );
       
    72     stream.WriteInt32L( aSource.Uid().iUid );
       
    73 
       
    74     // These are length and data pairs for descriptors
       
    75     IAUPDATE_TRACE_1("[IAUPDATE] search criteria: %S", &aSource.SearchCriteria() );
       
    76     ExternalizeDesL( aSource.SearchCriteria(), stream );
       
    77     IAUPDATE_TRACE_1("[IAUPDATE] command line executable: %S", &aSource.CommandLineExecutable() );
       
    78     ExternalizeDesL( aSource.CommandLineExecutable(), stream );
       
    79 #ifdef _DEBUG
       
    80     HBufC* temp = HBufC::NewL( aSource.CommandLineArguments().Length() );
       
    81     temp->Des().Copy( aSource.CommandLineArguments()) ;
       
    82     IAUPDATE_TRACE_1("[IAUPDATE] command line arguments: %S", temp );
       
    83     delete temp;
       
    84 #endif //_DEBUG
       
    85     ExternalizeDes8L( aSource.CommandLineArguments(), stream );
       
    86     
       
    87     // Boolean for ShowProgress
       
    88     stream.WriteInt32L( aSource.ShowProgress() );
       
    89     
       
    90     // TUint for importance
       
    91     stream.WriteInt32L( aSource.Importance() );
       
    92     
       
    93     // TUint for type
       
    94     stream.WriteInt32L( aSource.Type() );
       
    95     
       
    96     // Boolean for Refresh
       
    97     stream.WriteInt32L( aSource.Refresh() );
       
    98 
       
    99     // Stream is not needed anymore
       
   100     CleanupStack::PopAndDestroy( &stream );
       
   101 
       
   102     // Remove tmp from the stack but do not delete it because it will be
       
   103     // assigned to the aTarget below.
       
   104     CleanupStack::Pop( tmp );
       
   105     
       
   106     // Replace aTarget with new value
       
   107     delete aTarget;
       
   108     aTarget = tmp;
       
   109     IAUPDATE_TRACE("[IAUPDATE] IAUpdateTools::ExternalizeParametersL end");
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // IAUpdateTools::InternalizeParametersL
       
   114 // 
       
   115 // -----------------------------------------------------------------------------
       
   116 // 
       
   117 EXPORT_C void IAUpdateTools::InternalizeParametersL( CIAUpdateParameters& aTarget, 
       
   118                                                      const TDesC8& aSource )
       
   119     {
       
   120     IAUPDATE_TRACE("[IAUPDATE] IAUpdateTools::InternalizeParametersL begin");
       
   121     // Notice!
       
   122     // If you make changes here. Also, remember to make corresponding
       
   123     // changes to the ExternalizeParametersL
       
   124 
       
   125     // InternalizeDesL function will set values into this tmp descriptor.
       
   126     HBufC* tmp( NULL );
       
   127     
       
   128     // Create stream that uses the given buffer.
       
   129     RDesReadStream stream( aSource );
       
   130     CleanupClosePushL( stream );
       
   131 
       
   132     aTarget.SetUid( TUid::Uid( stream.ReadInt32L() ) );
       
   133     IAUPDATE_TRACE_1("[IAUPDATE] uid: %x", aTarget.Uid().iUid );
       
   134     
       
   135     InternalizeDesL( tmp, stream );
       
   136     CleanupStack::PushL( tmp );
       
   137     aTarget.SetSearchCriteriaL( *tmp );
       
   138     IAUPDATE_TRACE_1("[IAUPDATE] search criteria: %S", tmp );
       
   139     CleanupStack::PopAndDestroy( tmp );
       
   140     tmp = NULL;
       
   141         
       
   142     InternalizeDesL( tmp, stream );
       
   143     CleanupStack::PushL( tmp );
       
   144     aTarget.SetCommandLineExecutableL( *tmp );
       
   145     IAUPDATE_TRACE_1("[IAUPDATE] command line executable: %S", tmp );
       
   146     CleanupStack::PopAndDestroy( tmp );
       
   147     tmp = NULL;
       
   148 
       
   149     HBufC8* tmp8( NULL );        
       
   150     InternalizeDes8L( tmp8, stream );
       
   151     CleanupStack::PushL( tmp8 );
       
   152     aTarget.SetCommandLineArgumentsL( *tmp8 );
       
   153 #ifdef _DEBUG
       
   154     tmp = HBufC::NewL( tmp8->Length() );
       
   155     tmp->Des().Copy( *tmp8 ) ;
       
   156     IAUPDATE_TRACE_1("[IAUPDATE] command line arguments: %S", tmp );
       
   157     delete tmp;
       
   158     tmp = NULL;
       
   159 #endif //_DEBUG
       
   160     CleanupStack::PopAndDestroy( tmp8 );
       
   161     tmp8 = NULL;
       
   162     
       
   163     aTarget.SetShowProgress( stream.ReadInt32L() );
       
   164 
       
   165     // new parameters (in phase 2 IAD) do not always exist. Parameters may have written by old IAD in selfupdate case.
       
   166     TRAPD( err, aTarget.SetImportance( stream.ReadInt32L() ) );
       
   167     if ( err != KErrEof )
       
   168         {
       
   169         User::LeaveIfError( err );
       
   170         aTarget.SetType( stream.ReadInt32L() );
       
   171         aTarget.SetRefresh( stream.ReadInt32L() );
       
   172         }
       
   173      
       
   174     IAUPDATE_TRACE_1("[IAUPDATE] show progress: %d", aTarget.ShowProgress() );
       
   175     CleanupStack::PopAndDestroy( &stream );   
       
   176     IAUPDATE_TRACE("[IAUPDATE] IAUpdateTools::InternalizeParametersL end");
       
   177     }
       
   178 
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // IAUpdateTools::ExternalizeDesL
       
   182 // 
       
   183 // -----------------------------------------------------------------------------
       
   184 // 
       
   185 EXPORT_C void IAUpdateTools::ExternalizeDesL( const TDesC& aDes, 
       
   186                                               RWriteStream& aStream )
       
   187     {
       
   188     aStream.WriteInt32L( aDes.Length() );
       
   189     aStream.WriteL( aDes );
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // IAUpdateTools::InternalizeDesL
       
   194 // 
       
   195 // -----------------------------------------------------------------------------
       
   196 // 
       
   197 EXPORT_C TInt IAUpdateTools::InternalizeDesL( HBufC*& aDes, 
       
   198                                               RReadStream& aStream )
       
   199     {
       
   200     TInt length = aStream.ReadInt32L();
       
   201     if ( length > 0 ) 
       
   202         {
       
   203         HBufC* target = HBufC::NewLC( length );
       
   204         TPtr ptr( target->Des() );        
       
   205         aStream.ReadL( ptr, length );
       
   206         delete aDes;
       
   207         aDes = target;
       
   208         CleanupStack::Pop( target );
       
   209         }
       
   210     else
       
   211         {
       
   212         delete aDes;
       
   213         aDes = KNullDesC().AllocL();
       
   214         }
       
   215     return length;
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // IAUpdateTools::ExternalizeDes8L
       
   220 // 
       
   221 // -----------------------------------------------------------------------------
       
   222 // 
       
   223 EXPORT_C void IAUpdateTools::ExternalizeDes8L( const TDesC8& aDes, RWriteStream& aStream )
       
   224     {
       
   225     aStream.WriteInt32L( aDes.Length() );
       
   226     aStream.WriteL( aDes );
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // IAUpdateTools::InternalizeDes8L
       
   231 // 
       
   232 // -----------------------------------------------------------------------------
       
   233 // 
       
   234 EXPORT_C TInt IAUpdateTools::InternalizeDes8L( HBufC8*& aDes, RReadStream& aStream )
       
   235     {
       
   236     TInt length = aStream.ReadInt32L();
       
   237     if ( length > 0 ) 
       
   238         {
       
   239         HBufC8* target = HBufC8::NewLC( length );
       
   240         TPtr8 ptr( target->Des() );        
       
   241         aStream.ReadL( ptr, length );
       
   242         delete aDes;
       
   243         aDes = target;
       
   244         CleanupStack::Pop( target );
       
   245         }
       
   246     else
       
   247         {
       
   248         delete aDes;
       
   249         aDes = KNullDesC8().AllocL();
       
   250         }
       
   251     return length;
       
   252     }