omadm/omadmextensions/adapters/nsmldmbmadapter/src/nsmldmbmsettingstore.cpp
changeset 18 7d11f9a6646f
parent 4 75a71fdb4c92
child 21 c707676bf59f
equal deleted inserted replaced
4:75a71fdb4c92 18:7d11f9a6646f
     1 /*
       
     2 * Copyright (c) 2006 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:   Provides settings management in CommsDat.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <utf.h>
       
    22 #include <cmdestinationext.h>
       
    23 #include <cmconnectionmethoddef.h>
       
    24 #include <cmmanagerdef.h>
       
    25 #include <commsdat.h>
       
    26 
       
    27 #include "nsmldmbmsettingstore.h"
       
    28 #include "nsmldmbmadapter.h"
       
    29 #include "bmadapterlogger.h"
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CNSmlDmBmSettingStore::NewL
       
    33 // -----------------------------------------------------------------------------
       
    34 CNSmlDmBmSettingStore* CNSmlDmBmSettingStore::NewL( CNSmlDmBmAdapter * aAdapter )
       
    35     {
       
    36     CNSmlDmBmSettingStore* self = new (ELeave) CNSmlDmBmSettingStore( aAdapter );
       
    37     CleanupStack::PushL(self);
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop( self );
       
    40     return self;
       
    41     }
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CNSmlDmBmSettingStore::CNSmlDmBmSettingStore
       
    46 // -----------------------------------------------------------------------------
       
    47 CNSmlDmBmSettingStore::CNSmlDmBmSettingStore( CNSmlDmBmAdapter * aAdapter ) 
       
    48     : iAdapter( aAdapter )
       
    49     {
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CNSmlDmBmSettingStore::ConstructL
       
    54 // -----------------------------------------------------------------------------
       
    55 void CNSmlDmBmSettingStore::ConstructL()
       
    56     {
       
    57     iCmManagerExt.OpenL();
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CNSmlDmBmSettingStore::~CNSmlDmBmSettingStore
       
    62 // -----------------------------------------------------------------------------
       
    63 CNSmlDmBmSettingStore::~CNSmlDmBmSettingStore()
       
    64     {
       
    65     iCmManagerExt.Close();
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CNSmlDmBmSettingStore::StoreSnapL
       
    70 // Stores data related to a snap object. Executes commands for the snap and fills 
       
    71 // in status and for get commands result values.
       
    72 // -----------------------------------------------------------------------------
       
    73 void CNSmlDmBmSettingStore::StoreSnapL( CSmlDmBmSettingsElement& aSettings )
       
    74     {
       
    75     // this snap has been handled
       
    76     aSettings.SetExecuted( ETrue );
       
    77 
       
    78     // error empty settings object
       
    79     if ( !aSettings.NodeBuf().Count() )
       
    80       {
       
    81       BMADAPTERLOGSTRING( "StoreSnapL: Error, No commands found" )
       
    82         return;
       
    83         }
       
    84        
       
    85     TInt nameCmdInd( -1 );
       
    86     TInt startInd( 0 );
       
    87     RCmDestinationExt snap;
       
    88     TInt snapId( 0 );
       
    89     
       
    90     // New SNAP to be stored, first command is add node
       
    91     if( !aSettings.NodeBuf()[0]->Leaf() && 
       
    92       aSettings.NodeBuf()[0]->CmdType() == CNSmlDmBmAdapter::EAddCmd)
       
    93         {
       
    94         CSmlDmBmCommandElement* snapCmd( NULL );
       
    95         CSmlDmBmCommandElement* nameCmd( NULL );
       
    96       
       
    97         snapCmd = aSettings.NodeBuf()[0];
       
    98         startInd = 1;
       
    99 
       
   100         // find name command
       
   101         for ( TInt i( 0 ); i < aSettings.NodeBuf().Count(); i++)
       
   102             {
       
   103             if ( aSettings.NodeBuf()[i]->Leaf() && 
       
   104                  !aSettings.NodeBuf()[i]->LastUriSeg()->Compare( KNSmlDmBMAdapterName ) )
       
   105                 {
       
   106                 nameCmd = aSettings.NodeBuf()[i];
       
   107                 nameCmdInd = i;
       
   108                 break;
       
   109                 }
       
   110             }
       
   111         // Snap can be created when name cmd exists
       
   112         if ( snapCmd && nameCmd )
       
   113             {
       
   114             HBufC* name = HBufC::NewLC( nameCmd->Data()->Size() );
       
   115             TPtr namePtr = name->Des();
       
   116             CnvUtfConverter::ConvertToUnicodeFromUtf8( namePtr, *nameCmd->Data() );
       
   117             snap = iCmManagerExt.CreateDestinationL( namePtr );
       
   118             CleanupStack::PopAndDestroy( name );
       
   119             CleanupClosePushL( snap );
       
   120                               
       
   121             snap.UpdateL();
       
   122             snapCmd->SetStatus( CSmlDmAdapter::EOk );
       
   123             nameCmd->SetStatus( CSmlDmAdapter::EOk );
       
   124             snapCmd->SetExecuted( ETrue );
       
   125             nameCmd->SetExecuted( ETrue );
       
   126             aSettings.SetLuid( snap.Id() );
       
   127             }
       
   128         else
       
   129             {
       
   130             BMADAPTERLOGSTRING( "StoreSnapL: Error, SNAP doesn't have necessary data and can't be stored" )
       
   131             return;
       
   132             }
       
   133         }
       
   134     // existing SNAP
       
   135     else
       
   136         {
       
   137         snap = iCmManagerExt.DestinationL( aSettings.Luid() );
       
   138         CleanupClosePushL( snap );
       
   139         }
       
   140     snapId = snap.Id();
       
   141     TInt err( KErrNone );
       
   142     // execute all remaining commands for the snap 
       
   143     // starting after add node cmd
       
   144     for ( TInt i( startInd ); i < aSettings.NodeBuf().Count(); i++ )
       
   145         {
       
   146         // name command is already executed -> skipped
       
   147         if ( i != nameCmdInd )
       
   148             {
       
   149             CSmlDmBmCommandElement* currentCmd = aSettings.NodeBuf()[i];
       
   150             // handle leaf commands
       
   151             // leaves are trapped and if possible 
       
   152             // execution continues with remaining commands
       
   153             if ( currentCmd->Leaf() )
       
   154                 {
       
   155                 // name
       
   156                 if ( !currentCmd->LastUriSeg()->Compare( KNSmlDmBMAdapterName() ) )
       
   157                     {
       
   158                     // name is set more than once within same message
       
   159                     TRAP( err, ExecuteNameCmdL( *currentCmd, snap ) );
       
   160                     }
       
   161                 // metadata 
       
   162                 else if ( !currentCmd->LastUriSeg()->Compare( KNSmlDmBMAdapterMetadata ) )
       
   163                     {
       
   164                     TRAP( err, ExecuteMetadataCmdL( *currentCmd, snap ) );
       
   165                     }
       
   166                 // protected
       
   167                 else if ( !currentCmd->LastUriSeg()->Compare( KNSmlDmBMAdapterProtected ) )
       
   168                     {
       
   169                     TRAP( err, ExecuteProtectionCmdL( *currentCmd, snap ) );
       
   170                     }
       
   171                 // hidden
       
   172                 else if ( !currentCmd->LastUriSeg()->Compare( KNSmlDmBMAdapterHidden ) )
       
   173                     {
       
   174                     TRAP( err, ExecuteHiddenCmdL( *currentCmd, snap ) );
       
   175                     }
       
   176                 // iap list 
       
   177                 else if ( !currentCmd->LastUriSeg()->Compare( KNSmlDmBMAdapterIAPPriorityList ) )
       
   178                     {
       
   179                     TRAP( err, ExecuteIapsCmdL( *currentCmd, snap ) );
       
   180                     }
       
   181                 // embedded snap  
       
   182                 else if ( !currentCmd->LastUriSeg()->Compare( KNSmlDmBMAdapterEmbeddedSNAP ) )
       
   183                     {
       
   184                     TRAP( err, ExecuteEmbeddedSnapCmdL( *currentCmd, snap ) );
       
   185                     }
       
   186                 else
       
   187                     {
       
   188                     // invalid node
       
   189                     BMADAPTERLOGSTRING( "StoreSnapL: Error, Invalid node name" )
       
   190                     currentCmd->SetStatus( CSmlDmAdapter::ENotFound );
       
   191                     err = KErrNone;
       
   192                     }
       
   193                 }
       
   194             // snap node    
       
   195             else
       
   196                 {
       
   197                 TRAP( err, ExecuteSnapCmdL( *currentCmd, snap.Id() ) );
       
   198                 // no more commands will be executed
       
   199                 // after snap is deleted
       
   200                 if( currentCmd->CmdType() == CNSmlDmBmAdapter::EDeleteCmd )
       
   201                     {
       
   202                     break;
       
   203                     }
       
   204                 }
       
   205   
       
   206             // handle errors, check if execution may continue
       
   207             if( err != KErrNone )
       
   208                 {
       
   209                 // cases where not worth continuing
       
   210                 // attempt to return status codes however
       
   211                 if( err == KErrNoMemory )
       
   212                     {
       
   213                     currentCmd->SetStatus( CSmlDmAdapter::ENoMemory );
       
   214                     currentCmd->SetExecuted( ETrue );
       
   215                     break;
       
   216                     }
       
   217                 else if( err == KErrDiskFull )
       
   218                     {
       
   219                     currentCmd->SetStatus( CSmlDmAdapter::EDiskFull );
       
   220                     currentCmd->SetExecuted( ETrue );
       
   221                     break;
       
   222                     }
       
   223                 // cases where command execution continues
       
   224                 else if( err == KErrNotFound )
       
   225                     {
       
   226                     currentCmd->SetStatus( CSmlDmAdapter::ENotFound );
       
   227                     }
       
   228                 else if( err == KErrArgument )
       
   229                     {
       
   230                     currentCmd->SetStatus( CSmlDmAdapter::EInvalidObject );
       
   231                     }
       
   232                 else
       
   233                     {
       
   234                     currentCmd->SetStatus( CSmlDmAdapter::EError );
       
   235                     }
       
   236                 // if error occurred, reopen snap to dismis any changes
       
   237                 // continue with rest of buffered commands    
       
   238                 CleanupStack::PopAndDestroy( &snap );
       
   239                 snap = iCmManagerExt.DestinationL( snapId );
       
   240                 CleanupClosePushL( snap );
       
   241                 }
       
   242             // if leaf cmd execution was successful and data written -> update the snap
       
   243             else if( currentCmd->Leaf() &&
       
   244                 currentCmd->Status() == CSmlDmAdapter::EOk && 
       
   245                 currentCmd->CmdType() != CNSmlDmBmAdapter::EGetCmd && 
       
   246                 currentCmd->CmdType() != CNSmlDmBmAdapter::EGetSizeCmd )
       
   247                 {
       
   248                 snap.UpdateL();
       
   249                 }
       
   250             else
       
   251                 {
       
   252                 BMADAPTERLOGSTRING( 
       
   253                     "StoreSnapL: Leaf cmd execution unsuccessful" )
       
   254                 }
       
   255             currentCmd->SetExecuted( ETrue );
       
   256 
       
   257             }
       
   258         }
       
   259     CleanupStack::PopAndDestroy( &snap );
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CNSmlDmBmSettingStore::ExecuteCmdL
       
   264 // Executes a single command
       
   265 // -----------------------------------------------------------------------------
       
   266 void CNSmlDmBmSettingStore::ExecuteCmdL( CSmlDmBmCommandElement& aCmd, TUint aLuid)
       
   267     {
       
   268     if( !aCmd.Leaf() )
       
   269         {
       
   270         ExecuteSnapCmdL( aCmd, aLuid );
       
   271         }
       
   272     else 
       
   273         {
       
   274         // snap can be opened
       
   275         RCmDestinationExt snap = iCmManagerExt.DestinationL( aLuid );
       
   276         CleanupClosePushL( snap );
       
   277         // name
       
   278         if ( !aCmd.LastUriSeg()->Compare( KNSmlDmBMAdapterName ) )
       
   279             {
       
   280             ExecuteNameCmdL( aCmd, snap );
       
   281             }
       
   282         // iap list
       
   283         else if ( !aCmd.LastUriSeg()->Compare( KNSmlDmBMAdapterIAPPriorityList ) )
       
   284             {
       
   285             ExecuteIapsCmdL( aCmd, snap );
       
   286             } 
       
   287         // metadata
       
   288         else if ( !aCmd.LastUriSeg()->Compare( KNSmlDmBMAdapterMetadata ) )
       
   289             {
       
   290             ExecuteMetadataCmdL( aCmd, snap ); 
       
   291             } 
       
   292         // protected
       
   293         else if ( !aCmd.LastUriSeg()->Compare( KNSmlDmBMAdapterProtected ) )
       
   294             {
       
   295             ExecuteProtectionCmdL( aCmd, snap ); 
       
   296             }
       
   297         // hidden 
       
   298         else if ( !aCmd.LastUriSeg()->Compare( KNSmlDmBMAdapterHidden ) )
       
   299             {
       
   300             ExecuteHiddenCmdL( aCmd, snap ); 
       
   301             }
       
   302         // embedded snap
       
   303         else if ( !aCmd.LastUriSeg()->Compare( KNSmlDmBMAdapterEmbeddedSNAP ) )
       
   304             {
       
   305             ExecuteEmbeddedSnapCmdL( aCmd, snap );
       
   306             }
       
   307         else
       
   308             {
       
   309             // invalid node
       
   310             BMADAPTERLOGSTRING( "ExecuteCmdL: Error, Invalid node name" )
       
   311             aCmd.SetStatus( CSmlDmAdapter::ENotFound );
       
   312             }
       
   313         // update snap if necessary              
       
   314         if( aCmd.Status() == CSmlDmAdapter::EOk &&
       
   315             aCmd.CmdType() != CNSmlDmBmAdapter::EGetCmd && 
       
   316             aCmd.CmdType() != CNSmlDmBmAdapter::EGetSizeCmd)
       
   317             {
       
   318             snap.UpdateL();
       
   319             }
       
   320         aCmd.SetExecuted( ETrue );
       
   321         CleanupStack::PopAndDestroy( &snap );
       
   322         }
       
   323     }
       
   324 
       
   325    
       
   326 // -----------------------------------------------------------------------------
       
   327 // CNSmlDmBmSettingStore::GetSnapsL
       
   328 // Fetches all snap ids
       
   329 // -----------------------------------------------------------------------------
       
   330 void CNSmlDmBmSettingStore::GetSnapsL( RArray<TUint32>& aLUIDArray )
       
   331         {
       
   332         iCmManagerExt.AllDestinationsL( aLUIDArray);
       
   333         }
       
   334  
       
   335 // -----------------------------------------------------------------------------
       
   336 // CNSmlDmBmSettingStore::ExecuteSnapCmdL
       
   337 // Executes a command for snap node. Either delete or get, adds are handled 
       
   338 // in StoreSNAPL
       
   339 // -----------------------------------------------------------------------------
       
   340 void CNSmlDmBmSettingStore::ExecuteSnapCmdL( CSmlDmBmCommandElement& aCmd, TUint aLuid )
       
   341     {
       
   342     RCmDestinationExt snap = iCmManagerExt.DestinationL( aLuid );
       
   343     CleanupClosePushL( snap );
       
   344     if ( aCmd.CmdType() == CNSmlDmBmAdapter::EGetCmd )
       
   345         {
       
   346         TBool found( EFalse );
       
   347         // get child node list
       
   348 
       
   349         // check if snap has embedded snap        
       
   350         for ( TInt i(0), c = snap.ConnectionMethodCount(); i < c; i++ )
       
   351             {
       
   352             RCmConnectionMethodExt cm = snap.ConnectionMethodL( i );
       
   353             if ( cm.GetBoolAttributeL( CMManager::ECmDestination ) )
       
   354                 {
       
   355                 found = ETrue;
       
   356                 break;
       
   357                 }
       
   358             }
       
   359         if( found )
       
   360             {
       
   361             aCmd.SetDataL( KNSmlDmBMAllLeafNodes );
       
   362             }
       
   363         else
       
   364             {
       
   365             aCmd.SetDataL( KNSmlDmBMAllLeafNodesNoEmbedded );
       
   366             }
       
   367 
       
   368         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   369         aCmd.SetExecuted( ETrue );
       
   370         CleanupStack::PopAndDestroy( &snap );
       
   371         }
       
   372     else if ( aCmd.CmdType() == CNSmlDmBmAdapter::EDeleteCmd )
       
   373         {
       
   374         snap.DeleteLD();
       
   375         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   376         aCmd.SetExecuted( ETrue );
       
   377         CleanupStack::Pop( &snap );
       
   378         }
       
   379     else
       
   380         {
       
   381         BMADAPTERLOGSTRING( "ExecuteSnapCmdL: Error, Invalid cmd type" )
       
   382         aCmd.SetStatus( CSmlDmAdapter::EError );
       
   383         CleanupStack::PopAndDestroy( &snap );
       
   384         }
       
   385     }
       
   386 
       
   387 // ---------------------------------------------------------------------------
       
   388 // CNSmlDmBmSettingStore::ExecuteIapsCmdL
       
   389 // Executes an iap list command (add or get).
       
   390 // ---------------------------------------------------------------------------
       
   391 //    
       
   392 void CNSmlDmBmSettingStore::ExecuteIapsCmdL( CSmlDmBmCommandElement& aCmd, 
       
   393                                              RCmDestinationExt& aSnap )
       
   394     {
       
   395     // for add command replace the list of iaps with the new one
       
   396     if ( aCmd.CmdType() == CNSmlDmBmAdapter::EAddCmd )
       
   397         {
       
   398         // remove old iaps
       
   399         for( TInt i(0); i < aSnap.ConnectionMethodCount(); )
       
   400             {
       
   401             RCmConnectionMethodExt cm = aSnap.ConnectionMethodL( i );
       
   402             // if iap, remove
       
   403             if ( !cm.GetBoolAttributeL( CMManager::ECmDestination ) )
       
   404                 {
       
   405                 aSnap.RemoveConnectionMethodL( cm );
       
   406                 }
       
   407             // otherwise skip the ebedded snap entry  
       
   408             else
       
   409                 {
       
   410                 i++;
       
   411                 }
       
   412             }
       
   413         // add new list of iaps 
       
   414         RArray<TUint> iaps = iAdapter->GetIdArrayL( *aCmd.Data() );
       
   415         CleanupClosePushL( iaps );
       
   416         TInt wildcard(0);
       
   417         for ( TInt i( 0 ); i < iaps.Count(); i++ )
       
   418             {
       
   419             RCmConnectionMethodExt cm = iCmManagerExt.ConnectionMethodL( iaps[i] );
       
   420             aSnap.AddConnectionMethodL( cm );
       
   421             if ( aSnap.PriorityL( cm ) != CMManager::KDataMobilitySelectionPolicyPriorityWildCard )
       
   422                 {
       
   423                 // set the priority of iap as it's index in the list
       
   424                 // but preceding any iaps with wildcard priority.
       
   425                 aSnap.ModifyPriorityL( cm, i - wildcard );
       
   426                 }
       
   427             else
       
   428                 {
       
   429                 wildcard++;
       
   430                 }
       
   431             }
       
   432         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   433         CleanupStack::PopAndDestroy( &iaps );
       
   434         }
       
   435     // for get command fetch the list of iaps
       
   436     else if ( aCmd.CmdType() == CNSmlDmBmAdapter::EGetCmd || 
       
   437               aCmd.CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   438         {
       
   439         RArray<TUint> ids;
       
   440         CleanupClosePushL( ids );
       
   441         for ( TInt i(0), c = aSnap.ConnectionMethodCount(); i < c; i++ )
       
   442             {
       
   443             // if not embedded snap or hidden, insert into iap list 
       
   444             // (hidden iaps not handled by internet adapter, so link won't be found)
       
   445             if( !aSnap.ConnectionMethodL(i).GetBoolAttributeL( CMManager::ECmDestination ) &&
       
   446                 !aSnap.ConnectionMethodL(i).GetBoolAttributeL( CMManager::ECmHidden ) )
       
   447                 {
       
   448                 ids.Insert( aSnap.ConnectionMethodL(i).GetIntAttributeL( 
       
   449                                                        CMManager::ECmIapId ), i );
       
   450                 }
       
   451             }
       
   452         if ( ids.Count() > 0)
       
   453             {
       
   454             HBufC8* iapList = iAdapter->GetIapListL( ids );
       
   455             CleanupStack::PushL( iapList );
       
   456             aCmd.SetDataL( *iapList );
       
   457             CleanupStack::PopAndDestroy( iapList );
       
   458             }
       
   459         else
       
   460             {
       
   461             aCmd.SetDataL( KNullDesC8 );
       
   462             }
       
   463         CleanupStack::PopAndDestroy( &ids );
       
   464         // for size command, set the command data to be the 
       
   465         // size of the fetched data
       
   466         if( aCmd.CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   467             {
       
   468             HBufC8* size = iAdapter->IntToDes8L( aCmd.Data()->Size() );
       
   469             CleanupStack::PushL( size );
       
   470             aCmd.SetDataL( *size );
       
   471             CleanupStack::PopAndDestroy( size );
       
   472             }
       
   473         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   474         aCmd.SetExecuted( ETrue );
       
   475         }
       
   476     else
       
   477         {
       
   478         // unsupported command
       
   479         // this is checked by framework
       
   480         aCmd.SetStatus( CSmlDmAdapter::EError );
       
   481         BMADAPTERLOGSTRING( "ExecuteIapsCmdL: Error, Only Add, Get and Get size commands supported" )
       
   482         }
       
   483     }
       
   484 
       
   485 // ---------------------------------------------------------------------------
       
   486 // CNSmlDmBmSettingStore::ExecuteProtectionCmdL
       
   487 // Executes an protected command (add or get).
       
   488 // ---------------------------------------------------------------------------
       
   489 //
       
   490 void CNSmlDmBmSettingStore::ExecuteProtectionCmdL( CSmlDmBmCommandElement& aCmd, 
       
   491                                                    RCmDestinationExt& aSnap )
       
   492     {
       
   493     if ( aCmd.CmdType() == CNSmlDmBmAdapter::EAddCmd )
       
   494         {
       
   495         __UHEAP_MARK;
       
   496         TInt data( iAdapter->DesToIntL( *aCmd.Data() ) );
       
   497         // is proper protection level
       
   498         if ( data == CMManager::EProtLevel0 )
       
   499             {
       
   500             aSnap.SetProtectionL( CMManager::EProtLevel0 );
       
   501             aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   502             }
       
   503         else if ( data == CMManager::EProtLevel1 )
       
   504             {
       
   505             aSnap.SetProtectionL( CMManager::EProtLevel1 );
       
   506             aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   507             }
       
   508         else if ( data == CMManager::EProtLevel2 )
       
   509             {
       
   510             aSnap.SetProtectionL( CMManager::EProtLevel2 );
       
   511             aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   512             }
       
   513         else
       
   514             {
       
   515             aCmd.SetStatus( CSmlDmAdapter::EInvalidObject );
       
   516             }
       
   517         __UHEAP_MARKEND;
       
   518         }
       
   519     else if ( aCmd.CmdType() == CNSmlDmBmAdapter::EGetCmd ||
       
   520               aCmd.CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   521         {
       
   522         HBufC8* data = iAdapter->IntToDes8L( aSnap.ProtectionLevel() );
       
   523         CleanupStack::PushL( data );
       
   524         aCmd.SetDataL( *data );
       
   525         CleanupStack::PopAndDestroy( data );
       
   526         
       
   527         // for size command, set the command data to be the 
       
   528         // size of the fetched data
       
   529         if( aCmd.CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   530             {
       
   531             HBufC8* size = iAdapter->IntToDes8L( aCmd.Data()->Size() );
       
   532             CleanupStack::PushL( size );
       
   533             aCmd.SetDataL( *size );
       
   534             CleanupStack::PopAndDestroy( size );
       
   535             }
       
   536 
       
   537         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   538         aCmd.SetExecuted( ETrue );
       
   539         }
       
   540     else
       
   541         {
       
   542         // unsupported command
       
   543         // this is checked by framework
       
   544         aCmd.SetStatus( CSmlDmAdapter::EError );
       
   545         BMADAPTERLOGSTRING( "ExecuteProtectionCmdL: Error, Only Add, Get and Get size commands supported" )
       
   546         }
       
   547     }
       
   548 
       
   549 // ---------------------------------------------------------------------------
       
   550 // CNSmlDmBmSettingStore::ExecuteHiddenCmdL
       
   551 // Executes hidden command (add or get)
       
   552 // ---------------------------------------------------------------------------
       
   553 //
       
   554 void CNSmlDmBmSettingStore::ExecuteHiddenCmdL( CSmlDmBmCommandElement& aCmd, 
       
   555                                                RCmDestinationExt& aSnap )
       
   556     {
       
   557     if ( aCmd.CmdType() == CNSmlDmBmAdapter::EAddCmd )
       
   558         {
       
   559         __UHEAP_MARK;
       
   560         TBool data; 
       
   561         if( iAdapter->DesToBool( *aCmd.Data(), data ) )
       
   562             {
       
   563             aSnap.SetHiddenL( data );
       
   564             aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   565             }
       
   566         else
       
   567             {
       
   568             aCmd.SetStatus( CSmlDmAdapter::EInvalidObject );
       
   569             }
       
   570         __UHEAP_MARKEND;
       
   571         }
       
   572     else if ( aCmd.CmdType() == CNSmlDmBmAdapter::EGetCmd ||
       
   573               aCmd.CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   574         {
       
   575         HBufC8* data = iAdapter->BoolToDes8LC( aSnap.IsHidden() );
       
   576         aCmd.SetDataL( *data );
       
   577         CleanupStack::PopAndDestroy( data ); 
       
   578         // for size command, set the command data to be the 
       
   579         // size of the fetched data
       
   580         if( aCmd.CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   581             {
       
   582             HBufC8* size = iAdapter->IntToDes8L( aCmd.Data()->Size() );
       
   583             CleanupStack::PushL( size );
       
   584             aCmd.SetDataL( *size );
       
   585             CleanupStack::PopAndDestroy( size );
       
   586             }
       
   587         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   588         aCmd.SetExecuted( ETrue );
       
   589         }
       
   590     else
       
   591         {
       
   592         // unsupported command
       
   593         // this is checked by framework
       
   594         aCmd.SetStatus( CSmlDmAdapter::EError );
       
   595         BMADAPTERLOGSTRING( "ExecuteHiddenCmdL: Error, Only Add, Get and Get size commands supported" )
       
   596         }
       
   597     }
       
   598 
       
   599 // ---------------------------------------------------------------------------
       
   600 // CNSmlDmBmSettingStore::ExecuteMetadataCmdL
       
   601 // Executes metadata command (add or get)
       
   602 // ---------------------------------------------------------------------------
       
   603 //
       
   604 void CNSmlDmBmSettingStore::ExecuteMetadataCmdL( CSmlDmBmCommandElement& aCmd, 
       
   605                                                  RCmDestinationExt& aSnap )
       
   606     {
       
   607     if ( aCmd.CmdType() == CNSmlDmBmAdapter::EAddCmd )
       
   608         {
       
   609         __UHEAP_MARK;
       
   610         
       
   611         TInt data( iAdapter->DesToIntL( *aCmd.Data() ) );
       
   612         // AND with inversed bit masks to check if data 
       
   613         // has bits set that are not defined for metadata
       
   614         if( ( data & 
       
   615               ~CMManager::ESnapMetadataHighlight &
       
   616               ~CMManager::ESnapMetadataHiddenAgent & 
       
   617               ~CMManager::ESnapMetadataPurpose ) )
       
   618             {
       
   619             aCmd.SetStatus( CSmlDmAdapter::EError );
       
   620             }
       
   621         // set value for each metadata bit
       
   622         else
       
   623             {
       
   624             aSnap.SetMetadataL( CMManager::ESnapMetadataHighlight, 
       
   625                                 CMManager::ESnapMetadataHighlight & data );
       
   626             aSnap.SetMetadataL( CMManager::ESnapMetadataHiddenAgent, 
       
   627                                 CMManager::ESnapMetadataHiddenAgent & data );
       
   628             aSnap.SetMetadataL( CMManager::ESnapMetadataPurpose, 
       
   629                               ( CMManager::ESnapMetadataPurpose & data ) >> KShift8 );
       
   630             aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   631             }
       
   632         __UHEAP_MARKEND;
       
   633         }
       
   634     else if ( aCmd.CmdType() == CNSmlDmBmAdapter::EGetCmd ||
       
   635               aCmd.CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   636         {
       
   637         // get all metadata values
       
   638         TInt metadata(0);
       
   639         metadata = aSnap.MetadataL( CMManager::ESnapMetadataHighlight ) +
       
   640                    aSnap.MetadataL( CMManager::ESnapMetadataHiddenAgent ) + 
       
   641                  ( aSnap.MetadataL( CMManager::ESnapMetadataPurpose ) << KShift8 );
       
   642         HBufC8* data = iAdapter->IntToDes8L( metadata );
       
   643         CleanupStack::PushL( data );
       
   644         aCmd.SetDataL( *data ); 
       
   645         CleanupStack::PopAndDestroy( data );
       
   646         
       
   647         // for size command, set the command data to be the 
       
   648         // size of the fetched data
       
   649         if( aCmd.CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   650             {
       
   651             HBufC8* size = iAdapter->IntToDes8L( aCmd.Data()->Size() );
       
   652             CleanupStack::PushL( size );
       
   653             aCmd.SetDataL( *size );
       
   654             CleanupStack::PopAndDestroy( size );
       
   655             }
       
   656         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   657         aCmd.SetExecuted( ETrue );
       
   658         }
       
   659     else
       
   660         {
       
   661         // unsupported command
       
   662         // this is checked by framework
       
   663         aCmd.SetStatus( CSmlDmAdapter::EError );
       
   664         BMADAPTERLOGSTRING( "ExecuteMetadataCmdL: Error, Only Add, Get and Get size commands supported" )
       
   665         }
       
   666     }
       
   667 
       
   668 // ---------------------------------------------------------------------------
       
   669 // CNSmlDmBmSettingStore::ExecuteEmbeddedSnapCmdL
       
   670 // Executes embedded snap command (add, get or delete)
       
   671 // ---------------------------------------------------------------------------
       
   672 //
       
   673 void CNSmlDmBmSettingStore::ExecuteEmbeddedSnapCmdL( CSmlDmBmCommandElement& aCmd, 
       
   674                                                      RCmDestinationExt& aSnap )
       
   675     {
       
   676     if ( aCmd.CmdType() == CNSmlDmBmAdapter::EAddCmd )
       
   677         {
       
   678         // Remove ./ from beginning of the URI
       
   679         TPtrC8 embeddedUri = aCmd.Data()->Mid( KNSmlDmBmAdapterURIPrefix().Length() );
       
   680 
       
   681         // if the embedded snap is still in buffer it's stored here
       
   682         iAdapter->StoreSnapIfBufferedL( embeddedUri );
       
   683         // LUID mapping is assumed done by this time
       
   684 
       
   685         // get SNAP id for the URI 
       
   686         HBufC8* luid = iAdapter->GetLuidAllocL( embeddedUri );
       
   687         CleanupStack::PushL( luid );
       
   688         if ( luid->Size() > 0 )
       
   689             {
       
   690             TInt id = iAdapter->DesToIntL( *luid );
       
   691 
       
   692             // open snap with the id
       
   693             RCmDestinationExt embedded = iCmManagerExt.DestinationL( id );
       
   694             CleanupClosePushL( embedded );
       
   695 
       
   696             // check if snap has an existing embedded snap                       
       
   697             for ( TInt i(0), c = aSnap.ConnectionMethodCount(); i < c; i++ )
       
   698                 {
       
   699                 RCmConnectionMethodExt cm = aSnap.ConnectionMethodL( i );
       
   700                 // remove existing embedded snap before adding new one
       
   701                 if ( cm.GetBoolAttributeL( CMManager::ECmDestination ) )
       
   702                     {
       
   703                     aSnap.DeleteConnectionMethodL( cm );
       
   704                     break;
       
   705                 }
       
   706             }
       
   707             aSnap.AddEmbeddedDestinationL( embedded ); 
       
   708             CleanupStack::PopAndDestroy( &embedded );
       
   709             aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   710             }
       
   711         else
       
   712             {
       
   713             // no luid for the uri
       
   714             BMADAPTERLOGSTRING( "ExecuteEmbeddedSnapCmdL: No LUID found for embedded snap" )
       
   715             aCmd.SetStatus( CSmlDmAdapter::EInvalidObject );
       
   716             }
       
   717         aCmd.SetExecuted( ETrue );
       
   718         CleanupStack::PopAndDestroy( luid );
       
   719         }
       
   720     else if ( aCmd.CmdType() == CNSmlDmBmAdapter::EGetCmd ||
       
   721               aCmd.CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   722         {
       
   723         // get destination
       
   724         TInt embeddedId( -1 );
       
   725         for ( TInt i( 0 ), c = aSnap.ConnectionMethodCount(); i < c; i++ )
       
   726             {
       
   727             RCmConnectionMethodExt cm = aSnap.ConnectionMethodL( i );
       
   728             // check if embedded
       
   729             if ( cm.GetBoolAttributeL( CMManager::ECmDestination ) )
       
   730                 {
       
   731                 // get snap id
       
   732                 embeddedId = cm.GetIntAttributeL( CMManager::ECmId );
       
   733 
       
   734                 // CMManager::ECmId returns element id, 
       
   735                 // GetSnapUriFromLuidL needs record id
       
   736                 embeddedId = ( embeddedId & KCDMaskShowRecordId ) >> KShift8;
       
   737 
       
   738                 HBufC8* embeddedUri = iAdapter->GetSnapUriFromLuidL( embeddedId );
       
   739                 CleanupStack::PushL( embeddedUri );
       
   740                 
       
   741                 if( !embeddedUri )
       
   742                     {
       
   743                     embeddedId = -1;
       
   744                     break;
       
   745                     }
       
   746                 aCmd.SetDataL( *embeddedUri );
       
   747                 CleanupStack::PopAndDestroy( embeddedUri );
       
   748                 
       
   749                 // for size command, set the command data to be the 
       
   750                 // size of the fetched data
       
   751                 if( aCmd.CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   752                     {
       
   753                     HBufC8* size = iAdapter->IntToDes8L( aCmd.Data()->Size() );
       
   754                     CleanupStack::PushL( size );
       
   755                     aCmd.SetDataL( *size );
       
   756                     CleanupStack::PopAndDestroy( size );
       
   757                     }
       
   758                 aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   759                 aCmd.SetExecuted( ETrue );
       
   760                 break;
       
   761                 }
       
   762             }
       
   763         // if no embedded snap exists return not found
       
   764         if ( embeddedId < 0 )
       
   765             {
       
   766             BMADAPTERLOGSTRING( "ExecuteEmbeddedSnapCmdL: Get, No embedded snap found" )
       
   767             aCmd.SetStatus( CSmlDmAdapter::ENotFound );
       
   768             aCmd.SetExecuted( ETrue );
       
   769             }
       
   770         }
       
   771     else if ( aCmd.CmdType() == CNSmlDmBmAdapter::EDeleteCmd )
       
   772         {
       
   773         TBool found( EFalse);
       
   774         for ( TInt i( 0 ), c = aSnap.ConnectionMethodCount(); i < c; i++ )
       
   775             {
       
   776             RCmConnectionMethodExt cm = aSnap.ConnectionMethodL( i );
       
   777             // find embedded snap and delete it
       
   778             if ( cm.GetBoolAttributeL( CMManager::ECmDestination ) )
       
   779                 {
       
   780                 found = ETrue;
       
   781                 aSnap.DeleteConnectionMethodL( cm );
       
   782                 aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   783                 break;
       
   784                 }
       
   785             }
       
   786         if ( !found )
       
   787             {
       
   788             BMADAPTERLOGSTRING( "ExecuteEmbeddedSnapCmdL: Delete, No embedded snap found" )
       
   789             aCmd.SetStatus( CSmlDmAdapter::ENotFound );
       
   790             aCmd.SetExecuted( ETrue );
       
   791             }
       
   792         }
       
   793     else    
       
   794         {
       
   795         // unsupported command
       
   796         // this is checked by framework
       
   797         aCmd.SetStatus( CSmlDmAdapter::EError );
       
   798         aCmd.SetExecuted( ETrue );
       
   799         BMADAPTERLOGSTRING( "ExecuteEmbeddedSnapCmdL: Error, command not supported" )
       
   800         }
       
   801     }
       
   802 
       
   803 // ---------------------------------------------------------------------------
       
   804 // CNSmlDmBmSettingStore::ExecuteNameCmdL
       
   805 // Executes name command (add or get )
       
   806 // ---------------------------------------------------------------------------
       
   807 //
       
   808 void CNSmlDmBmSettingStore::ExecuteNameCmdL( CSmlDmBmCommandElement& aCmd, 
       
   809                                              RCmDestinationExt& aSnap )
       
   810     {
       
   811     if ( aCmd.CmdType() == CNSmlDmBmAdapter::EAddCmd )
       
   812         {
       
   813         HBufC* name = HBufC::NewLC( aCmd.Data()->Size() );
       
   814         TPtr namePtr = name->Des();
       
   815         CnvUtfConverter::ConvertToUnicodeFromUtf8( namePtr, *aCmd.Data() );
       
   816         aSnap.SetNameL( namePtr );
       
   817         CleanupStack::PopAndDestroy( name );
       
   818         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   819         }
       
   820     else if ( aCmd.CmdType() == CNSmlDmBmAdapter::EGetCmd ||
       
   821               aCmd.CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   822         {
       
   823         HBufC* data = aSnap.NameLC();
       
   824         HBufC8* data8 = HBufC8::NewLC( data->Size() );
       
   825         TPtr8 toPtr = data8->Des();
       
   826         CnvUtfConverter::ConvertFromUnicodeToUtf8( toPtr, *data );
       
   827         aCmd.SetDataL( *data8 );
       
   828         CleanupStack::PopAndDestroy( data8 );
       
   829         CleanupStack::PopAndDestroy( data );
       
   830        
       
   831         // for size command, set the command data to be the 
       
   832         // size of the fetched data
       
   833         if( aCmd.CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   834             {
       
   835             HBufC8* size = iAdapter->IntToDes8L( aCmd.Data()->Size() );
       
   836             CleanupStack::PushL( size );
       
   837             aCmd.SetDataL( *size );
       
   838             CleanupStack::PopAndDestroy( size );
       
   839             }
       
   840         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   841         aCmd.SetExecuted( ETrue );
       
   842         }
       
   843     else    
       
   844         {
       
   845         // unsupported command
       
   846         // this is checked by framework
       
   847         aCmd.SetStatus( CSmlDmAdapter::EError );
       
   848         BMADAPTERLOGSTRING( "ExecuteEmbeddedSnapCmdL: Error, Only Add, Get and Get size commands supported" )
       
   849         }
       
   850     }
       
   851