omadm/omadmextensions/adapters/fota/src/nsmldmfotaadapter.cpp
changeset 0 3ce708148e4d
child 19 f2fc39bc30a5
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2004 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:    DM Fota Adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <implementationproxy.h> // For TImplementationProxy definition
       
    23 //#ifdef RD_OMADMAPPUI_UI_EVOLUTION
       
    24 #include <DevManInternalCRKeys.h>
       
    25 //#endif
       
    26 #include <SyncMLClient.h>
       
    27 #include <SyncMLClientDM.h>
       
    28 #include <e32property.h>
       
    29 #include <centralrepository.h>
       
    30 #include "fotaadapterCRKeys.h"
       
    31 #include "NSmlPrivateAPI.h"
       
    32 #include "nsmldmimpluids.h"
       
    33 #include "nsmldmfotaadapter.h"
       
    34 #include "nsmldmconst.h"
       
    35 #include "nsmldebug.h"
       
    36 
       
    37 #include "nsmldmtreedbclient.h"
       
    38 
       
    39 
       
    40 // =========================== MEMBER FUNCTIONS ==============================
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CNSmlDmFotaAdapter* CNSmlDmFotaAdapter::NewL()
       
    44 // Creates new instance of CNSmlDmFotaEngine and returns a pointer to it.
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CNSmlDmFotaAdapter* CNSmlDmFotaAdapter::NewL( MSmlDmCallback* aDmCallback )
       
    48     {
       
    49     _DBG_FILE("CNSmlDmFotaAdapter::NewL(): begin");
       
    50     CNSmlDmFotaAdapter* self = NewLC( aDmCallback );
       
    51     CleanupStack::Pop( self );
       
    52     _DBG_FILE("CNSmlDmFotaAdapter::NewL(): end");
       
    53     return self;
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CNSmlDmFotaAdapter* CNSmlDmFotaAdapter::NewLC()
       
    58 // Creates new instance of CNSmlDmFotaEngine and returns a pointer to it. 
       
    59 // Leaves the pointer onto the CleanupStack.
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CNSmlDmFotaAdapter* CNSmlDmFotaAdapter::NewLC( MSmlDmCallback* aDmCallback )
       
    63     {
       
    64     _DBG_FILE("CNSmlDmFotaAdapter::NewLC(): begin");
       
    65     CNSmlDmFotaAdapter* self = new (ELeave) CNSmlDmFotaAdapter( aDmCallback );
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL();
       
    68     _DBG_FILE("CNSmlDmFotaAdapter::NewLC(): end");
       
    69     return self;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CNSmlDmFotaAdapter::CNSmlDmFotaAdapter()
       
    74 // Constructor.
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CNSmlDmFotaAdapter::CNSmlDmFotaAdapter( TAny* aEcomArguments )
       
    78     : CSmlDmAdapter( aEcomArguments ), iPkgId( KNSmlDMFotaNullPkgId )
       
    79     {
       
    80     _DBG_FILE("CNSmlDmFotaAdapter::CNSmlDmFotaAdapter(): begin");
       
    81     _DBG_FILE("CNSmlDmFotaAdapter::CNSmlDmFotaAdapter(): end");
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CNSmlDmFotaAdapter::ConstructL()
       
    86 // Second phase construction.
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CNSmlDmFotaAdapter::ConstructL()
       
    90     {
       
    91     // Check if Fota feature is defined
       
    92     TInt value( 0 );
       
    93     CRepository * rep = CRepository::NewLC( KCRUidFotaAdapter );
       
    94 	TInt err = rep->Get( KCRFotaAdapterEnabled, value );
       
    95 	CleanupStack::PopAndDestroy( rep );
       
    96 	
       
    97 	if ( err != KErrNone || value == 0 )
       
    98     	{
       
    99     	User::Leave( KErrNotSupported );
       
   100     	}    
       
   101     	
       
   102     iFotaEngine.OpenL();
       
   103     iFotaDb = CNSmlDmFotaAdapterDb::NewL();
       
   104     }
       
   105     
       
   106 // ---------------------------------------------------------------------------
       
   107 // CNSmlDmFotaAdapter::~CNSmlDmFotaAdapter()
       
   108 // Destructor.
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 CNSmlDmFotaAdapter::~CNSmlDmFotaAdapter()
       
   112     {
       
   113     _DBG_FILE("CNSmlDmFotaAdapter::~CNSmlDmFotaAdapter(): begin");
       
   114 
       
   115     iFotaEngine.Close();
       
   116 
       
   117     delete iFotaDb;
       
   118 
       
   119     _DBG_FILE("CNSmlDmFotaAdapter::~CNSmlDmFotaAdapter(): end");
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 //  CNSmlDmFotaAdapter::DDFVersionL()
       
   124 //  Returns the DDF version of the adapter.
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 void CNSmlDmFotaAdapter::DDFVersionL( CBufBase& aDDFVersion )
       
   128     {
       
   129     _DBG_FILE("CNSmlDmFotaAdapter::DDFVersionL(TDes& aDDFVersion): begin");
       
   130 
       
   131     aDDFVersion.InsertL( 0, KNSmlDMFotaDDFVersion );
       
   132 
       
   133     _DBG_FILE("CNSmlDmFotaAdapter::DDFVersionL(TDes& aDDFVersion): end");
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 //  CNSmlDmFotaAdapter::DDFStructureL()
       
   138 //  Builds the DDF structure of adapter.
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CNSmlDmFotaAdapter::DDFStructureL( MSmlDmDDFObject& aDDF )
       
   142     {
       
   143     _DBG_FILE("CNSmlDmFotaAdapter::DDFStructureL(): begin");
       
   144 
       
   145     TSmlDmAccessTypes accessTypes;
       
   146     
       
   147     // fota root
       
   148     MSmlDmDDFObject& FUMO = aDDF.AddChildObjectL( KNSmlDMFotaNode );
       
   149     accessTypes.SetAdd();
       
   150     accessTypes.SetGet();
       
   151     FillNodeInfoL(  FUMO, 
       
   152                     accessTypes,
       
   153                     MSmlDmDDFObject::EOne,
       
   154                     MSmlDmDDFObject::EPermanent,
       
   155                     MSmlDmDDFObject::ENode,
       
   156                     KNSmlDMFotaNodeDescription );
       
   157 
       
   158     accessTypes.Reset();
       
   159 
       
   160     // run time node <X>
       
   161     MSmlDmDDFObject& rtPkg = FUMO.AddChildObjectGroupL();
       
   162     rtPkg.AddDFTypeMimeTypeL( KNSmlDMFotaRunTimeMimeType );
       
   163     accessTypes.SetAdd();
       
   164     accessTypes.SetDelete();
       
   165     accessTypes.SetGet();
       
   166     //accessTypes.SetReplace();
       
   167     FillNodeInfoL(  rtPkg, 
       
   168                     accessTypes,
       
   169                     MSmlDmDDFObject::EZeroOrMore, 
       
   170                     MSmlDmDDFObject::EDynamic, 
       
   171                     MSmlDmDDFObject::ENode, 
       
   172                     KNSmlDMFotaRunTimeNodeDescription );
       
   173 
       
   174     accessTypes.Reset();
       
   175 
       
   176     // <X>/PkgName
       
   177     MSmlDmDDFObject& name = rtPkg.AddChildObjectL( KNSmlDMFotaNodeName );
       
   178     accessTypes.SetAdd();
       
   179     accessTypes.SetGet();
       
   180     accessTypes.SetReplace();
       
   181     FillNodeInfoL(  name,
       
   182                     accessTypes,
       
   183                     MSmlDmDDFObject::EZeroOrOne,
       
   184                     MSmlDmDDFObject::EDynamic,
       
   185                     MSmlDmDDFObject::EChr,
       
   186                     KNSmlDMFotaNodeNameDescription );
       
   187 
       
   188     // <X>/PkgVersion
       
   189     MSmlDmDDFObject& version = rtPkg.AddChildObjectL( KNSmlDMFotaNodeVersion );
       
   190     FillNodeInfoL(  version,
       
   191                     accessTypes,
       
   192                     MSmlDmDDFObject::EZeroOrOne,
       
   193                     MSmlDmDDFObject::EDynamic,
       
   194                     MSmlDmDDFObject::EChr,
       
   195                     KNSmlDMFotaNodeVersionDescription );
       
   196 
       
   197     accessTypes.Reset();
       
   198 
       
   199     // <X>/Download
       
   200     MSmlDmDDFObject& download = 
       
   201     rtPkg.AddChildObjectL( KNSmlDMFotaNodeDownload );
       
   202 
       
   203     accessTypes.SetGet();
       
   204     accessTypes.SetExec();
       
   205     FillNodeInfoL(  download,
       
   206                     accessTypes,
       
   207                     MSmlDmDDFObject::EZeroOrOne,
       
   208                     MSmlDmDDFObject::EDynamic,
       
   209                     MSmlDmDDFObject::ENode,
       
   210                     KNSmlDMFotaNodeDownloadDescription );
       
   211 
       
   212     accessTypes.Reset();
       
   213 
       
   214     // <X>/Download/PkgURL
       
   215     MSmlDmDDFObject& dlUrl = 
       
   216     download.AddChildObjectL( KNSmlDMFotaNodeDownloadUrl );
       
   217 
       
   218     accessTypes.SetGet();
       
   219     accessTypes.SetReplace();
       
   220     FillNodeInfoL(  dlUrl,
       
   221                     accessTypes,
       
   222                     MSmlDmDDFObject::EOne,
       
   223                     MSmlDmDDFObject::EDynamic,
       
   224                     MSmlDmDDFObject::EChr,
       
   225                     KNSmlDMFotaNodeDownloadUrlDescription );
       
   226 
       
   227     accessTypes.Reset();
       
   228 
       
   229     // <X>/Update
       
   230     MSmlDmDDFObject& update = rtPkg.AddChildObjectL( KNSmlDMFotaNodeUpdate );
       
   231     accessTypes.SetGet();
       
   232     accessTypes.SetExec();
       
   233     FillNodeInfoL(  update,
       
   234                     accessTypes,
       
   235                     MSmlDmDDFObject::EZeroOrOne,
       
   236                     MSmlDmDDFObject::EDynamic,
       
   237                     MSmlDmDDFObject::ENode,
       
   238                     KNSmlDMFotaNodeUpdateDescription );
       
   239 
       
   240     accessTypes.Reset();
       
   241 
       
   242     // <X>/Update/PkgData
       
   243     MSmlDmDDFObject& data = 
       
   244     update.AddChildObjectL( KNSmlDMFotaNodeUpdateData );
       
   245 
       
   246     accessTypes.SetReplace();
       
   247     FillNodeInfoL(  data,
       
   248                     accessTypes,
       
   249                     MSmlDmDDFObject::EZeroOrOne,
       
   250                     MSmlDmDDFObject::EDynamic,
       
   251                     MSmlDmDDFObject::EBin,
       
   252                     KNSmlDMFotaNodeUpdateDataDescription );
       
   253 
       
   254     accessTypes.Reset();
       
   255 
       
   256     // <X>/DownloadAndUpdate
       
   257     MSmlDmDDFObject& dlAndUpdate = 
       
   258     rtPkg.AddChildObjectL( KNSmlDMFotaNodeDownloadAndUpdate );
       
   259 
       
   260     accessTypes.SetGet();
       
   261     accessTypes.SetExec();
       
   262     FillNodeInfoL(  dlAndUpdate,
       
   263                     accessTypes,
       
   264                     MSmlDmDDFObject::EZeroOrOne,
       
   265                     MSmlDmDDFObject::EDynamic,
       
   266                     MSmlDmDDFObject::ENode,
       
   267                     KNSmlDMFotaNodeDownloadAndUpdateDescription );
       
   268 
       
   269     accessTypes.Reset();
       
   270 
       
   271     // <X>/DownloadAndUpdate/PkgURL
       
   272     MSmlDmDDFObject& dlAndUpdateUrl = 
       
   273     dlAndUpdate.AddChildObjectL( KNSmlDMFotaNodeDownloadAndUpdateUrl );
       
   274 
       
   275     accessTypes.SetGet();
       
   276     accessTypes.SetReplace();
       
   277     FillNodeInfoL(  dlAndUpdateUrl,
       
   278                     accessTypes,
       
   279                     MSmlDmDDFObject::EOne,
       
   280                     MSmlDmDDFObject::EDynamic,
       
   281                     MSmlDmDDFObject::EChr,
       
   282                     KNSmlDMFotaNodeDownloadAndUpdateUrlDescription );
       
   283 
       
   284     accessTypes.Reset();
       
   285 
       
   286     // <X>/State
       
   287     MSmlDmDDFObject& state = rtPkg.AddChildObjectL( KNSmlDMFotaNodeState );
       
   288     accessTypes.SetGet();
       
   289     FillNodeInfoL(  state,
       
   290                     accessTypes,
       
   291                     MSmlDmDDFObject::EOne,
       
   292                     MSmlDmDDFObject::EDynamic,
       
   293                     MSmlDmDDFObject::EInt,
       
   294                     KNSmlDMFotaNodeStateDescription );
       
   295 
       
   296     
       
   297     
       
   298     //Check cenrep for predefined node and add if its not in DB
       
   299     CheckAndAddPredefinedNodeL();
       
   300     
       
   301     // check if there is need to make generic alert(s), 
       
   302     // and generate them if there are
       
   303     MakeGenericAlertsL();
       
   304 
       
   305 
       
   306     // Set ACL for fota root, if not yet set
       
   307     RNSmlDMCallbackSession session;
       
   308     User::LeaveIfError( session.Connect() );
       
   309     CleanupClosePushL(session);
       
   310 
       
   311     CBufBase* acl=CBufFlat::NewL(10);
       
   312     CleanupStack::PushL( acl );
       
   313     session.GetAclL( KNSmlDMFotaNode,*acl,EFalse );
       
   314 
       
   315     if( acl->Size() == 0 )
       
   316         {
       
   317         _LIT8(KACLForAll, "Add=*&Get=*&Delete=*&Exec=*&Replace=*");
       
   318         session.UpdateAclL( KNSmlDMFotaNode, KACLForAll);
       
   319         }
       
   320     CleanupStack::PopAndDestroy( acl );
       
   321     CleanupStack::PopAndDestroy( &session );
       
   322 
       
   323     _DBG_FILE("CNSmlDmFotaAdapter::DDFStructureL(): end");
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // CNSmlDmFotaAdapter::UpdateLeafObjectL()
       
   328 // Updates value of leaf object.
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 void CNSmlDmFotaAdapter::UpdateLeafObjectL( const TDesC8& aURI, 
       
   332                                             const TDesC8& aLUID, 
       
   333                                             const TDesC8& aObject, 
       
   334                                             const TDesC8& /*aType*/, 
       
   335                                             const TInt aStatusRef )
       
   336     {
       
   337     _DBG_FILE("CNSmlDmFotaAdapter::UpdateLeafObjectL(): begin");
       
   338     
       
   339     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
   340     
       
   341     if ( aLUID.Length() > 0 )
       
   342         {
       
   343         TInt res = KErrNotFound;
       
   344         TNSmlDmFwObjectId id = DesToInt( aLUID );
       
   345         
       
   346         TPtrC8 lastSeg = LastURISeg( aURI );
       
   347         if ( lastSeg == KNSmlDMFotaNodeName )
       
   348             {
       
   349             res = iFotaDb->SetPkgNameL( aObject, id );
       
   350             }
       
   351         else if ( lastSeg == KNSmlDMFotaNodeVersion )
       
   352             {
       
   353             res = iFotaDb->SetPkgVersionL( aObject, id );
       
   354             }
       
   355         else if ( lastSeg == KNSmlDMFotaNodeDownloadUrl || 
       
   356                   lastSeg == KNSmlDMFotaNodeDownloadAndUpdateUrl )
       
   357             {
       
   358             TInt configFlags( KErrNone );        
       
   359             CRepository* centrep = NULL;
       
   360             TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys ) );    	
       
   361             if ( err == KErrNone && centrep ) 
       
   362                 {
       
   363                 configFlags = 2; //means fota operation
       
   364                 centrep->Set( KDevManSessionType, configFlags );
       
   365                 delete centrep;
       
   366                 centrep = NULL;
       
   367                 }
       
   368             else
       
   369                 {
       
   370                 User::Leave( err );
       
   371                 }
       
   372             res = iFotaDb->SetPkgUrlL( aObject, id );
       
   373             }
       
   374         else if ( lastSeg == KNSmlDMFotaNodeUpdateData )
       
   375             {
       
   376             // check if there is space for this data
       
   377             if ( iFotaEngine.IsPackageStoreSizeAvailable( aObject.Size() ) )
       
   378                 {
       
   379                 // get stream from Fota Engine
       
   380                 RWriteStream* stream = NULL;
       
   381                 TInt err = iFotaEngine.OpenUpdatePackageStore( id, stream );
       
   382                 
       
   383                 if ( ( err == KErrNone ) && stream )
       
   384                     {
       
   385                     // stream was opened successfully, write data 
       
   386                     // and close stream
       
   387                     stream->WriteL( aObject );
       
   388                     stream->Close();
       
   389                     
       
   390                     // inform fota engine that data has been written
       
   391                     iFotaEngine.UpdatePackageDownloadComplete( id );
       
   392                     
       
   393                     res = KErrNone;
       
   394                     }
       
   395                 else
       
   396                     {
       
   397                     // error occured
       
   398                     res = KErrGeneral;
       
   399                     }
       
   400                 }
       
   401             else
       
   402                 {
       
   403                 // there was no space for the data
       
   404                 res = KErrDiskFull;
       
   405                 }
       
   406             }
       
   407         
       
   408         // map error
       
   409         status = MapErrorToStatus( res );
       
   410         }
       
   411     else
       
   412         {
       
   413         // cannot update, object unknown
       
   414         status = CSmlDmAdapter::ENotFound;
       
   415         }
       
   416     
       
   417     Callback().SetStatusL( aStatusRef, status );
       
   418     
       
   419     _DBG_FILE("CNSmlDmFotaAdapter::UpdateLeafObjectL(): end");
       
   420     }
       
   421     
       
   422 // ---------------------------------------------------------------------------
       
   423 // CNSmlDmFotaAdapter::DeleteObjectL()
       
   424 // Deletes a firmware object from Fota database.
       
   425 // ---------------------------------------------------------------------------
       
   426 //
       
   427 void CNSmlDmFotaAdapter::DeleteObjectL( const TDesC8& aURI, 
       
   428                                         const TDesC8& aLUID, 
       
   429                                         const TInt aStatusRef )
       
   430     {
       
   431     _DBG_FILE("CNSmlDmFotaAdapter::DeleteLeafObjectL( ): begin");
       
   432     
       
   433     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
   434     
       
   435     if ( ( aURI.Match( KNSmlDMFotaRuntimeMatch ) != KErrNotFound ) && 
       
   436          ( aLUID.Length() > 0 ) )
       
   437         {
       
   438 		TBuf8<KMaxFullName> temp;
       
   439 		GetPredefinedNodeL(temp);
       
   440 		TBuf8<KMaxName> node[4];
       
   441     	TInt location = temp.LocateReverse(',');
       
   442     	node[0].Copy(temp.Mid(location+1));
       
   443     	TInt newLocation = (temp.Left(location-1)).LocateReverse(',');
       
   444     	node[1].Copy(temp.Mid(newLocation+1,location-(newLocation+1)));
       
   445     	location = newLocation;
       
   446     	newLocation = (temp.Left(location-1)).LocateReverse(',');
       
   447     	node[2].Copy(temp.Mid(newLocation+1,location-(newLocation+1)));
       
   448     	node[3].Copy(temp.Mid(0,newLocation ));
       
   449     	for(TInt i =0 ; i<4; i++)
       
   450     	{    		
       
   451     		if (node[i].Length() && aURI.Find( node[i] ) != KErrNotFound)
       
   452             {
       
   453             status = CSmlDmAdapter::ENotAllowed;
       
   454             Callback().SetStatusL( aStatusRef, status );
       
   455             return;
       
   456             }
       
   457     	}
       
   458         // delete object identified by aLUID
       
   459         TNSmlDmFwObjectId id = DesToInt( aLUID );
       
   460         TInt res = iFotaDb->DeleteFwObjectL( id );
       
   461 
       
   462         if ( res == KErrNone )
       
   463             {
       
   464             // deletion was successful, delete also from Fota Engine
       
   465             iFotaEngine.DeleteUpdatePackage( id );
       
   466             }
       
   467         else
       
   468             {
       
   469             status = MapErrorToStatus( res );
       
   470             }
       
   471         }
       
   472     else
       
   473         {
       
   474         // object unknown
       
   475         status = CSmlDmAdapter::ENotFound;
       
   476         }
       
   477     
       
   478     Callback().SetStatusL( aStatusRef, status );
       
   479     
       
   480     _DBG_FILE("CNSmlDmFotaAdapter::DeleteLeafObjectL( ): end");
       
   481     }
       
   482     
       
   483 // ---------------------------------------------------------------------------
       
   484 //  CNSmlDmFotaAdapter::FetchLeafObjectL()
       
   485 //  Fetches the values of leaf objects.
       
   486 // ---------------------------------------------------------------------------
       
   487 //
       
   488 void CNSmlDmFotaAdapter::FetchLeafObjectL( const TDesC8& aURI, 
       
   489                                            const TDesC8& aLUID,
       
   490                                            const TDesC8& aType,
       
   491                                            const TInt aResultsRef,
       
   492                                            const TInt aStatusRef )
       
   493     {
       
   494     _DBG_FILE("CNSmlDmFotaAdapter::FetchLeafObjectL(): begin");
       
   495     // buffer for result
       
   496     CBufBase* result = CBufFlat::NewL( KNSmlDMFotaResultBufferExpandSize );
       
   497     CleanupStack::PushL( result );
       
   498     
       
   499     // fetch data
       
   500     CSmlDmAdapter::TError status = DoFetchObjectL( aURI, aLUID, *result );
       
   501     if ( status == CSmlDmAdapter::EOk )
       
   502         {
       
   503         Callback().SetResultsL( aResultsRef, *result, aType );
       
   504         }
       
   505     
       
   506     CleanupStack::PopAndDestroy( result );
       
   507     
       
   508     Callback().SetStatusL( aStatusRef, status );
       
   509     
       
   510     _DBG_FILE("CNSmlDmFotaAdapter::FetchLeafObjectL(): end");
       
   511     }
       
   512 
       
   513 // ---------------------------------------------------------------------------
       
   514 //  CNSmlDmFotaAdapter::ChildURIListL()
       
   515 //  Returns the list of children of a node.
       
   516 // ---------------------------------------------------------------------------
       
   517 //
       
   518 void CNSmlDmFotaAdapter::ChildURIListL( const TDesC8& aURI,
       
   519                                         const TDesC8& aLUID, 
       
   520                                         const CArrayFix<TSmlDmMappingInfo>& aPreviousURISegmentList, 
       
   521                                         const TInt aResultsRef, 
       
   522                                         const TInt aStatusRef )
       
   523     {
       
   524     _DBG_FILE("CNSmlDmFotaAdapter::ChildURIListL(): begin");
       
   525 
       
   526     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
   527     TPtrC8 mimeType( KNullDesC8 );
       
   528     
       
   529     // buffer for result
       
   530     CBufBase* result = CBufFlat::NewL( KNSmlDMFotaResultBufferExpandSize );
       
   531     CleanupStack::PushL( result );
       
   532     
       
   533     TPtrC8 lastSeg = LastURISeg( aURI );
       
   534     if ( lastSeg == KNSmlDMFotaNodeDownload && aLUID.Length() > 0 )
       
   535         {
       
   536         // target is ./FUMO/<x>/Download
       
   537         result->InsertL( 0, KNSmlDMFotaNodeDownloadUrl );
       
   538         }
       
   539     else if ( lastSeg == KNSmlDMFotaNodeUpdate && aLUID.Length() > 0 )
       
   540         {
       
   541         // target is ./FUMO/<x>/Update
       
   542         result->InsertL( 0, KNSmlDMFotaNodeUpdateData );
       
   543         }
       
   544     else if ( lastSeg == KNSmlDMFotaNodeDownloadAndUpdate && aLUID.Length() > 0 )
       
   545         {
       
   546         // target is ./FUMO/<x>/DownloadAndUpdate
       
   547         result->InsertL( 0, KNSmlDMFotaNodeDownloadAndUpdateUrl );
       
   548         }
       
   549     else if ( ( aURI.Match( KNSmlDMFotaRuntimeMatch ) != KErrNotFound ) 
       
   550         && ( TableExistsL( aLUID ) ) )
       
   551         {
       
   552         // target is ./FUMO/<x>
       
   553         result->InsertL( 0, KNSmlDMFotaRunTimeChildren );
       
   554         mimeType.Set( KNSmlDMFotaRunTimeMimeType );
       
   555         }
       
   556     else if ( aURI.Match( KNSmlDMFotaRootMatch ) != KErrNotFound )
       
   557         {
       
   558         // target is ./FUMO
       
   559         
       
   560         // return the children listed in aPreviousURISegmentList
       
   561         TInt childCount = aPreviousURISegmentList.Count();
       
   562         for ( TInt i = 0; i < childCount - 1; ++i )
       
   563             {
       
   564             result->InsertL( result->Size(), aPreviousURISegmentList[i].iURISeg );
       
   565             result->InsertL( result->Size(), KNSmlDMFotaSeparatorDes );
       
   566             }
       
   567         
       
   568         if ( childCount )
       
   569             {
       
   570             // insert last child without separator
       
   571             result->InsertL( result->Size(), 
       
   572                 aPreviousURISegmentList[ childCount - 1 ].iURISeg );
       
   573             }
       
   574         
       
   575         }
       
   576     else
       
   577         {
       
   578         // invalid target
       
   579         status = CSmlDmAdapter::ENotFound;
       
   580         }
       
   581     
       
   582     // set result, if it was found
       
   583     if ( status == CSmlDmAdapter::EOk )
       
   584         {
       
   585         Callback().SetResultsL( aResultsRef, *result, mimeType );
       
   586         }
       
   587     
       
   588     Callback().SetStatusL( aStatusRef, status );
       
   589     
       
   590     CleanupStack::PopAndDestroy( result );
       
   591     
       
   592     _DBG_FILE("CNSmlDmFotaAdapter::ChildURIListL(): end");
       
   593     }
       
   594     
       
   595 
       
   596 
       
   597 // ---------------------------------------------------------------------------
       
   598 // CNSmlDmFotaAdapter::TableExistsL(const TDesC8& aLUID) const
       
   599 // Checks if table exists
       
   600 // ---------------------------------------------------------------------------
       
   601 //
       
   602 TBool CNSmlDmFotaAdapter::TableExistsL(const TDesC8& aLUID) const
       
   603     {
       
   604     TBool ret = EFalse;
       
   605     if(aLUID.Length()>0)
       
   606         {
       
   607         TNSmlDmFwObjectId luid = DesToInt( aLUID );
       
   608         TSmlProfileId profileId = iFotaDb->ProfileIdL(luid);
       
   609         if (profileId!=KErrNotFound)
       
   610             {
       
   611             ret = ETrue;
       
   612             }
       
   613         }
       
   614     return ret;
       
   615     }
       
   616 
       
   617 //
       
   618 // ---------------------------------------------------------------------------
       
   619 // CNSmlDmFotaAdapter::AddNodeObjectL()
       
   620 // Adds new row to firmware object table in Fota database.
       
   621 // ---------------------------------------------------------------------------
       
   622 //
       
   623 void CNSmlDmFotaAdapter::AddNodeObjectL( const TDesC8& aURI, 
       
   624                                          const TDesC8& aParentLUID, 
       
   625                                          const TInt aStatusRef )
       
   626     {
       
   627     _DBG_FILE("CNSmlDmFotaAdapter::AddNodeObjectL(): begin");
       
   628     
       
   629     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
   630     
       
   631      // Luid specified and it's a valid luid => already exists
       
   632     if ( TableExistsL( aParentLUID ) )
       
   633         {
       
   634         // the object has already been created and mapping set to DM Framework
       
   635         status = CSmlDmAdapter::EAlreadyExists;
       
   636         }
       
   637     else if ( aURI.Match( KNSmlDMFotaRuntimeMatch ) != KErrNotFound )
       
   638         {
       
   639         // add new FW object to db
       
   640         TNSmlDmFwObjectId newId = KErrNotFound;
       
   641         TRAPD( err, newId = iFotaDb->AddFwObjectL() );
       
   642         
       
   643         if ( err == KErrNone )
       
   644             {
       
   645             // added ok
       
   646             TBuf8<KNSmlFwMgmtObjectIntegerLength> newLUID;
       
   647             newLUID.AppendNum( newId );
       
   648             
       
   649             Callback().SetMappingL( aURI, newLUID );
       
   650             }
       
   651         else
       
   652             {
       
   653             status = MapErrorToStatus( err );
       
   654             }
       
   655         
       
   656         }
       
   657     else
       
   658         {
       
   659         // error, invalid uri
       
   660         status = CSmlDmAdapter::ENotFound;
       
   661         }
       
   662     
       
   663     Callback().SetStatusL( aStatusRef, status );
       
   664 //    if(status==CSmlDmAdapter::EOk)
       
   665 //        {
       
   666 //        TSmlProfileId profId = KErrNotFound;
       
   667 //        HBufC8* serverId = NULL;
       
   668 //        
       
   669 //        GetServerInfoL( profId, serverId );
       
   670 //        
       
   671 //        if(serverId)
       
   672 //            {
       
   673 //            CleanupStack::PushL( serverId );
       
   674 //            
       
   675 //            _LIT( KFotaAclAdd, "Add=");
       
   676 //            _LIT( KFotaAclGet, "Get=");
       
   677 //            _LIT( KFotaAclReplace, "Replace=");
       
   678 //            _LIT( KFotaAclDelete, "Delete=");
       
   679 //            _LIT( KFotaAclExec, "Exec=");
       
   680 //            _LIT( KFotaAclSeparator, "&");
       
   681 //            _LIT( KFotaAclForAll, "*");
       
   682 //            
       
   683 //            const TUint length = KFotaAclAdd().Length() +
       
   684 //                                 KFotaAclGet().Length() +
       
   685 //                                 KFotaAclReplace().Length() +
       
   686 //                                 KFotaAclDelete().Length() +
       
   687 //                                 KFotaAclExec().Length() +
       
   688 //                                 serverId->Length()*4 +
       
   689 //                                 5; /* 4*'&'+ ''*' */
       
   690 //                                 
       
   691 //            HBufC8* acl = HBufC8::NewLC(length);
       
   692 //            TPtr8 acltPtr = acl->Des();
       
   693 //            acltPtr.Append(KFotaAclAdd);
       
   694 //            acltPtr.Append(*serverId);
       
   695 //            acltPtr.Append(KFotaAclSeparator);
       
   696 //
       
   697 //            acltPtr.Append(KFotaAclGet);
       
   698 //            acltPtr.Append(*serverId);
       
   699 //            acltPtr.Append(KFotaAclSeparator);
       
   700 //
       
   701 //            acltPtr.Append(KFotaAclReplace);
       
   702 //            acltPtr.Append(*serverId);
       
   703 //            acltPtr.Append(KFotaAclSeparator);
       
   704 //
       
   705 //            acltPtr.Append(KFotaAclDelete);
       
   706 //            acltPtr.Append(KFotaAclForAll);
       
   707 //            acltPtr.Append(KFotaAclSeparator);
       
   708 //
       
   709 //            acltPtr.Append(KFotaAclExec);
       
   710 //            acltPtr.Append(*serverId);
       
   711 //            
       
   712 //            RNSmlDMCallbackSession session;
       
   713 //            User::LeaveIfError( session.Connect() );
       
   714 //            CleanupClosePushL(session);
       
   715 //            session.UpdateAclL(aURI,*acl);
       
   716 //            CleanupStack::PopAndDestroy( &session );
       
   717 //            CleanupStack::PopAndDestroy( acl );
       
   718 //            CleanupStack::PopAndDestroy( serverId );
       
   719 //            }
       
   720 //        }
       
   721     
       
   722     _DBG_FILE("CNSmlDmFotaAdapter::AddNodeObjectL(): end");
       
   723     }
       
   724     
       
   725 // ---------------------------------------------------------------------------
       
   726 // CNSmlDmFotaAdapter::UpdateLeafObjectL()
       
   727 // Updates a leaf object using streaming. In Fota adapter this method is used 
       
   728 // only to update PkgData of a firmware object.
       
   729 // ---------------------------------------------------------------------------
       
   730 //
       
   731 void CNSmlDmFotaAdapter::UpdateLeafObjectL( const TDesC8& aURI, 
       
   732                                             const TDesC8& aLUID, 
       
   733                                             RWriteStream*& aStream, 
       
   734                                             const TDesC8& /*aType*/, 
       
   735                                             const TInt aStatusRef )
       
   736     {
       
   737     _DBG_FILE("CNSmlDmFotaAdapter::UpdateLeafObjectL(stream): begin");
       
   738     
       
   739     CSmlDmAdapter::TError status = CSmlDmAdapter::ENotFound;
       
   740     
       
   741     if ( aLUID.Length() > 0 )
       
   742         {
       
   743         TNSmlDmFwObjectId id = DesToInt( aLUID );
       
   744         
       
   745         TPtrC8 lastSeg = LastURISeg( aURI );
       
   746         if ( lastSeg == KNSmlDMFotaNodeUpdateData )
       
   747             {
       
   748             // set final result to undefined error in db (in case an 
       
   749             // error occures during large object download)
       
   750             TInt res = iFotaDb->SetFinalResultL( KNSmlDMFotaUndefinedError, id );
       
   751             
       
   752             if ( res == KErrNone )
       
   753                 {
       
   754                 // save the id so that it is known when stream is committed
       
   755                 iPkgId = id;
       
   756             
       
   757                 // open stream and give it to DM Host Server
       
   758                 TInt err = iFotaEngine.OpenUpdatePackageStore( id, aStream );
       
   759                 
       
   760                 if ( err == KErrNone )
       
   761                     {
       
   762                     // stream was opened successfully
       
   763                     status = CSmlDmAdapter::EOk;
       
   764                 	User::LeaveIfError(iFotaDb->SetFinalResultL( KNSmlFotaNullResult, id ));
       
   765                 	User::LeaveIfError( iFotaDb->SetMgmtUriL( aURI, id ) );
       
   766                 	// fetch profile id and server id of the currently running dm session
       
   767                 	TSmlProfileId profId = KErrNotFound;
       
   768                 	HBufC8* serverId = NULL;                    
       
   769                 	GetServerInfoL( profId, serverId );
       
   770                 	CleanupStack::PushL( serverId );                    
       
   771                 	// save profile id and server id to fota db
       
   772                 	User::LeaveIfError( iFotaDb->SetServerInfoL( profId, *serverId, id ) );
       
   773                 	DBG_FILE_CODE(profId, _S8("UpdateLeafObjectL profile id is"));
       
   774                 	//Set ProfId & PkgId
       
   775                 	err = RProperty::Set(TUid::Uid(KFotaServerUid),KFotaLrgObjDl,1);
       
   776                 	DBG_FILE_CODE(err, _S8("UpdateLeafObjectL set P&S key KFotaLrgObjDl to 1"));
       
   777                 	err = RProperty::Set(TUid::Uid(KFotaServerUid),KFotaLrgObjProfileId,profId);
       
   778                 	DBG_FILE_CODE(err, _S8("UpdateLeafObjectL set P&S key profile id err is"));                	
       
   779                 	CleanupStack::PopAndDestroy( serverId );
       
   780                     }
       
   781                 else
       
   782                     {
       
   783                     // error occured
       
   784                     aStream = NULL;
       
   785                     status = CSmlDmAdapter::EError;
       
   786                     }
       
   787                 }
       
   788             }
       
   789         }
       
   790         
       
   791     Callback().SetStatusL( aStatusRef, status );
       
   792     
       
   793     _DBG_FILE("CNSmlDmFotaAdapter::UpdateLeafObjectL(stream): end");
       
   794     }
       
   795 
       
   796 // ---------------------------------------------------------------------------
       
   797 // void CNSmlDmFotaAdapter::FetchLeafObjectSizeL()
       
   798 // Fetches data object and returns its size.
       
   799 // ---------------------------------------------------------------------------
       
   800 //
       
   801 void CNSmlDmFotaAdapter::FetchLeafObjectSizeL( const TDesC8& aURI, 
       
   802                                                const TDesC8& aLUID, 
       
   803                                                const TDesC8& aType, 
       
   804                                                const TInt aResultsRef, 
       
   805                                                const TInt aStatusRef )
       
   806     {
       
   807     _DBG_FILE("CNSmlDmFotaAdapter::FetchLeafObjectSizeL(): begin");
       
   808     
       
   809     // buffer for result
       
   810     CBufBase* result = CBufFlat::NewL( KNSmlDMFotaResultBufferExpandSize );
       
   811     CleanupStack::PushL( result );
       
   812     
       
   813     // fetch data
       
   814     CSmlDmAdapter::TError status = DoFetchObjectL( aURI, aLUID, *result );
       
   815     if ( status == CSmlDmAdapter::EOk )
       
   816         {
       
   817         // get size and form a string representation
       
   818         TInt size = result->Size();
       
   819         TBuf8<KNSmlFwMgmtObjectIntegerLength> sizeStr;
       
   820         sizeStr.AppendNum( size );
       
   821         
       
   822         // insert size to result
       
   823         result->Reset();
       
   824         result->InsertL( 0, sizeStr );
       
   825         
       
   826         Callback().SetResultsL( aResultsRef, *result, aType );
       
   827         }
       
   828     
       
   829     CleanupStack::PopAndDestroy( result );
       
   830     
       
   831     Callback().SetStatusL( aStatusRef, status );
       
   832     
       
   833     _DBG_FILE("CNSmlDmFotaAdapter::FetchLeafObjectSizeL(): end");
       
   834     }
       
   835 
       
   836 // ---------------------------------------------------------------------------
       
   837 // CNSmlDmFotaAdapter::ExecuteCommandL()
       
   838 // Executes Update, Download or DownloadAndUpdate command depending on aURI. 
       
   839 // If aURI does not match to any of these, ENotFound is set as status.
       
   840 // ---------------------------------------------------------------------------
       
   841 //
       
   842 void CNSmlDmFotaAdapter::ExecuteCommandL( const TDesC8& aURI, 
       
   843                                           const TDesC8& aLUID, 
       
   844                                           const TDesC8& aArgument, 
       
   845                                           const TDesC8& /*aType*/, 
       
   846                                           const TInt aStatusRef )
       
   847     {
       
   848     _DBG_FILE("CNSmlDmFotaAdapter::ExecuteCommandL(): begin");
       
   849     //#ifdef RD_OMADMAPPUI_UI_EVOLUTION
       
   850     TInt configFlags( 0 );        
       
   851     CRepository* centrep = NULL;
       
   852     TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys ) );
       
   853     if ( centrep )
       
   854         {
       
   855         centrep->Get( KDevManSessionType, configFlags );            
       
   856         }
       
   857     if ( err != KErrNone ) 
       
   858         {
       
   859         User::Leave( err );
       
   860         }
       
   861     else
       
   862         {
       
   863         configFlags = 1;
       
   864         centrep->Set( KDevManSessionType, configFlags );
       
   865         }
       
   866     if( centrep )    
       
   867        {
       
   868         delete centrep;
       
   869        }        
       
   870     //#endif   
       
   871     CSmlDmAdapter::TError status = CSmlDmAdapter::ENotFound;
       
   872     
       
   873     if ( aLUID.Length() > 0 )
       
   874         {
       
   875         TNSmlDmFwObjectId id = DesToInt( aLUID );
       
   876         
       
   877         // uri should target Update, Download or DownloadAndUpdate
       
   878         TPtrC8 lastSeg = LastURISeg( aURI );
       
   879         if ( lastSeg == KNSmlDMFotaNodeUpdate ||
       
   880              lastSeg == KNSmlDMFotaNodeDownload ||
       
   881              lastSeg == KNSmlDMFotaNodeDownloadAndUpdate )
       
   882             {
       
   883             
       
   884             // save information about the execution and get profile id of 
       
   885             // currently running DM session
       
   886             TSmlProfileId profId = 0;
       
   887             TRAPD( err, profId = SaveExecInfoL( aURI, id, aArgument ) );
       
   888             
       
   889             if ( err == KErrNone )
       
   890                 {
       
   891                 if ( lastSeg == KNSmlDMFotaNodeUpdate )
       
   892                     {
       
   893                     // update
       
   894                     status = DoExecUpdateL( id, profId );
       
   895                     }
       
   896                 else if ( lastSeg == KNSmlDMFotaNodeDownload )
       
   897                     {
       
   898                     // download
       
   899                     status = DoExecDownloadL( id, profId, EFalse );
       
   900                     }
       
   901                 else if ( lastSeg == KNSmlDMFotaNodeDownloadAndUpdate )
       
   902                     {
       
   903                     // download and update
       
   904                     status = DoExecDownloadL( id, profId, ETrue );
       
   905                     }
       
   906                 
       
   907                 }
       
   908             else
       
   909                 {
       
   910                 status = MapErrorToStatus( err );
       
   911                 }
       
   912             }
       
   913         
       
   914         }
       
   915     
       
   916     Callback().SetStatusL( aStatusRef, status );
       
   917     
       
   918     _DBG_FILE("CNSmlDmFotaAdapter::ExecuteCommandL(): end");
       
   919     }
       
   920 
       
   921 // ---------------------------------------------------------------------------
       
   922 // CNSmlDmFotaAdapter::ExecuteCommandL()
       
   923 // Not supported.
       
   924 // ---------------------------------------------------------------------------
       
   925 //
       
   926 void CNSmlDmFotaAdapter::ExecuteCommandL( const TDesC8& /*aURI*/, 
       
   927                                           const TDesC8& /*aLUID*/, 
       
   928                                           RWriteStream*& /*aStream*/, 
       
   929                                           const TDesC8& /*aType*/, 
       
   930                                           const TInt aStatusRef )
       
   931     {
       
   932     _DBG_FILE("CNSmlDmFotaAdapter::ExecuteCommandL(): begin");
       
   933     
       
   934     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   935     
       
   936     _DBG_FILE("CNSmlDmFotaAdapter::ExecuteCommandL(): end");
       
   937     }
       
   938 
       
   939 // ---------------------------------------------------------------------------
       
   940 // CNSmlDmFotaAdapter::CopyCommandL()
       
   941 // Not supported.
       
   942 // ---------------------------------------------------------------------------
       
   943 //
       
   944 void CNSmlDmFotaAdapter::CopyCommandL( const TDesC8& /*aTargetURI*/, 
       
   945                                        const TDesC8& /*aTargetLUID*/, 
       
   946                                        const TDesC8& /*aSourceURI*/,
       
   947                                        const TDesC8& /*aSourceLUID*/, 
       
   948                                        const TDesC8& /*aType*/, 
       
   949                                        TInt aStatusRef )
       
   950     {
       
   951     _DBG_FILE("CNSmlDmFotaAdapter::CopyCommandL(): begin");
       
   952     
       
   953     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   954     
       
   955     _DBG_FILE("CNSmlDmFotaAdapter::CopyCommandL(): end");
       
   956     }
       
   957 
       
   958 // ---------------------------------------------------------------------------
       
   959 // CNSmlDmFotaAdapter::StartAtomicL()
       
   960 // Not supported.
       
   961 // ---------------------------------------------------------------------------
       
   962 //
       
   963 void CNSmlDmFotaAdapter::StartAtomicL()
       
   964     {
       
   965     _DBG_FILE("CNSmlDmFotaAdapter::StartAtomicL(): begin");
       
   966     _DBG_FILE("CNSmlDmFotaAdapter::StartAtomicL(): end");
       
   967     }
       
   968 
       
   969 // ---------------------------------------------------------------------------
       
   970 // CNSmlDmFotaAdapter::CommitAtomicL()
       
   971 // Not supported.
       
   972 // ---------------------------------------------------------------------------
       
   973 //
       
   974 void CNSmlDmFotaAdapter::CommitAtomicL()
       
   975     {
       
   976     _DBG_FILE("CNSmlDmFotaAdapter::CommitAtomicL(): begin");
       
   977     _DBG_FILE("CNSmlDmFotaAdapter::CommitAtomicL(): end");
       
   978     }
       
   979 
       
   980 // ---------------------------------------------------------------------------
       
   981 // CNSmlDmFotaAdapter::RollbackAtomicL()
       
   982 // Not supported.
       
   983 // ---------------------------------------------------------------------------
       
   984 //
       
   985 void CNSmlDmFotaAdapter::RollbackAtomicL()
       
   986     {
       
   987     _DBG_FILE("CNSmlDmFotaAdapter::RollbackAtomicL(): begin");
       
   988     _DBG_FILE("CNSmlDmFotaAdapter::RollbackAtomicL(): end");
       
   989     }
       
   990 
       
   991 // ---------------------------------------------------------------------------
       
   992 // CNSmlDmFotaAdapter::StreamingSupport()
       
   993 // Returns whether or not streaming is supported in this adapter.
       
   994 // In Fota this method is also used to enquire whether or not a large object
       
   995 // whose size is given in aItemSize fits to disk (OOD check using Fota Engine),
       
   996 // and to acknowledge that Generic Alerts have been sent succesfully to remote 
       
   997 // server. If aItemSize is larger that 0, OOD check feature is executed. 
       
   998 // If aItemSize equals to KNSmlDMResetGenAlerts, Generic Alerts are marked 
       
   999 // sent. Otherwise aItemSize is set to a treshold value, which is used by 
       
  1000 // DM Host Server to determineif streaming should be used (large object) 
       
  1001 // or not.
       
  1002 // ---------------------------------------------------------------------------
       
  1003 //
       
  1004 TBool CNSmlDmFotaAdapter::StreamingSupport( TInt& aItemSize )
       
  1005     {
       
  1006     _DBG_FILE("CNSmlDmFotaAdapter::StreamingSupport(): begin");
       
  1007     
       
  1008     if ( aItemSize == KNSmlDMResetGenAlerts )
       
  1009         {
       
  1010         // generic alerts have been sent successfully to this server
       
  1011         TRAPD( err, MarkGenericAlertsSentL() );
       
  1012         if(err)
       
  1013         {
       
  1014         	_DBG_FILE("CNSmlDmFotaAdapter::StreamingSupport(): error in MarkGenricAlertSentL()");
       
  1015         }
       
  1016         }
       
  1017     else if ( aItemSize <= 0 )
       
  1018         {
       
  1019         // item size set so that streaming is used only when updating PkgData
       
  1020         aItemSize = KNSmlDMFotaStreamingTreshold;
       
  1021         }
       
  1022     else
       
  1023         {
       
  1024         // streaming is about to be used (fota overloaded feature)
       
  1025         // ask from engine if enough space is available
       
  1026         if ( iFotaEngine.IsPackageStoreSizeAvailable( aItemSize ) )
       
  1027             {
       
  1028             // space available
       
  1029             aItemSize = KErrNone;
       
  1030             }
       
  1031         else
       
  1032             {
       
  1033             // not enough space available
       
  1034             aItemSize = KErrNoMemory;
       
  1035             }
       
  1036         }
       
  1037     
       
  1038     _DBG_FILE("CNSmlDmFotaAdapter::StreamingSupport(): end");
       
  1039     
       
  1040     return ETrue;
       
  1041     }
       
  1042 
       
  1043 // ---------------------------------------------------------------------------
       
  1044 // CNSmlDmFotaAdapter::StreamCommittedL()
       
  1045 // Notification method used by DM Host Server. All data has been written to 
       
  1046 // stream successfully and stream has been committed and closed.
       
  1047 // ---------------------------------------------------------------------------
       
  1048 //
       
  1049 void CNSmlDmFotaAdapter::StreamCommittedL()
       
  1050     {
       
  1051     _DBG_FILE("CNSmlDmFotaAdapter::StreamCommittedL(): begin");
       
  1052     TInt err = RProperty::Set(TUid::Uid(KFotaServerUid),KFotaLrgObjDl,KErrNotFound);
       
  1053     DBG_FILE_CODE(err, _S8("StreamCommittedL set P&S key KFotaLrgObjDl to -1"));
       
  1054     // set success result to db
       
  1055     iFotaDb->SetFinalResultL( KNSmlDMFotaSuccessfullDownload, iPkgId );
       
  1056     
       
  1057     // notify fota engine that all data is written
       
  1058     iFotaEngine.UpdatePackageDownloadComplete( iPkgId );
       
  1059     
       
  1060     iPkgId = KNSmlDMFotaNullPkgId;
       
  1061     
       
  1062     _DBG_FILE("CNSmlDmFotaAdapter::StreamCommittedL(): end");
       
  1063     }
       
  1064     
       
  1065 // ---------------------------------------------------------------------------
       
  1066 // CNSmlDmFotaAdapter::CompleteOutstandingCmdsL()
       
  1067 // Not supported.
       
  1068 // ---------------------------------------------------------------------------
       
  1069 //
       
  1070 void CNSmlDmFotaAdapter::CompleteOutstandingCmdsL()
       
  1071     {
       
  1072     _DBG_FILE("CNSmlDmFotaAdapter::CompleteOutstandingCmdsL(): begin");
       
  1073     _DBG_FILE("CNSmlDmFotaAdapter::CompleteOutstandingCmdsL(): end");
       
  1074     }
       
  1075 
       
  1076 // ---------------------------------------------------------------------------
       
  1077 // CNSmlDmFotaAdapter::DoFetchObjectL()
       
  1078 // Fetches the data identified by aURI in FW object aLUID. Writes the data 
       
  1079 // to aObject and returns status code according to the success of the fetch.
       
  1080 // ---------------------------------------------------------------------------
       
  1081 //
       
  1082 CSmlDmAdapter::TError CNSmlDmFotaAdapter::DoFetchObjectL( const TDesC8& aURI,
       
  1083                                                           const TDesC8& aLUID,
       
  1084                                                           CBufBase& aObject )
       
  1085     {
       
  1086     CSmlDmAdapter::TError status = CSmlDmAdapter::ENotFound;
       
  1087     
       
  1088     if ( aLUID.Length() > 0 )
       
  1089         {
       
  1090         HBufC8* data = NULL;
       
  1091         TNSmlDmFwObjectId id = DesToInt( aLUID );
       
  1092         
       
  1093         // get correct data according to the last segment of the uri
       
  1094         TPtrC8 lastSeg = LastURISeg( aURI );
       
  1095         if ( lastSeg == KNSmlDMFotaNodeName )
       
  1096             {
       
  1097             data = iFotaDb->PkgNameL( id );
       
  1098             }
       
  1099         else if ( lastSeg == KNSmlDMFotaNodeVersion )
       
  1100             {
       
  1101             data = iFotaDb->PkgVersionL( id );
       
  1102             }
       
  1103         else if ( lastSeg == KNSmlDMFotaNodeDownloadUrl || 
       
  1104                   lastSeg == KNSmlDMFotaNodeDownloadAndUpdateUrl )
       
  1105             {
       
  1106             data = iFotaDb->PkgUrlL( id );
       
  1107             }
       
  1108         else if ( lastSeg == KNSmlDMFotaNodeState )
       
  1109             {
       
  1110             // state is fetched from fota engine
       
  1111             RFotaEngineSession::TState state = iFotaEngine.GetState( id );
       
  1112             data = HBufC8::NewL( KNSmlFwMgmtObjectIntegerLength );
       
  1113             data->Des().AppendNum( state );
       
  1114             }
       
  1115         
       
  1116         // if data is fetched ok, set results
       
  1117         if ( data )
       
  1118             {
       
  1119             CleanupStack::PushL( data );
       
  1120             
       
  1121             aObject.InsertL( 0, *data );
       
  1122             status = CSmlDmAdapter::EOk;
       
  1123             
       
  1124             CleanupStack::PopAndDestroy( data );
       
  1125             }
       
  1126         }
       
  1127     
       
  1128     return status;
       
  1129     }
       
  1130 
       
  1131 // ---------------------------------------------------------------------------
       
  1132 // CNSmlDmFotaAdapter::DoExecUpdateL()
       
  1133 // Gets needed data for Update from Fota DB and notifies Fota Engine that 
       
  1134 // Update should be executed. Returns status according to the success of 
       
  1135 // the method.
       
  1136 // ---------------------------------------------------------------------------
       
  1137 //
       
  1138 CSmlDmAdapter::TError CNSmlDmFotaAdapter::DoExecUpdateL( 
       
  1139                                                 const TNSmlDmFwObjectId aLUID, 
       
  1140                                                 const TSmlProfileId aProfile )
       
  1141     {
       
  1142     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
  1143     
       
  1144     // get needed data from db for fota engine
       
  1145     HBufC8* pkgName = iFotaDb->PkgNameL( aLUID );
       
  1146     CleanupStack::PushL( pkgName );
       
  1147     
       
  1148     HBufC8* pkgVersion = iFotaDb->PkgVersionL( aLUID );
       
  1149     CleanupStack::PushL( pkgVersion );
       
  1150     
       
  1151     TInt error = KErrNone;
       
  1152 
       
  1153     if ( pkgName && pkgVersion )
       
  1154         {
       
  1155         // notify fota engine to start update
       
  1156         error = iFotaEngine.Update( aLUID, aProfile, *pkgName, *pkgVersion );
       
  1157         
       
  1158         // if immediate error occured, set final result to corresponding 
       
  1159         // value so that generic alert is not sent
       
  1160         if ( error == KErrNotFound )
       
  1161             {
       
  1162             // binary update package has not been downloaded yet -> not 
       
  1163             // possible to update
       
  1164             status = CSmlDmAdapter::ENotFound;
       
  1165             iFotaDb->SetFinalResultL( KNSmlDMFotaUndefinedError, aLUID  );
       
  1166             }
       
  1167         else if ( error != KErrNone )
       
  1168             {
       
  1169             // other error
       
  1170             status = CSmlDmAdapter::EError;
       
  1171             iFotaDb->SetFinalResultL( KNSmlDMFotaUndefinedError, aLUID );
       
  1172             }
       
  1173         }
       
  1174     else
       
  1175         {
       
  1176         // fw object was not found
       
  1177         status = CSmlDmAdapter::ENotFound;
       
  1178         }
       
  1179     
       
  1180     CleanupStack::PopAndDestroy( pkgVersion );
       
  1181     CleanupStack::PopAndDestroy( pkgName );
       
  1182 
       
  1183     return status;
       
  1184     }
       
  1185 
       
  1186 // ---------------------------------------------------------------------------
       
  1187 // CNSmlDmFotaAdapter::DoExecDownloadL()
       
  1188 // Gets needed data for Download or DownloadAndUpdate from Fota DB and 
       
  1189 // notifies Fota Engine that Download or DownloadAndUpdate should be executed.
       
  1190 // Returns status according to the success of the method.
       
  1191 // ---------------------------------------------------------------------------
       
  1192 //
       
  1193 CSmlDmAdapter::TError CNSmlDmFotaAdapter::DoExecDownloadL( 
       
  1194                                                 const TNSmlDmFwObjectId aLUID,
       
  1195                                                 const TSmlProfileId aProfile,
       
  1196                                                 TBool aUpdate )
       
  1197     {
       
  1198     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
  1199     
       
  1200     // get needed data from db for fota engine
       
  1201     HBufC8* url = iFotaDb->PkgUrlL( aLUID );
       
  1202     CleanupStack::PushL( url );
       
  1203     
       
  1204     HBufC8* pkgName = iFotaDb->PkgNameL( aLUID );
       
  1205     CleanupStack::PushL( pkgName );
       
  1206     
       
  1207     HBufC8* pkgVersion = iFotaDb->PkgVersionL( aLUID );
       
  1208     CleanupStack::PushL( pkgVersion );
       
  1209     
       
  1210     TInt error = KErrNone;
       
  1211     
       
  1212     if ( url && pkgName && pkgVersion )
       
  1213         {
       
  1214         
       
  1215         if ( aUpdate )
       
  1216             {
       
  1217             // notify fota engine to start download and update
       
  1218             error = iFotaEngine.DownloadAndUpdate( aLUID, *url, aProfile, *pkgName, *pkgVersion );
       
  1219             }
       
  1220         else
       
  1221             {
       
  1222             // notify fota engine to start download
       
  1223             error = iFotaEngine.Download( aLUID, *url, aProfile, *pkgName, *pkgVersion );
       
  1224             }
       
  1225         
       
  1226         // if immediate error occured, set final result to corresponding value so that 
       
  1227         // generic alert is not sent
       
  1228         if ( error == KErrArgument )
       
  1229             {
       
  1230             // url incorrectly formed
       
  1231             status = CSmlDmAdapter::EInvalidObject;
       
  1232             iFotaDb->SetFinalResultL( KNSmlDMFotaBadUrl, aLUID );
       
  1233             }
       
  1234         else if ( error != KErrNone )
       
  1235             {
       
  1236             // other error
       
  1237             status = CSmlDmAdapter::EError;
       
  1238             iFotaDb->SetFinalResultL( KNSmlDMFotaUndefinedError, aLUID );
       
  1239             }
       
  1240         }
       
  1241     else
       
  1242         {
       
  1243         // fw object was not found
       
  1244         status = CSmlDmAdapter::ENotFound;
       
  1245         }
       
  1246     
       
  1247     CleanupStack::PopAndDestroy( pkgVersion );
       
  1248     CleanupStack::PopAndDestroy( pkgName );
       
  1249     CleanupStack::PopAndDestroy( url );
       
  1250 
       
  1251     return status;
       
  1252     }
       
  1253 
       
  1254 // ---------------------------------------------------------------------------
       
  1255 // CNSmlDmFotaAdapter::SaveExecInfoL()
       
  1256 // Saves the values needed when starting an exec command. Returns the saved 
       
  1257 // profile id.
       
  1258 // ---------------------------------------------------------------------------
       
  1259 //
       
  1260 TSmlProfileId CNSmlDmFotaAdapter::SaveExecInfoL( const TDesC8& aURI, 
       
  1261                                                  const TNSmlDmFwObjectId aLUID,
       
  1262                                                  const TDesC8& aCorrelator )
       
  1263     {
       
  1264     // set final result (null), uri and correlator to fota db
       
  1265     User::LeaveIfError( iFotaDb->SetFinalResultL( KNSmlFotaNullResult, aLUID ) );
       
  1266     User::LeaveIfError( iFotaDb->SetMgmtUriL( aURI, aLUID ) );
       
  1267     User::LeaveIfError( iFotaDb->SetCorrelatorL( aCorrelator, aLUID ) );
       
  1268     
       
  1269     // fetch profile id and server id of the currently running dm session
       
  1270     TSmlProfileId profId = KErrNotFound;
       
  1271     HBufC8* serverId = NULL;
       
  1272     
       
  1273     GetServerInfoL( profId, serverId );
       
  1274     CleanupStack::PushL( serverId );
       
  1275     
       
  1276     // save profile id and server id to fota db
       
  1277     User::LeaveIfError( iFotaDb->SetServerInfoL( profId, *serverId, aLUID ) );
       
  1278     
       
  1279     CleanupStack::PopAndDestroy( serverId );
       
  1280     
       
  1281     return profId;
       
  1282     }
       
  1283 
       
  1284 // ---------------------------------------------------------------------------
       
  1285 // CNSmlDmFotaAdapter::GetServerInfoL()
       
  1286 // Fetches profile id and server id of the currently running dm session. 
       
  1287 // Data is fetched using Client API and set to the references given as 
       
  1288 // parameters. Reallocates server id to aServerId.
       
  1289 // ---------------------------------------------------------------------------
       
  1290 //
       
  1291 void CNSmlDmFotaAdapter::GetServerInfoL( TSmlProfileId& aProfId, 
       
  1292                                          HBufC8*& aServerId ) const
       
  1293     {
       
  1294     // Open session
       
  1295     RSyncMLSession session;
       
  1296     session.OpenL();
       
  1297     CleanupClosePushL( session );
       
  1298     
       
  1299     // get current job's id (and usage type)
       
  1300     TSmlJobId jobId = KErrNotFound;
       
  1301     TSmlUsageType type = ESmlDevMan;
       
  1302     session.CurrentJobL( jobId, type );
       
  1303     
       
  1304     // open currently running job
       
  1305     RSyncMLDevManJob dmJob;
       
  1306     dmJob.OpenL( session, jobId );
       
  1307     CleanupClosePushL( dmJob );
       
  1308     
       
  1309     // get job's profile id
       
  1310     aProfId = dmJob.Profile();
       
  1311     
       
  1312     // open profile using id in read-only mode
       
  1313     RSyncMLDevManProfile dmProf;
       
  1314     dmProf.OpenL( session, aProfId, ESmlOpenRead );
       
  1315     CleanupClosePushL( dmProf );
       
  1316     
       
  1317     // get profile's server id
       
  1318     aServerId = dmProf.ServerId().AllocL();
       
  1319     
       
  1320     // close handles
       
  1321     CleanupStack::PopAndDestroy( &dmProf );
       
  1322     CleanupStack::PopAndDestroy( &dmJob );
       
  1323     CleanupStack::PopAndDestroy( &session );
       
  1324     }
       
  1325 // ---------------------------------------------------------------------------
       
  1326 // CNSmlDmFotaAdapter::CheckAndAddPredefinedNodeL()
       
  1327 // Checks if predefined node for FUMO is in tree if not add to the tree 
       
  1328 // ---------------------------------------------------------------------------
       
  1329 //    
       
  1330 void CNSmlDmFotaAdapter::CheckAndAddPredefinedNodeL()
       
  1331     {
       
  1332     
       
  1333 	TBuf8<KMaxFullName> temp;
       
  1334 	GetPredefinedNodeL(temp);
       
  1335 	if (temp.Length())
       
  1336 		{
       
  1337     	RNSmlDMCallbackSession session;
       
  1338     	User::LeaveIfError( session.Connect() );
       
  1339     	CleanupClosePushL(session);
       
  1340 	TBuf8<KMaxName> node[4];
       
  1341     TInt location = temp.LocateReverse(',');
       
  1342     node[0].Copy(temp.Mid(location+1));
       
  1343     TInt newLocation = (temp.Left(location-1)).LocateReverse(',');
       
  1344     node[1].Copy(temp.Mid(newLocation+1,location-(newLocation+1)));
       
  1345     location = newLocation;
       
  1346     newLocation = (temp.Left(location-1)).LocateReverse(',');
       
  1347     node[2].Copy(temp.Mid(newLocation+1,location-(newLocation+1)));
       
  1348     node[3].Copy(temp.Mid(0,newLocation ));
       
  1349 	for(TInt i=0; i<4; i++)
       
  1350 	{	
       
  1351 		TBuf8<KMaxFullName> temp1;
       
  1352 		temp1.Zero();
       
  1353 		temp1.Copy(KNSmlDMFotaNode);
       
  1354 		temp1.Append(KNSmlDMFotaSeparatorDes);
       
  1355 		temp1.Append(node[i]);
       
  1356    		HBufC8* luid = session.GetLuidAllocL( KNSmlDMFotaAdapterImplUid,temp1);
       
  1357 		CleanupStack::PushL(luid);
       
  1358     	if ( luid->Length() > 0 )
       
  1359 			{
       
  1360 			CleanupStack::PopAndDestroy( luid );
       
  1361     		CleanupStack::PopAndDestroy( &session );
       
  1362 			return;			
       
  1363 			}
       
  1364    		else
       
  1365     		{
       
  1366       		// Add the mapping 
       
  1367 			TNSmlDmFwObjectId newId = KErrNotFound;
       
  1368         	TRAPD( err, newId = iFotaDb->AddFwObjectL() );
       
  1369 
       
  1370 	        if ( err == KErrNone )
       
  1371 				{
       
  1372             	// added ok
       
  1373             	TBuf8<KNSmlFwMgmtObjectIntegerLength> newLUID;
       
  1374             	newLUID.AppendNum( newId );
       
  1375       			session.AddMappingInfoL(KNSmlDMFotaAdapterImplUid, temp1, newLUID );
       
  1376             	}
       
  1377     		}
       
  1378 		CleanupStack::PopAndDestroy( luid );
       
  1379 	}
       
  1380 		CleanupStack::PopAndDestroy( &session );
       
  1381     	}
       
  1382     }
       
  1383 // ---------------------------------------------------------------------------
       
  1384 // CNSmlDmFotaAdapter::GetPredefinedNodeL()
       
  1385 // Gets  predefined node for FUMO from cenrep 
       
  1386 // ---------------------------------------------------------------------------
       
  1387 //
       
  1388 void CNSmlDmFotaAdapter::GetPredefinedNodeL(TDes8& aNode)
       
  1389 	{
       
  1390     CRepository* centrep( NULL);
       
  1391 	aNode.Zero();
       
  1392    	centrep = CRepository::NewLC( TUid::Uid(0x101F9A0A) );
       
  1393 
       
  1394     if ( centrep )
       
  1395 	    {
       
  1396     	TFullName temp;
       
  1397 		
       
  1398     	if (centrep->Get( KDevManFUMOPredefinedNodes, temp )==KErrNone && temp.Length() )
       
  1399 			{
       
  1400 			temp.Trim();
       
  1401 			aNode.Copy(temp);
       
  1402 			}
       
  1403 		CleanupStack::PopAndDestroy(centrep);
       
  1404 	    }
       
  1405 	}
       
  1406 // ---------------------------------------------------------------------------
       
  1407 // CNSmlDmFotaAdapter::MakeGenericAlertsL()
       
  1408 // Checks whether or not there are fw objects whose final result should be 
       
  1409 // sent to the remote server which is involved with the current DM session.
       
  1410 // If there are such objects, notifies private api using the data needed for
       
  1411 // generic alert generation.
       
  1412 // ---------------------------------------------------------------------------
       
  1413 //
       
  1414 void CNSmlDmFotaAdapter::MakeGenericAlertsL()
       
  1415     {
       
  1416     // search for fw objects that have empty final result
       
  1417     RNSmlDmFwObjectArray ids;
       
  1418     CleanupClosePushL( ids );
       
  1419     
       
  1420     iFotaDb->GetEmptyFinalResultsL( ids );
       
  1421     if ( ids.Count() == 0 )
       
  1422         {
       
  1423         // none found, no need for generic alerts
       
  1424         CleanupStack::PopAndDestroy( &ids );
       
  1425         return;
       
  1426         }
       
  1427     
       
  1428     // get information of the remote DM server
       
  1429     TSmlProfileId profId = 0;
       
  1430     HBufC8* serverId = NULL;
       
  1431     GetServerInfoL( profId, serverId );
       
  1432     CleanupStack::PushL( serverId );
       
  1433     
       
  1434     // open handle to private api
       
  1435     RNSmlPrivateAPI privateAPI;
       
  1436     privateAPI.OpenL();
       
  1437     CleanupClosePushL( privateAPI );
       
  1438     
       
  1439     // go through all objects in ids
       
  1440     for ( TInt i = 0; i < ids.Count(); ++i )
       
  1441         {
       
  1442         // check that server ids match. if not, move to next entry
       
  1443         HBufC8* fwServerId = iFotaDb->ServerIdL( ids[i] );
       
  1444         CleanupStack::PushL( fwServerId );
       
  1445         
       
  1446         if ( *serverId == *fwServerId )
       
  1447             {
       
  1448             // check that mgmt uri is not empty string. if it is, 
       
  1449             // move to next entry
       
  1450             HBufC8* fwMgmtUri = iFotaDb->MgmtUriL( ids[i] );
       
  1451             CleanupStack::PushL( fwMgmtUri );
       
  1452             
       
  1453             if ( *fwMgmtUri != KNullDesC8 )
       
  1454                 {
       
  1455                 // check that update has reached its final result
       
  1456                 TInt finalResult = iFotaEngine.GetResult( ids[i] );
       
  1457                 
       
  1458                 RFotaEngineSession::TState finalState = iFotaEngine.GetState( ids[i] );
       
  1459                 
       
  1460                 if ( finalResult != KErrNotFound && finalState != RFotaEngineSession::EStartingUpdate)
       
  1461                     {
       
  1462                     // get fw object's correlator
       
  1463                     HBufC8* fwCorrelator = iFotaDb->CorrelatorL( ids[i] );
       
  1464                     CleanupStack::PushL( fwCorrelator );
       
  1465                     
       
  1466                     // add generic alert to dm message
       
  1467                     TPtrC8 metaType = GetMetaType( *fwMgmtUri );
       
  1468                     privateAPI.AddDMGenericAlertRequestL( *fwMgmtUri, metaType, KNSmlDMFotaMetaFormat, finalResult, *fwCorrelator );
       
  1469                     
       
  1470                     CleanupStack::PopAndDestroy( fwCorrelator );
       
  1471                     }
       
  1472                 }
       
  1473             
       
  1474             CleanupStack::PopAndDestroy( fwMgmtUri );
       
  1475             }
       
  1476         
       
  1477         CleanupStack::PopAndDestroy( fwServerId );
       
  1478         }
       
  1479     
       
  1480     CleanupStack::PopAndDestroy( &privateAPI );
       
  1481     CleanupStack::PopAndDestroy( serverId );
       
  1482     CleanupStack::PopAndDestroy( &ids );
       
  1483     
       
  1484     }
       
  1485 
       
  1486 // ---------------------------------------------------------------------------
       
  1487 // CNSmlDmFotaAdapter::MarkGenericAlertsSentL()
       
  1488 // Puts a final result value to those fw objects, that are 
       
  1489 // associated with current DM session's remote server, have 
       
  1490 // been a target to an exec command and the exec command has 
       
  1491 // finished. I.e. Generic Alert has been sent to remote server
       
  1492 // reporting the results of these exec commands --> not needed to 
       
  1493 // send Generic Alert anymore in next DM session.
       
  1494 // ---------------------------------------------------------------------------
       
  1495 //
       
  1496 void CNSmlDmFotaAdapter::MarkGenericAlertsSentL()
       
  1497     {
       
  1498     // search for fw objects that have empty final result
       
  1499     RNSmlDmFwObjectArray ids;
       
  1500     CleanupClosePushL( ids );
       
  1501     
       
  1502     // get information of the remote DM server
       
  1503     TSmlProfileId profId = 0;
       
  1504     HBufC8* serverId = NULL;
       
  1505     GetServerInfoL( profId, serverId );
       
  1506     CleanupStack::PushL( serverId );
       
  1507     
       
  1508     iFotaDb->GetEmptyFinalResultsL( ids, *serverId );
       
  1509     
       
  1510     // go through all objects in ids
       
  1511     for ( TInt i = 0; i < ids.Count(); ++i )
       
  1512         {
       
  1513         // check that update has reached its final result
       
  1514         TInt finalResult = iFotaEngine.GetResult( ids[i] );
       
  1515         if ( finalResult != KErrNotFound )
       
  1516             {
       
  1517             // set final result thus setting generic alert sent
       
  1518             iFotaDb->SetFinalResultL( finalResult, ids[i] );
       
  1519             
       
  1520             // also notify fota engine, that generic alert has been
       
  1521             // successfully sent, thus enabling possible cleanup
       
  1522             iFotaEngine.GenericAlertSentL( ids[i] );
       
  1523             }
       
  1524         }
       
  1525     
       
  1526     CleanupStack::PopAndDestroy( serverId );
       
  1527     CleanupStack::PopAndDestroy( &ids );
       
  1528     }
       
  1529 
       
  1530 // ---------------------------------------------------------------------------
       
  1531 // CNSmlDmFotaAdapter::GetMetaType()
       
  1532 // Determines by the given uri which meta/type should be used in generic 
       
  1533 // alert.Returns the correct type, or KNullDesC8 if uri does not match to 
       
  1534 // exec targets.
       
  1535 // ---------------------------------------------------------------------------
       
  1536 //
       
  1537 TPtrC8 CNSmlDmFotaAdapter::GetMetaType( const TDesC8& aURI ) const
       
  1538     {
       
  1539     TPtrC8 lastSeg = LastURISeg( aURI );
       
  1540     
       
  1541     if ( lastSeg == KNSmlDMFotaNodeUpdate )
       
  1542         {
       
  1543         return KNSmlDMFotaUpdateMetaType();
       
  1544         }
       
  1545     else if ( lastSeg == KNSmlDMFotaNodeDownload )
       
  1546         {
       
  1547         return KNSmlDMFotaDownloadMetaType();
       
  1548         }
       
  1549     else if ( lastSeg == KNSmlDMFotaNodeDownloadAndUpdate )
       
  1550         {
       
  1551         return KNSmlDMFotaDownloadAndUpdateMetaType();
       
  1552         }
       
  1553 
       
  1554     return KNullDesC8();
       
  1555     }
       
  1556 
       
  1557 // ---------------------------------------------------------------------------
       
  1558 // CNSmlDmFotaAdapter::MapStatusToError()
       
  1559 // Returns a status code corresponding to the system error code given 
       
  1560 // as parameter.
       
  1561 // ---------------------------------------------------------------------------
       
  1562 //
       
  1563 CSmlDmAdapter::TError CNSmlDmFotaAdapter::MapErrorToStatus( TInt aError ) const
       
  1564     {
       
  1565     CSmlDmAdapter::TError err = CSmlDmAdapter::EError;
       
  1566     
       
  1567     switch( aError )
       
  1568         {
       
  1569         case KErrNone:
       
  1570             err = CSmlDmAdapter::EOk;
       
  1571             break;
       
  1572         case KErrNotFound:
       
  1573             err = CSmlDmAdapter::ENotFound;
       
  1574             break;
       
  1575         case KErrDiskFull:
       
  1576             err = CSmlDmAdapter::EDiskFull;
       
  1577             break;
       
  1578         case KErrOverflow:
       
  1579             err = CSmlDmAdapter::ETooLargeObject;
       
  1580             break;
       
  1581         default:
       
  1582             break;
       
  1583         }
       
  1584     
       
  1585     return err;
       
  1586     }
       
  1587 
       
  1588 // ---------------------------------------------------------------------------
       
  1589 // CNSmlDmFotaAdapter::DesToInt()
       
  1590 // Converts a 8 bit descriptor to an integer.
       
  1591 // ---------------------------------------------------------------------------
       
  1592 //
       
  1593 TInt CNSmlDmFotaAdapter::DesToInt( const TDesC8& aLUID ) const
       
  1594     {
       
  1595     TLex8 lex( aLUID );
       
  1596     TInt value = KErrNotFound;
       
  1597     lex.Val( value );
       
  1598     
       
  1599     return value;
       
  1600     }
       
  1601 
       
  1602 // ---------------------------------------------------------------------------
       
  1603 // CNSmlDmFotaAdapter::LastURISeg()
       
  1604 // Returns the last segment of the given uri.
       
  1605 // ---------------------------------------------------------------------------
       
  1606 //
       
  1607 TPtrC8 CNSmlDmFotaAdapter::LastURISeg( const TDesC8& aURI ) const
       
  1608     {
       
  1609     TInt pos = aURI.LocateReverse( KNSmlDMFotaSeparatorDes()[0] );
       
  1610     if( pos == KErrNotFound )
       
  1611         {
       
  1612         return aURI;
       
  1613         }
       
  1614     else
       
  1615         {
       
  1616         return aURI.Mid( pos + 1 );
       
  1617         }
       
  1618     }
       
  1619 
       
  1620 // ---------------------------------------------------------------------------
       
  1621 // CNSmlDmFotaAdapter::FillNodeInfoL()
       
  1622 // Fills the DDF node info.
       
  1623 // ---------------------------------------------------------------------------
       
  1624 //
       
  1625 void CNSmlDmFotaAdapter::FillNodeInfoL( MSmlDmDDFObject& aNode, 
       
  1626                                         const TSmlDmAccessTypes& aAccTypes, 
       
  1627                                         MSmlDmDDFObject::TOccurence aOccurrence, 
       
  1628                                         MSmlDmDDFObject::TScope aScope, 
       
  1629                                         MSmlDmDDFObject::TDFFormat aFormat, 
       
  1630                                         const TDesC8& aDescription ) const
       
  1631     {
       
  1632     aNode.SetAccessTypesL( aAccTypes );
       
  1633     aNode.SetOccurenceL( aOccurrence );
       
  1634     aNode.SetScopeL( aScope );
       
  1635     aNode.SetDFFormatL( aFormat );
       
  1636     
       
  1637     if( aFormat != MSmlDmDDFObject::ENode )
       
  1638         {
       
  1639         aNode.AddDFTypeMimeTypeL( KNSmlDMFotaTextPlain );
       
  1640         }
       
  1641     
       
  1642     aNode.SetDescriptionL( aDescription );
       
  1643     }
       
  1644 
       
  1645 // ---------------------------------------------------------------------------
       
  1646 // TImplementationProxy ImplementationTable[]
       
  1647 // Needed because of ECOM architecture.
       
  1648 // ---------------------------------------------------------------------------
       
  1649 //
       
  1650 #ifndef IMPLEMENTATION_PROXY_ENTRY
       
  1651 #define IMPLEMENTATION_PROXY_ENTRY(aUid, aFuncPtr)  {{aUid},(aFuncPtr)}
       
  1652 #endif
       
  1653 
       
  1654 const TImplementationProxy ImplementationTable[] = 
       
  1655     {
       
  1656     IMPLEMENTATION_PROXY_ENTRY(KNSmlDMFotaAdapterImplUid, CNSmlDmFotaAdapter::NewL)
       
  1657     };
       
  1658 
       
  1659 
       
  1660 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
  1661 
       
  1662 // ---------------------------------------------------------------------------
       
  1663 // ImplementationGroupProxy()
       
  1664 // Needed because of ECOM architecture.
       
  1665 // ---------------------------------------------------------------------------
       
  1666 //
       
  1667 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
  1668     {
       
  1669     _DBG_FILE("ImplementationGroupProxy() for CNSmlDmFotaAdapter: begin");
       
  1670     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
  1671     _DBG_FILE("ImplementationGroupProxy() for CNSmlDmFotaAdapter: end");
       
  1672     return ImplementationTable;
       
  1673     }
       
  1674 
       
  1675 
       
  1676 // End of file
       
  1677