omadm/omadmextensions/adapters/nsmldmbmadapter/src/nsmldmbmadapter.cpp
changeset 1 4490afcb47b1
equal deleted inserted replaced
0:3ce708148e4d 1:4490afcb47b1
       
     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:   Bearer management DM adapter. Provides handling of 
       
    15                 Bearer management related settings in Device management
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <ecom/implementationproxy.h>
       
    22 #include <cmdestinationext.h>
       
    23 
       
    24 #include "nsmldmbmadapter.h"
       
    25 #include "bmadapterlogger.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 
       
    30 // --------------------------------------------------------------------------
       
    31 // Maps plugin UID to its factory function (constructor)
       
    32 // --------------------------------------------------------------------------
       
    33 const TImplementationProxy ImplementationTable[] =
       
    34     {
       
    35     IMPLEMENTATION_PROXY_ENTRY(0x101f6d2f, 
       
    36                                CNSmlDmBmAdapter::NewL)
       
    37     };
       
    38 
       
    39 // --------------------------------------------------------------------------
       
    40 // For ecom plugin implementation
       
    41 // -------------------------------------------------------------------------
       
    42 
       
    43 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
    44     {
       
    45     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
    46     return ImplementationTable;
       
    47     }
       
    48 
       
    49 // --------------------------------------------------------------------------
       
    50 // CNSmlDmBmAdapter::NewL
       
    51 // --------------------------------------------------------------------------
       
    52 CNSmlDmBmAdapter* CNSmlDmBmAdapter::NewL( MSmlDmCallback* aDmCallback )
       
    53     {
       
    54     BMADAPTERLOGSTRING("CNSmlDmBmAdapter::NewL: Start")
       
    55     CNSmlDmBmAdapter* self = new (ELeave) CNSmlDmBmAdapter( aDmCallback );
       
    56     CleanupStack::PushL(self);
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     BMADAPTERLOGSTRING("CNSmlDmBmAdapter::NewL: End")
       
    60     return self;
       
    61     }
       
    62 
       
    63 // --------------------------------------------------------------------------
       
    64 // CNSmlDmBmAdapter::CNSmlDmBmAdapter
       
    65 // --------------------------------------------------------------------------
       
    66 
       
    67 CNSmlDmBmAdapter::CNSmlDmBmAdapter( MSmlDmCallback* aDmCallback ) 
       
    68     : CSmlDmAdapter( aDmCallback )
       
    69     {
       
    70     }
       
    71 
       
    72 // --------------------------------------------------------------------------
       
    73 // CNSmlDmBmAdapter::ConstructL
       
    74 // --------------------------------------------------------------------------
       
    75 void CNSmlDmBmAdapter::ConstructL()
       
    76     {
       
    77     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::CNSmlDmBmAdapter: Start" )
       
    78     iSettingStore = CNSmlDmBmSettingStore::NewL( this );
       
    79     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::CNSmlDmBmAdapter: End" )
       
    80     }
       
    81 
       
    82 // --------------------------------------------------------------------------
       
    83 // CNSmlDmBmAdapter::~CNSmlDmBmAdapter
       
    84 // --------------------------------------------------------------------------
       
    85 CNSmlDmBmAdapter::~CNSmlDmBmAdapter()
       
    86     {
       
    87     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::~CNSmlDmBmAdapter: Start" )
       
    88     iBuffer.ResetAndDestroy();
       
    89     iBuffer.Close();
       
    90     delete iSettingStore;
       
    91     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::~CNSmlDmBmAdapter: End" )
       
    92     }
       
    93     
       
    94 // --------------------------------------------------------------------------
       
    95 // CNSmlDmBmAdapter::DDFVersionL
       
    96 // Returns ddf version nr
       
    97 // --------------------------------------------------------------------------
       
    98 void CNSmlDmBmAdapter::DDFVersionL( CBufBase& aDDFVersion )
       
    99     {
       
   100     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::DDFVersionL: Start" )
       
   101     aDDFVersion.InsertL( 0, KNSmlDmBMAdapterDDFVersion );
       
   102     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::DDFVersionL:End" )
       
   103     }
       
   104    
       
   105 // --------------------------------------------------------------------------
       
   106 // CNSmlDmBmAdapter::DDFStructureL
       
   107 //  Constructs the DDF structure
       
   108 // --------------------------------------------------------------------------
       
   109 void CNSmlDmBmAdapter::DDFStructureL( MSmlDmDDFObject& aDDF )
       
   110     {
       
   111     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::DDFStructureL: Start" )
       
   112     TSmlDmAccessTypes accessTypes;
       
   113 
       
   114     // BearerManagementSNAP
       
   115     MSmlDmDDFObject& bm = aDDF.AddChildObjectL( KNSmlDmBMAdapterBM );
       
   116     accessTypes.SetGet();
       
   117     accessTypes.SetAdd();
       
   118     bm.SetAccessTypesL( accessTypes );
       
   119     bm.SetOccurenceL( MSmlDmDDFObject::EOne );
       
   120     bm.SetScopeL( MSmlDmDDFObject::EPermanent );
       
   121     bm.SetDFFormatL( MSmlDmDDFObject::ENode );
       
   122     bm.AddDFTypeMimeTypeL( KNSmlDmBMAdapterTextPlain );
       
   123     bm.SetDescriptionL( KNSmlDmBMAdapterBMDescription );
       
   124     accessTypes.Reset();
       
   125 
       
   126     
       
   127     // BearerManagementSNAP/<X>
       
   128     MSmlDmDDFObject& dynamic1 = bm.AddChildObjectGroupL();
       
   129     accessTypes.SetAdd();
       
   130     accessTypes.SetDelete();
       
   131     accessTypes.SetGet();
       
   132     accessTypes.SetReplace();
       
   133     dynamic1.SetAccessTypesL( accessTypes );
       
   134     dynamic1.SetOccurenceL( MSmlDmDDFObject::EZeroOrMore );
       
   135     dynamic1.SetScopeL( MSmlDmDDFObject::EDynamic );
       
   136     dynamic1.SetDFFormatL( MSmlDmDDFObject::ENode );
       
   137     dynamic1.AddDFTypeMimeTypeL( KNSmlDmBMAdapterTextPlain );
       
   138     dynamic1.SetDescriptionL( KNSmlDmBMAdapterDynamicDescription );
       
   139     accessTypes.Reset();
       
   140 
       
   141 
       
   142     // BearerManagementSNAP/<X>/Name
       
   143     MSmlDmDDFObject& name = dynamic1.AddChildObjectL( KNSmlDmBMAdapterName );
       
   144     accessTypes.SetAdd();
       
   145     accessTypes.SetGet();
       
   146     accessTypes.SetReplace();
       
   147     name.SetAccessTypesL( accessTypes );
       
   148     name.SetOccurenceL( MSmlDmDDFObject::EOne );
       
   149     name.SetScopeL( MSmlDmDDFObject::EDynamic );
       
   150     name.SetDFFormatL( MSmlDmDDFObject::EChr );
       
   151     name.SetDescriptionL( KNSmlDmBMAdapterNameDescription );
       
   152     accessTypes.Reset();
       
   153 
       
   154     // BearerManagementSNAP/<X>/IAPPrioityList
       
   155     MSmlDmDDFObject& iapList = 
       
   156     dynamic1.AddChildObjectL( KNSmlDmBMAdapterIAPPriorityList );
       
   157     accessTypes.SetAdd();
       
   158     accessTypes.SetGet();
       
   159     accessTypes.SetReplace();
       
   160     iapList.SetAccessTypesL( accessTypes );
       
   161     iapList.SetOccurenceL( MSmlDmDDFObject::EOne );
       
   162     iapList.SetScopeL( MSmlDmDDFObject::EDynamic );
       
   163     iapList.SetDFFormatL( MSmlDmDDFObject::EChr );
       
   164     iapList.SetDescriptionL( KNSmlDmBMAdapterIAPPriorityListDescription );
       
   165     accessTypes.Reset();
       
   166         
       
   167     // BearerManagementSNAP/<X>/EmbeddedSNAP
       
   168     MSmlDmDDFObject& embedded = 
       
   169     dynamic1.AddChildObjectL( KNSmlDmBMAdapterEmbeddedSNAP );
       
   170     accessTypes.SetAdd();
       
   171     accessTypes.SetDelete();
       
   172     accessTypes.SetGet();
       
   173     accessTypes.SetReplace();
       
   174     embedded.SetAccessTypesL( accessTypes );
       
   175     embedded.SetOccurenceL( MSmlDmDDFObject::EZeroOrOne );
       
   176     embedded.SetScopeL( MSmlDmDDFObject::EDynamic );
       
   177     embedded.SetDFFormatL( MSmlDmDDFObject::EChr );
       
   178     embedded.SetDescriptionL( KNSmlDmBMAdapterEmbeddedSNAPDescription );
       
   179     accessTypes.Reset();
       
   180 
       
   181     // BearerManagementSNAP/<X>/Metadata
       
   182     MSmlDmDDFObject& metadata = 
       
   183     dynamic1.AddChildObjectL( KNSmlDmBMAdapterMetadata );
       
   184     accessTypes.SetAdd();
       
   185     accessTypes.SetGet();
       
   186     accessTypes.SetReplace();
       
   187     metadata.SetAccessTypesL( accessTypes );
       
   188     metadata.SetOccurenceL( MSmlDmDDFObject::EOne );
       
   189     metadata.SetScopeL( MSmlDmDDFObject::EDynamic );
       
   190     metadata.SetDFFormatL( MSmlDmDDFObject::EInt );
       
   191     metadata.SetDescriptionL( KNSmlDmBMAdapterMetadataDescription );
       
   192     accessTypes.Reset();
       
   193  
       
   194  
       
   195     // BearerManagementSNAP/<X>/Protected
       
   196     MSmlDmDDFObject& protection = 
       
   197     dynamic1.AddChildObjectL( KNSmlDmBMAdapterProtected );
       
   198     accessTypes.SetAdd();
       
   199     accessTypes.SetGet();
       
   200     accessTypes.SetReplace();
       
   201     protection.SetAccessTypesL( accessTypes );
       
   202     protection.SetOccurenceL( MSmlDmDDFObject::EOne );
       
   203     protection.SetScopeL( MSmlDmDDFObject::EDynamic );
       
   204     protection.SetDFFormatL( MSmlDmDDFObject::EInt );
       
   205     protection.SetDescriptionL( KNSmlDmBMAdapterProtectedDescription );
       
   206     accessTypes.Reset(); 
       
   207     
       
   208     // BearerManagementSNAP/<X>/Hidden
       
   209     MSmlDmDDFObject& hidden = dynamic1.AddChildObjectL( KNSmlDmBMAdapterHidden );
       
   210     accessTypes.SetAdd();
       
   211     accessTypes.SetGet();
       
   212     accessTypes.SetReplace();
       
   213     hidden.SetAccessTypesL( accessTypes );
       
   214     hidden.SetOccurenceL( MSmlDmDDFObject::EOne );
       
   215     hidden.SetScopeL( MSmlDmDDFObject::EDynamic );
       
   216     hidden.SetDFFormatL( MSmlDmDDFObject::EBool );
       
   217     hidden.SetDescriptionL( KNSmlDmBMAdapterHiddenDescription );
       
   218     accessTypes.Reset(); 
       
   219     
       
   220     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::DDFStructureL: End" )
       
   221     }
       
   222 
       
   223 // -------------------------------------------------------------------------
       
   224 // CNSmlDmBmAdapter::UpdateLeafObjectL
       
   225 //  Adds or updates leaf node value. If snap object is 
       
   226 //  in buffer this command is also buffered. Also if leaf node 
       
   227 //  is embedded snap and that snap is buffered, the argument command
       
   228 //  is buffered.
       
   229 // -------------------------------------------------------------------------
       
   230 void CNSmlDmBmAdapter::UpdateLeafObjectL( const TDesC8& aURI, 
       
   231                                           const TDesC8& aLUID, 
       
   232                                           const TDesC8& aObject, 
       
   233                                           const TDesC8& /*aType*/, 
       
   234                                           TInt aStatusRef )
       
   235     {
       
   236     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::UpdateLeafObjectL: Start" )
       
   237     BMADAPTERLOGSTRING4( "\tUpdateLeafObjectL  \tURI: %S, \n\tLUID: %S,\
       
   238                          \tobject: %S ", 
       
   239                         &aURI, &aLUID, &aObject )
       
   240 
       
   241     TInt snapId = MapPredefinedSnapsL( aURI, aLUID );
       
   242                         
       
   243     // Check if parent snap node is found in the buffered settings
       
   244     CSmlDmBmSettingsElement* snap = 
       
   245     GetSnapIfBuffered( RemoveLastURISeg( aURI ) );
       
   246 
       
   247     // data for buffered SNAP -> Store command into buffer    
       
   248     if ( snap )
       
   249         {
       
   250         CSmlDmBmCommandElement* cmd = 
       
   251         CSmlDmBmCommandElement::NewLC( ETrue, 
       
   252                                        aStatusRef,
       
   253                                        KNSmlDmBmInvalidRef, 
       
   254                                        CNSmlDmBmAdapter::EAddCmd,
       
   255                                        LastURISeg( aURI ), 
       
   256                                        aObject);
       
   257         snap->NodeBuf().AppendL(cmd);
       
   258         CleanupStack::Pop( cmd );
       
   259         BMADAPTERLOGSTRING2( "\tSnap %S found, buffering cmd", 
       
   260                             snap->MappingName() )
       
   261 
       
   262         }
       
   263     // updates for an existing SNAP
       
   264     else
       
   265         {
       
   266 
       
   267         // If setting embedded SNAP node and the embedded SNAP node is still 
       
   268         // buffered -> Buffer also this command
       
   269         if( !LastURISeg( aURI ).Compare( KNSmlDmBMAdapterEmbeddedSNAP ) )
       
   270             {
       
   271             snap = GetSnapIfBuffered( aObject );
       
   272 
       
   273                 // embedded SNAP is buffered
       
   274                 if ( snap )
       
   275                     {
       
   276                     CSmlDmBmCommandElement* cmd = 
       
   277                     CSmlDmBmCommandElement::NewLC( ETrue, 
       
   278                                                    aStatusRef,
       
   279                                                    KNSmlDmBmInvalidRef, 
       
   280                                                    CNSmlDmBmAdapter::EAddCmd,
       
   281                                                    LastURISeg( aURI ), 
       
   282                                                    aObject);
       
   283 
       
   284                     // buffer this command
       
   285                     CSmlDmBmSettingsElement* setting = 
       
   286                     CSmlDmBmSettingsElement::NewLC( RemoveLastURISeg( aURI ) );
       
   287                     
       
   288                     // Check if SNAP was predefined or not
       
   289                     if( snapId == KErrNotFound )
       
   290                         {
       
   291                         snapId = DesToIntL( aLUID );
       
   292                         }
       
   293                     setting->SetLuid( snapId );
       
   294                     iBuffer.AppendL( setting );
       
   295                     CleanupStack::Pop( setting );
       
   296                     setting->NodeBuf().AppendL(cmd);
       
   297                     CleanupStack::Pop( cmd );
       
   298                     BMADAPTERLOGSTRING2( "\tEmbedded Snap %S buffered, buffering cmd", 
       
   299                                          snap->MappingName() )
       
   300                     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::UpdateLeafObjectL: End" )
       
   301                     return;
       
   302                     }
       
   303             }
       
   304         // execute command and return status  
       
   305         CSmlDmBmCommandElement* cmd = 
       
   306         CSmlDmBmCommandElement::NewLC( ETrue, 
       
   307                                        aStatusRef,
       
   308                                        KNSmlDmBmInvalidRef, 
       
   309                                        CNSmlDmBmAdapter::EAddCmd,
       
   310                                        LastURISeg( aURI ), 
       
   311                                        aObject);
       
   312         if( snapId == KErrNotFound )
       
   313             {
       
   314             snapId = DesToIntL( aLUID );
       
   315             }
       
   316         iSettingStore->ExecuteCmdL( *cmd, snapId );
       
   317         BMADAPTERLOGSTRING2( "\tCmd executed with status: %d", 
       
   318                               cmd->Status() )
       
   319         Callback().SetStatusL( aStatusRef, cmd->Status() );
       
   320         CleanupStack::PopAndDestroy( cmd );
       
   321 
       
   322         }
       
   323     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::UpdateLeafObjectL: End" )
       
   324     }
       
   325 // --------------------------------------------------------------------------
       
   326 // CNSmlDmBmAdapter::DeleteObjectL
       
   327 //  Deletes node or leaf object. If the snap this command relates to is
       
   328 //  buffered, also the delete command is buffered.
       
   329 // --------------------------------------------------------------------------
       
   330 
       
   331 void CNSmlDmBmAdapter::DeleteObjectL( const TDesC8& aURI, 
       
   332                                       const TDesC8& aLUID,
       
   333                                       TInt aStatusRef )
       
   334     {
       
   335     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::DeleteObjectL: Start" )
       
   336     BMADAPTERLOGSTRING3( "\tDeleteObjectL  \tURI: %S, \tLUID: %S", 
       
   337                          &aURI, &aLUID )
       
   338     
       
   339     CSmlDmBmCommandElement* cmd;
       
   340     
       
   341     TInt snapId = MapPredefinedSnapsL( aURI, aLUID );
       
   342     // check if node or leaf object and create command accordingly
       
   343     // when updating, make sure that cmd is constructed
       
   344     if ( NumOfURISegs( aURI  ) == KNsmlDmBmSNAPNodeDepth )
       
   345         {
       
   346         cmd = CSmlDmBmCommandElement::NewLC( EFalse, 
       
   347                                              aStatusRef,
       
   348                                              KNSmlDmBmInvalidRef, 
       
   349                                              CNSmlDmBmAdapter::EDeleteCmd,
       
   350                                              KNullDesC8, KNullDesC8 );
       
   351         }
       
   352     else if ( ! LastURISeg( aURI ).Compare( KNSmlDmBMAdapterEmbeddedSNAP() ) )
       
   353         {
       
   354         cmd = CSmlDmBmCommandElement::NewLC( ETrue, 
       
   355                                              aStatusRef,
       
   356                                              KNSmlDmBmInvalidRef, 
       
   357                                              CNSmlDmBmAdapter::EDeleteCmd,
       
   358                                              LastURISeg( aURI ), 
       
   359                                              KNullDesC8 );
       
   360         }
       
   361     else
       
   362         {
       
   363         // unsupported node, framework should check this
       
   364         Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   365         BMADAPTERLOGSTRING( "\tCNSmlDmBmAdapter::DeleteObjectL: \
       
   366         Error, unsupported node" )
       
   367         return;
       
   368         }
       
   369 
       
   370     // If this SNAP still in buffer -> buffer command for later execution
       
   371     // Check if SNAP is found in the buffered settings
       
   372     CSmlDmBmSettingsElement* snap = NULL;
       
   373     if( cmd->Leaf() )
       
   374         {
       
   375         snap = GetSnapIfBuffered( RemoveLastURISeg( aURI ) );
       
   376         }
       
   377     else
       
   378         {
       
   379         snap = GetSnapIfBuffered( aURI );
       
   380         }
       
   381     // when updating make sure that cmd is removed from cleanup 
       
   382     // stack and deleted if necessary
       
   383     
       
   384     // if cmd for buffered snap append cmd to buffer
       
   385     if ( snap )
       
   386         {
       
   387         snap->NodeBuf().AppendL( cmd );
       
   388         CleanupStack::Pop( cmd );
       
   389         BMADAPTERLOGSTRING2( "\tSnap %S found, buffering cmd", 
       
   390                             snap->MappingName() )
       
   391         }
       
   392     // if existing node, execute command
       
   393     else if( aLUID.Length() > 0 || snapId != KErrNotFound )
       
   394         {
       
   395         if( snapId == KErrNotFound )
       
   396             {
       
   397             snapId = DesToIntL( aLUID );
       
   398             }
       
   399         iSettingStore->ExecuteCmdL( *cmd, snapId );
       
   400         BMADAPTERLOGSTRING2( "\tCmd executed with status: %d ", 
       
   401                               cmd->Status() )
       
   402         Callback().SetStatusL( aStatusRef, cmd->Status() );
       
   403         CleanupStack::PopAndDestroy( cmd );
       
   404         }
       
   405         // unknown node    
       
   406     else
       
   407         {
       
   408         BMADAPTERLOGSTRING( "\tUnknown node\n" )
       
   409         Callback().SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   410         CleanupStack::PopAndDestroy( cmd );
       
   411         }
       
   412     
       
   413     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::DeleteObjectL: End" )
       
   414     }
       
   415 // -------------------------------------------------------------------------
       
   416 // CNSmlDmBmAdapter::FetchLeafObjectL
       
   417 //  Fetches leaf object value. If the snap is buffered also this command 
       
   418 //  will
       
   419 //  be buffered.
       
   420 // -------------------------------------------------------------------------
       
   421 void CNSmlDmBmAdapter::FetchLeafObjectL( const TDesC8& aURI, 
       
   422                                          const TDesC8& aLUID, 
       
   423                                          const TDesC8& /*aType*/, 
       
   424                                          const TInt aResultsRef, 
       
   425                                          const TInt aStatusRef )
       
   426     {
       
   427     BMADAPTERLOGSTRING( "NSmlDmBMAdapter::FetchLeafObjectL: Start" )
       
   428     BMADAPTERLOGSTRING3( "\tFetchLeafObjectL  \tURI: %S, \tLUID: %S,", 
       
   429                         &aURI, &aLUID )
       
   430 
       
   431     TInt snapId = MapPredefinedSnapsL( aURI, aLUID );                         
       
   432                         
       
   433     // check if parent snap node is buffered 
       
   434     CSmlDmBmSettingsElement* snap = 
       
   435     GetSnapIfBuffered( RemoveLastURISeg( aURI ) );
       
   436 
       
   437     // data for buffered SNAP -> Store command into buffer    
       
   438     if ( snap )
       
   439         {
       
   440         CSmlDmBmCommandElement* cmd = 
       
   441         CSmlDmBmCommandElement::NewLC( ETrue, 
       
   442                                        aStatusRef, 
       
   443                                        aResultsRef, 
       
   444                                        CNSmlDmBmAdapter::EGetCmd,
       
   445                                        LastURISeg( aURI ), 
       
   446                                        KNullDesC8);
       
   447         snap->NodeBuf().AppendL( cmd );
       
   448         CleanupStack::Pop( cmd );
       
   449         BMADAPTERLOGSTRING2( "\tSnap %S found, buffering cmd", 
       
   450                             snap->MappingName() )
       
   451         }
       
   452     // otherwise execute cmd right away
       
   453     else
       
   454         {
       
   455                 
       
   456         CSmlDmBmCommandElement* cmd = 
       
   457         CSmlDmBmCommandElement::NewLC( ETrue, 
       
   458                                        aStatusRef, 
       
   459                                        aResultsRef, 
       
   460                                        CNSmlDmBmAdapter::EGetCmd,
       
   461                                        LastURISeg( aURI ), 
       
   462                                        KNullDesC8);
       
   463         if( snapId == KErrNotFound )
       
   464             {
       
   465             snapId = DesToIntL( aLUID );
       
   466             }
       
   467 
       
   468         iSettingStore->ExecuteCmdL( *cmd, snapId );
       
   469         BMADAPTERLOGSTRING2( "\tCmd executed with status: %d ", 
       
   470                               cmd->Status() )
       
   471         // if executed return status
       
   472         if ( cmd->Executed() ) 
       
   473             {
       
   474             Callback().SetStatusL( aStatusRef, cmd->Status() );
       
   475             // if successful set results
       
   476             if ( cmd->Status() == CSmlDmAdapter::EOk )
       
   477                 {
       
   478                 BMADAPTERLOGSTRING2( "\tCmd executed with result: %S ", 
       
   479                                       cmd->Data() )
       
   480                 CBufBase* result = CBufFlat::NewL( cmd->Data()->Size() );
       
   481                 CleanupStack::PushL( result );
       
   482                 result->InsertL( 0, *cmd->Data() );
       
   483                 Callback().SetResultsL( aResultsRef, *result, KNullDesC8 );
       
   484                 CleanupStack::PopAndDestroy( result );
       
   485                 }
       
   486             }
       
   487         else
       
   488             {
       
   489             // failed to execute command
       
   490             Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   491             }
       
   492         CleanupStack::PopAndDestroy( cmd );
       
   493         }
       
   494     
       
   495     BMADAPTERLOGSTRING( "NSmlDmBMAdapter::FetchLeafObjectL: End" )
       
   496     }
       
   497 
       
   498 // --------------------------------------------------------------------------
       
   499 //  CNSmlDmBmAdapter::FetchLeafObjectSizeL
       
   500 //  Fetches leaf object size. If the snap is buffered also this command will
       
   501 //  be buffered.
       
   502 // -------------------------------------------------------------------------
       
   503 void CNSmlDmBmAdapter::FetchLeafObjectSizeL( const TDesC8& aURI, 
       
   504                                              const TDesC8& aLUID,
       
   505                                              const TDesC8& /* aType */, 
       
   506                                              TInt aResultsRef,
       
   507                                              TInt aStatusRef )
       
   508     {
       
   509     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::FetchLeafObjectSizeL: Start" )
       
   510     BMADAPTERLOGSTRING3( "\tFetchLeafObjectSizeL  \tURI: %S, \tLUID: %S,", 
       
   511                          &aURI, &aLUID )
       
   512    
       
   513     TInt snapId = MapPredefinedSnapsL( aURI, aLUID );
       
   514     
       
   515     // check if parent snap node is buffered 
       
   516     CSmlDmBmSettingsElement* snap = 
       
   517     GetSnapIfBuffered( RemoveLastURISeg( aURI ) );
       
   518 
       
   519     // data for buffered SNAP -> Store command into buffer    
       
   520     if ( snap )
       
   521         {
       
   522         CSmlDmBmCommandElement* cmd = 
       
   523         CSmlDmBmCommandElement::NewLC( ETrue, 
       
   524                                        aStatusRef, 
       
   525                                        aResultsRef, 
       
   526                                        CNSmlDmBmAdapter::EGetSizeCmd,
       
   527                                        LastURISeg( aURI ), 
       
   528                                        KNullDesC8);
       
   529         snap->NodeBuf().AppendL( cmd );
       
   530         CleanupStack::Pop( cmd ); 
       
   531         BMADAPTERLOGSTRING2( "\tSnap %S found, buffering cmd", 
       
   532                              snap->MappingName() )
       
   533         }
       
   534     // otherwise execute get size cmd right away
       
   535     else
       
   536         {
       
   537         CSmlDmBmCommandElement* cmd = 
       
   538         CSmlDmBmCommandElement::NewLC( ETrue, 
       
   539                                        aStatusRef, 
       
   540                                        aResultsRef, 
       
   541                                        CNSmlDmBmAdapter::EGetSizeCmd,
       
   542                                        LastURISeg( aURI ), 
       
   543                                        KNullDesC8);
       
   544         if( snapId == KErrNotFound )
       
   545             {
       
   546             snapId = DesToIntL( aLUID );
       
   547             }
       
   548         iSettingStore->ExecuteCmdL( *cmd, snapId );
       
   549         BMADAPTERLOGSTRING2( "\tCmd executed with status: %d ", 
       
   550                               cmd->Status() )
       
   551         // if executed get status
       
   552         if ( cmd->Executed() ) 
       
   553             {
       
   554             Callback().SetStatusL( aStatusRef, cmd->Status() );
       
   555             // if successful get results
       
   556             if ( cmd->Status() == CSmlDmAdapter::EOk )
       
   557                 {
       
   558                 BMADAPTERLOGSTRING2( "\tCmd executed with result: %S ", 
       
   559                                       cmd->Data() )
       
   560                 CBufBase* result = CBufFlat::NewL( cmd->Data()->Size() );
       
   561                 CleanupStack::PushL( result );
       
   562                 result->InsertL( 0, *cmd->Data() );
       
   563                 Callback().SetResultsL( aResultsRef, *result, KNullDesC8 );
       
   564                 CleanupStack::PopAndDestroy( result );
       
   565                 }
       
   566             }
       
   567         else
       
   568             {
       
   569             // failed to execute command
       
   570             Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   571             }
       
   572         
       
   573         CleanupStack::PopAndDestroy( cmd );
       
   574         }
       
   575     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::FetchLeafObjectSizeL: End" )
       
   576     }
       
   577 
       
   578 // ------------------------------------------------------------------------
       
   579 //  CNSmlDmBmAdapter::ChildURIListL
       
   580 //  Fetches child nodes of a node. these may be either all snap nodes
       
   581 //  or leaf nodes under a snap node. 
       
   582 // ------------------------------------------------------------------------
       
   583 void CNSmlDmBmAdapter::ChildURIListL( const TDesC8& aURI, 
       
   584                                       const TDesC8& aLUID,
       
   585                                       const CArrayFix<TSmlDmMappingInfo>& 
       
   586                                       aPreviousURISegmentList,
       
   587                                       TInt aResultsRef, 
       
   588                                       TInt aStatusRef )
       
   589     {
       
   590     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::ChildURIListL: Start" )
       
   591     BMADAPTERLOGSTRING3( "\tChildURIListL  URI: %S, LUID: %S ", 
       
   592                         &aURI, &aLUID )
       
   593                         
       
   594     TInt snapId = MapPredefinedSnapsL( aURI, aLUID );
       
   595     
       
   596     CBufBase* resultList = CBufFlat::NewL( KSmlMaxURISegLen );
       
   597     CleanupStack::PushL( resultList );
       
   598     // get all snap nodes
       
   599     if ( !aURI.Compare(KNSmlDmBMAdapterBM) )
       
   600         {
       
   601         RArray<TUint32> snaps = RArray<TUint32>( KNSmlDmBMGranularity );
       
   602         CleanupClosePushL( snaps );
       
   603         iSettingStore->GetSnapsL( snaps );
       
   604         TInt currentSNAP( -1 );
       
   605         for ( TInt i( 0 ); i < snaps.Count(); i++)
       
   606             {
       
   607             currentSNAP = snaps[i];
       
   608             BMADAPTERLOGSTRING2( "\tSnap id: %d, ", currentSNAP )
       
   609 
       
   610             // check that not previously mapped
       
   611             TBool found = EFalse;
       
   612             
       
   613             for ( TInt j( 0 ); j < aPreviousURISegmentList.Count(); j++ )
       
   614                 {
       
   615                 TSmlDmMappingInfo mapping = aPreviousURISegmentList.At( j );
       
   616                 // snap already has mapping
       
   617                 if ( currentSNAP == DesToIntL( mapping.iURISegLUID ) )
       
   618                     {
       
   619                     BMADAPTERLOGSTRING2( " URI: %S exists ", &mapping.iURISeg )
       
   620                     found = ETrue;
       
   621                     // add to result list
       
   622                     resultList->InsertL( resultList->Size(), 
       
   623                                          mapping.iURISeg);
       
   624                     break;
       
   625                     }
       
   626                 }
       
   627             if ( !found )
       
   628                 {
       
   629                 // This is new snap -> create URI and mapping and add 
       
   630                 // node name to result
       
   631                 HBufC8* uri = HBufC8::NewLC( aURI.Length() + 
       
   632                                              KNSmlDmBmSeparator().Length() +
       
   633                                              KSmlMaxURISegLen );
       
   634                     
       
   635                 TPtr8 uriPtr = uri->Des(); 
       
   636                 uriPtr.Format( aURI );
       
   637                 uriPtr.Append( KNSmlDmBmSeparator );
       
   638                 uriPtr.Append( KNSmlDmBMSNAPNamePrefix ); 
       
   639                 HBufC8* luidBuf = IntToDes8L( currentSNAP );
       
   640                 CleanupStack::PushL( luidBuf );
       
   641                 uriPtr.Append( *luidBuf );
       
   642 
       
   643                 Callback().SetMappingL( uriPtr, *luidBuf );
       
   644                 resultList->InsertL( resultList->Size(), 
       
   645                                      LastURISeg( uriPtr ) );
       
   646                 BMADAPTERLOGSTRING2( "Creating mapping for URI %S ", &uriPtr ) 
       
   647                 CleanupStack::PopAndDestroy( luidBuf );
       
   648                 CleanupStack::PopAndDestroy( uri );
       
   649                 }
       
   650             // insert separator if not last    
       
   651             if ( i < snaps.Count() - 1 )
       
   652                 {
       
   653                 resultList->InsertL( resultList->Size(), 
       
   654                                      KNSmlDmBmSeparator );
       
   655                 }
       
   656             }
       
   657         CleanupStack::PopAndDestroy( &snaps );
       
   658         Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   659         Callback().SetResultsL( aResultsRef, *resultList, KNullDesC8 );
       
   660         }
       
   661     // get child nodes of a snap node
       
   662     else if ( NumOfURISegs( aURI ) == KNsmlDmBmSNAPNodeDepth )
       
   663         {        
       
   664         CSmlDmBmSettingsElement* snap = GetSnapIfBuffered( aURI );
       
   665         // if buffered, add this command to buffer
       
   666         if( snap )
       
   667             {
       
   668             CSmlDmBmCommandElement* cmd = 
       
   669             CSmlDmBmCommandElement::NewLC( EFalse, 
       
   670                                            aStatusRef,
       
   671                                            aResultsRef, 
       
   672                                            CNSmlDmBmAdapter::EGetCmd, 
       
   673                                            KNullDesC8, 
       
   674                                            KNullDesC8 );
       
   675             snap->NodeBuf().AppendL( cmd );
       
   676             CleanupStack::Pop( cmd );
       
   677             BMADAPTERLOGSTRING2( "\tSnap %S found, buffering cmd", 
       
   678                                  snap->MappingName() )
       
   679             }
       
   680         // existing snap must have luid mapped
       
   681         else if( aLUID.Length() > 0 || snapId != KErrNotFound )
       
   682             {
       
   683             CSmlDmBmCommandElement* cmd = 
       
   684             CSmlDmBmCommandElement::NewLC( EFalse, 
       
   685                                            aStatusRef,
       
   686                                            aResultsRef, 
       
   687                                            CNSmlDmBmAdapter::EGetCmd, 
       
   688                                            KNullDesC8, 
       
   689                                            KNullDesC8 );
       
   690             if( snapId == KErrNotFound )
       
   691                 {
       
   692                 snapId = DesToIntL( aLUID );
       
   693                 }
       
   694             
       
   695             iSettingStore->ExecuteCmdL( *cmd, snapId );
       
   696             BMADAPTERLOGSTRING2( "\tCmd executed with status: %d ", 
       
   697                                   cmd->Status() )
       
   698             Callback().SetStatusL( aStatusRef, cmd->Status() );
       
   699             if( cmd->Status() == CSmlDmAdapter::EOk )
       
   700                 {
       
   701                 resultList->InsertL( 0, *cmd->Data() );
       
   702                 Callback().SetResultsL( aResultsRef, 
       
   703                                         *resultList, 
       
   704                                         KNullDesC8 );
       
   705                 } 
       
   706             CleanupStack::PopAndDestroy( cmd );
       
   707             }
       
   708         // invalid snap object
       
   709         else
       
   710             {
       
   711             BMADAPTERLOGSTRING( "\tCNSmlDmBmAdapter::ChildURIListL: Error, \
       
   712             invalid snap node" )
       
   713             Callback().SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   714             }           
       
   715         }
       
   716     else
       
   717         {
       
   718         BMADAPTERLOGSTRING( "\tChildURIListL: Invalid URI" )
       
   719         }
       
   720     CleanupStack::PopAndDestroy( resultList );
       
   721     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::ChildURIListL: End" )
       
   722     }
       
   723  
       
   724 // --------------------------------------------------------------------------
       
   725 //  CNSmlDmBmAdapter::AddNodeObjectL
       
   726 //  Adds a snap node. The node is buffered until all data is received.
       
   727 // --------------------------------------------------------------------------
       
   728 void CNSmlDmBmAdapter::AddNodeObjectL( const TDesC8& aURI, 
       
   729                                        const TDesC8& aParentLUID,
       
   730                                        TInt aStatusRef )
       
   731     {
       
   732     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::AddNodeObjectL: Start" )
       
   733     BMADAPTERLOGSTRING3( "\tAddNodeObjectL  \tURI: %S, \tparent LUID: %S,", 
       
   734                         &aURI, &aParentLUID )
       
   735     if ( NumOfURISegs( aURI ) == KNsmlDmBmSNAPNodeDepth )
       
   736         {
       
   737         // if same node already exists command fails
       
   738         CSmlDmBmSettingsElement* setting = GetSnapIfBuffered( aURI );
       
   739         if( setting || aParentLUID.Compare( KNullDesC8) )
       
   740             {
       
   741             BMADAPTERLOGSTRING( "\t Snap exists" )
       
   742             Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EAlreadyExists );
       
   743             }
       
   744         else if ( LastURISeg( aURI ).Length() > KSmlMaxURISegLen )
       
   745             {
       
   746             BMADAPTERLOGSTRING( "\t Node name too long" )
       
   747             Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   748             }
       
   749         else
       
   750             {
       
   751             // Store command in buffer for later processing
       
   752             setting = CSmlDmBmSettingsElement::NewLC( aURI );
       
   753             iBuffer.AppendL( setting );
       
   754             CleanupStack::Pop( setting );
       
   755         
       
   756             // store the add node command
       
   757             CSmlDmBmCommandElement* command = 
       
   758             CSmlDmBmCommandElement::NewLC( EFalse, 
       
   759                                            aStatusRef,
       
   760                                            KNSmlDmBmInvalidRef, 
       
   761                                            CNSmlDmBmAdapter::EAddCmd, 
       
   762                                            KNullDesC8, 
       
   763                                            KNullDesC8 );
       
   764             TInt index( iBuffer.Count() - 1 );
       
   765             iBuffer[index]->NodeBuf().AppendL( command ); 
       
   766             CleanupStack::Pop( command );
       
   767             BMADAPTERLOGSTRING( "\t Cmd buffered" )
       
   768             }
       
   769         }
       
   770       
       
   771     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::AddNodeObjectL: End" )
       
   772     }
       
   773 
       
   774 // -------------------------------------------------------------------------
       
   775 //  CNSmlDmBmAdapter::UpdateLeafObjectL
       
   776 //  Not supported
       
   777 // -------------------------------------------------------------------------
       
   778 void CNSmlDmBmAdapter::UpdateLeafObjectL( const TDesC8& /* aURI */, 
       
   779                                           const TDesC8& /* aLUID */, 
       
   780                                           RWriteStream*& /* aStream */, 
       
   781                                           const TDesC8& /* aType */, 
       
   782                                           TInt /* aStatusRef */ )
       
   783     {
       
   784     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::UpdateLeafObjectL: Start" )
       
   785     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::UpdateLeafObjectL: End" )
       
   786     }
       
   787 
       
   788 
       
   789 
       
   790 // -------------------------------------------------------------------------
       
   791 //  CNSmlDmBmAdapter::ExecuteCommandL
       
   792 //  Not supported
       
   793 // -------------------------------------------------------------------------
       
   794 void CNSmlDmBmAdapter::ExecuteCommandL( const TDesC8& /* aURI */, 
       
   795                                         const TDesC8& /* aLUID */, 
       
   796                                         const TDesC8& /* aArgument */, 
       
   797                                         const TDesC8& /* aType */, 
       
   798                                         TInt aStatusRef )
       
   799     {
       
   800     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::ExecuteCommandL: Start" )
       
   801     Callback().SetStatusL(aStatusRef, CSmlDmAdapter::EError);
       
   802     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::ExecuteCommandL: End" )
       
   803     }
       
   804 // -------------------------------------------------------------------------
       
   805 //  CNSmlDmBmAdapter::ExecuteCommandL
       
   806 //  Not supported
       
   807 // -------------------------------------------------------------------------
       
   808 void CNSmlDmBmAdapter::ExecuteCommandL( const TDesC8& /* aURI */, 
       
   809                                         const TDesC8& /* aLUID */, 
       
   810                                         RWriteStream*& /* aStream */, 
       
   811                                         const TDesC8& /* aType */, 
       
   812                                         TInt aStatusRef )
       
   813     {
       
   814     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::ExecuteCommandL: Start" )
       
   815     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   816     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::ExecuteCommandL: End" )
       
   817     }
       
   818  
       
   819 // -------------------------------------------------------------------------
       
   820 //  CNSmlDmBmAdapter::CopyCommandL
       
   821 //  Not supported
       
   822 // -------------------------------------------------------------------------
       
   823 void CNSmlDmBmAdapter::CopyCommandL( const TDesC8& /* aTargetURI */ , 
       
   824                                      const TDesC8& /* aTargetLUID */ , 
       
   825                                      const TDesC8& /* aSourceURI */ , 
       
   826                                      const TDesC8& /* aSourceLUID */, 
       
   827                                      const TDesC8& /* aType */ , 
       
   828                                      TInt aStatusRef )
       
   829     {
       
   830     //not supported
       
   831     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::CopyCommandL: Sart" )
       
   832     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   833     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::CopyCommandL: End" )
       
   834     }
       
   835 // -------------------------------------------------------------------------
       
   836 //  CNSmlDmBmAdapter::StartAtomicL
       
   837 //  Not supported
       
   838 // -------------------------------------------------------------------------
       
   839 void CNSmlDmBmAdapter::StartAtomicL()
       
   840     {
       
   841     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::StartAtomicL: Start" )
       
   842     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::StartAtomicL: End" )
       
   843     }
       
   844 // -------------------------------------------------------------------------
       
   845 //  CNSmlDmBmAdapter::CommitAtomicL
       
   846 //  Not supported
       
   847 // -------------------------------------------------------------------------
       
   848 void CNSmlDmBmAdapter::CommitAtomicL()
       
   849     {
       
   850     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::CommitAtomicL: Start" )
       
   851     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::CommitAtomicL: End" )
       
   852     }
       
   853 
       
   854 // -------------------------------------------------------------------------
       
   855 //  CNSmlDmBmAdapter::RollbackAtomicL
       
   856 //  Not supported
       
   857 // -------------------------------------------------------------------------
       
   858 void CNSmlDmBmAdapter::RollbackAtomicL()
       
   859     {
       
   860     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::RollbackAtomicL: Start" )
       
   861     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::RollbackAtomicL: End" )
       
   862     }
       
   863 
       
   864 TBool CNSmlDmBmAdapter::StreamingSupport( TInt& /* aItemSize */ )
       
   865     {
       
   866     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::StreamingSupport: Start" )
       
   867     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::StreamingSupport: End" )
       
   868     return EFalse;
       
   869     }
       
   870 // -------------------------------------------------------------------------
       
   871 //  CNSmlDmBmAdapter::StreamCommittedL
       
   872 //  Not supported
       
   873 // -------------------------------------------------------------------------
       
   874 void CNSmlDmBmAdapter::StreamCommittedL()
       
   875     {
       
   876     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::StreamCommittedL: Start" )
       
   877     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::StreamCommittedL: End" )
       
   878     }
       
   879 
       
   880 // -------------------------------------------------------------------------
       
   881 // CNSmlDmBmAdapter::CompleteOutstandingCmdsL
       
   882 //  CNSmlDmBmAdapter::CompleteOutstandingCmdsL
       
   883 // -------------------------------------------------------------------------
       
   884 void CNSmlDmBmAdapter::CompleteOutstandingCmdsL()
       
   885     {
       
   886     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::CompleteOutstandingCmdsL: Start" )
       
   887     CSmlDmBmSettingsElement* settings( NULL );
       
   888     CSmlDmBmCommandElement* cmd( NULL );
       
   889     TInt err(0);
       
   890     // Read through the buffer and execute commands
       
   891     for ( TInt i(0); i < iBuffer.Count(); )
       
   892         {
       
   893         settings = iBuffer[i];
       
   894         if( settings->NodeBuf().Count() )
       
   895             {
       
   896             // the setting may be executed already if it has been an embedded
       
   897             // snap for another snap
       
   898             if ( !settings->Executed() ) 
       
   899                 {
       
   900                 //execute commands for snap
       
   901                 TRAP( err, iSettingStore->StoreSnapL( *settings )); 
       
   902                 } 
       
   903             // if can't recover from error, don't continue processing 
       
   904             // commands
       
   905             if( err == KErrNoMemory || 
       
   906                 err == KErrDiskFull )
       
   907                 {
       
   908                 BMADAPTERLOGSTRING2( "\tCNSmlDmBmAdapter::\
       
   909                 CompleteOutstandingCmdsL: Error %d", err )
       
   910                 User::Leave( err );
       
   911                 }
       
   912             // if this is a new snap and created successfully, map luid
       
   913             if ( !settings->NodeBuf()[0]->Leaf() &&
       
   914                  settings->NodeBuf()[0]->CmdType() == CNSmlDmBmAdapter::EAddCmd && 
       
   915                  settings->NodeBuf()[0]->Executed() &&
       
   916                  settings->NodeBuf()[0]->Status() == CSmlDmAdapter::EOk )
       
   917                 {
       
   918                 HBufC8* luid = IntToDes8L( settings->Luid() );
       
   919                 CleanupStack::PushL( luid );
       
   920                 Callback().SetMappingL( *settings->MappingName(), *luid );
       
   921                 BMADAPTERLOGSTRING3( "\t Setting mapping %S - %S ",
       
   922                 settings->MappingName(), luid )
       
   923                 CleanupStack::PopAndDestroy( luid );
       
   924                 }
       
   925             // set status for all commands executed and remove the command
       
   926             for ( TInt j( 0 ); j < settings->NodeBuf().Count(); )
       
   927                 {
       
   928                 
       
   929                 cmd = settings->NodeBuf()[j];
       
   930                  
       
   931                 // return status values if executed
       
   932                 if ( cmd->Executed() )
       
   933                     {
       
   934                     
       
   935                     Callback().SetStatusL( cmd->StatusRef(),
       
   936                                   cmd->Status() );
       
   937                     // for certain errors, don't continue command execution
       
   938                     if( cmd->Status() == CSmlDmAdapter::ENoMemory )
       
   939                         {
       
   940                         // commands are deleted     
       
   941                         iBuffer.ResetAndDestroy();
       
   942                         BMADAPTERLOGSTRING( "\tCmd failed with CSmlDmAdapter::ENoMemory" )
       
   943                         User::Leave( KErrNoMemory );
       
   944                         }
       
   945                    else if( cmd->Status() == CSmlDmAdapter::EDiskFull )
       
   946                         {
       
   947                         // commands are deleted   
       
   948                         iBuffer.ResetAndDestroy();
       
   949                         BMADAPTERLOGSTRING( "\tCmd failed with CSmlDmAdapter::EDiskFull" )
       
   950                         User::Leave( KErrDiskFull );
       
   951                         }
       
   952                    else
       
   953                         {
       
   954                         BMADAPTERLOGSTRING2( 
       
   955                             "\tCmd failed with CSmlDmAdapter::%d", 
       
   956                             cmd->Status() )
       
   957                         }
       
   958                     // for get commands, also return the results
       
   959                    if ( cmd->CmdType() == CNSmlDmBmAdapter::EGetCmd || 
       
   960                         cmd->CmdType() == CNSmlDmBmAdapter::EGetSizeCmd )
       
   961                        {
       
   962                        CBufBase* result = CBufFlat::NewL( cmd->Data()->Size() );
       
   963                        CleanupStack::PushL( result );
       
   964                        result->InsertL( 0, *cmd->Data() ); 
       
   965                        Callback().SetResultsL( cmd->ResultRef(), 
       
   966                                                *result, 
       
   967                                                KNullDesC8 );
       
   968                        CleanupStack::PopAndDestroy( result );
       
   969                        }
       
   970                    }
       
   971                else
       
   972                    {
       
   973                    Callback().SetStatusL( cmd->StatusRef(),
       
   974                                  CSmlDmAdapter::EError );
       
   975                    }
       
   976                settings->NodeBuf().Remove( j );
       
   977                delete cmd;
       
   978                }
       
   979             }
       
   980             
       
   981         // delete settings element and remove it from buffer 
       
   982         delete settings;
       
   983         iBuffer.Remove( i );
       
   984         }
       
   985     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::CompleteOutstandingCmdsL: End" )
       
   986     }
       
   987 
       
   988 
       
   989 
       
   990 // -------------------------------------------------------------------------
       
   991 // CNSmlDmBmAdapter::StoreSnapIfBufferedL
       
   992 // If argument snap is found in the buffer iSettingStore->StoreSNAPL is 
       
   993 // called 
       
   994 // for it and LUID is mapped. SNAP is set as executed.
       
   995 // This is called when checking if snap has embedded snap reference to 
       
   996 // another 
       
   997 // snap which is stored further in the command buffer. 
       
   998 // All embedded snap commands of this type are buffered and execution only 
       
   999 // happens with CompleteOutstandingCmdsL call. 
       
  1000 // -------------------------------------------------------------------------
       
  1001     
       
  1002 void CNSmlDmBmAdapter::StoreSnapIfBufferedL( const TDesC8& aURI )
       
  1003     {
       
  1004     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::StoreSnapIfBufferedL: Start" )
       
  1005     CSmlDmBmSettingsElement* snap = GetSnapIfBuffered( aURI );
       
  1006     // if snap is in buffer and is a new snap
       
  1007     if( snap && !snap->Luid() )
       
  1008         {
       
  1009         iSettingStore->StoreSnapL( *snap );
       
  1010         // set mapping if succesfully executed
       
  1011         if ( snap->NodeBuf()[0]->Executed() &&
       
  1012              snap->NodeBuf()[0]->Status() == CSmlDmAdapter::EOk )
       
  1013             {
       
  1014             HBufC8* luid = IntToDes8L( snap->Luid() );
       
  1015             CleanupStack::PushL( luid );
       
  1016             Callback().SetMappingL( *snap->MappingName(), *luid);
       
  1017             CleanupStack::PopAndDestroy( luid );
       
  1018             }
       
  1019         }
       
  1020     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::StoreSnapIfBufferedL: End" )
       
  1021     }
       
  1022 // -------------------------------------------------------------------------
       
  1023 // CNSmlDmBmAdapter::GetSnapUriFromLuidL
       
  1024 // Returns heap desciptor holding snap node URI matching the argument LUID
       
  1025 // -------------------------------------------------------------------------
       
  1026 HBufC8* CNSmlDmBmAdapter::GetSnapUriFromLuidL( const TUint aSnapId )
       
  1027     {
       
  1028     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::GetSnapURIFromLUIDL: Start" )
       
  1029     HBufC8* uri( NULL );
       
  1030     MSmlDmAdapter::TError err( MSmlDmAdapter::EOk );
       
  1031     CBufBase* fetchRes = CBufFlat::NewL( KSmlMaxURISegLen );
       
  1032     CleanupStack::PushL( fetchRes );
       
  1033     // fetch all snap nodes
       
  1034     Callback().FetchLinkL( KNSmlDmBMAdapterBMURI, *fetchRes, err );
       
  1035 
       
  1036     TPtr8 snapNodes = fetchRes->Ptr( 0 );
       
  1037 
       
  1038     TInt numSnaps = NumOfURISegs( snapNodes );
       
  1039         
       
  1040     // get uri-luid mappings for snap nodes
       
  1041     for ( TInt i( 0 ); i < numSnaps; i++ )
       
  1042         {
       
  1043         TPtrC8 node = LastURISeg( snapNodes );
       
  1044 
       
  1045         HBufC8* uriSeg = HBufC8::NewLC( KNSmlDmBmAdapterURIMaxLength + 
       
  1046                                         node.Length());
       
  1047         uriSeg->Des().Append( KNSmlDmBMAdapterBM() );
       
  1048         uriSeg->Des().Append( KNSmlDmBmSeparator() );
       
  1049         uriSeg->Des().Append( node ); 
       
  1050 
       
  1051         HBufC8* luid = Callback().GetLuidAllocL( *uriSeg );
       
  1052         CleanupStack::PopAndDestroy( uriSeg );
       
  1053         CleanupStack::PushL( luid );
       
  1054         // node may not have luid mapped if it's just created
       
  1055         if( luid->Size() )
       
  1056             {
       
  1057             TInt id = DesToIntL( *luid );
       
  1058             CleanupStack::PopAndDestroy( luid ); 
       
  1059             if ( aSnapId ==  id ) 
       
  1060                 {
       
  1061                 uri = HBufC8::NewLC( KNSmlDmBMAdapterBMURI().Size() + 
       
  1062                                KNSmlDmBmSeparator().Size() + 
       
  1063                                node.Size() );
       
  1064 
       
  1065                 uri->Des().Append( KNSmlDmBMAdapterBMURI() );
       
  1066                 uri->Des().Append( KNSmlDmBmSeparator() );
       
  1067                 uri->Des().Append( node );
       
  1068                 break;
       
  1069                 }
       
  1070             }
       
  1071         else
       
  1072             {
       
  1073             CleanupStack::PopAndDestroy( luid );
       
  1074             }
       
  1075         snapNodes = RemoveLastURISeg( snapNodes );
       
  1076         }
       
  1077           
       
  1078     if( uri )
       
  1079         {
       
  1080          CleanupStack::Pop( uri );
       
  1081         }
       
  1082 
       
  1083     CleanupStack::PopAndDestroy( fetchRes );
       
  1084 
       
  1085     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::IdArrayToIAPList: End" )
       
  1086     return uri;
       
  1087     }
       
  1088 
       
  1089 // -------------------------------------------------------------------------
       
  1090 // CNSmlDmBmAdapter::GetIapListL
       
  1091 // Returns heap desciptor holding a comma separated list of AP node URIs
       
  1092 // matching the luids in the argument array.
       
  1093 // -------------------------------------------------------------------------
       
  1094 HBufC8* CNSmlDmBmAdapter::GetIapListL( const RArray<TUint>& aIdArray )
       
  1095     {
       
  1096     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::GetIapListL: Start" )
       
  1097     HBufC8* iapList = HBufC8::NewLC( aIdArray.Count() * 
       
  1098                                     ( KNSmlDmBmAdapterAPURIMaxLength + 
       
  1099                                       KSmlMaxURISegLen ) );
       
  1100     MSmlDmAdapter::TError err;
       
  1101     CBufBase* fetchRes = CBufFlat::NewL( KSmlMaxURISegLen );
       
  1102     CleanupStack::PushL( fetchRes );
       
  1103     // fetch dynamic AP nodes, so that LUID mapping is created
       
  1104     Callback().FetchLinkL( KNSmlDmBMAdapterIAPURI, *fetchRes, err );
       
  1105 
       
  1106     // list of all nodes has a trailing '/' unlike regular uris, remove that
       
  1107     // for further handling 
       
  1108     TPtr8 iapNodes = fetchRes->Ptr( 0 );
       
  1109     if ( iapNodes.Length() > 0 && iapNodes[iapNodes.Length() - 1] == '/')
       
  1110         {
       
  1111         iapNodes = iapNodes.Left( iapNodes.Length() - 1 );
       
  1112         }
       
  1113 
       
  1114     TInt numAPs = NumOfURISegs( iapNodes );
       
  1115     
       
  1116     CArrayFixFlat<TSmlDmMappingInfo>* mappings = 
       
  1117         new (ELeave) CArrayFixFlat<TSmlDmMappingInfo>( numAPs * 
       
  1118                                                        sizeof( TSmlDmMappingInfo ) );
       
  1119     CleanupStack::PushL( mappings );
       
  1120     
       
  1121    // get uri-luid mappings for all ap nodes
       
  1122     HBufC8* luid = NULL;
       
  1123     for ( TInt i( 0 ); i < numAPs; i++ )
       
  1124         {
       
  1125         TSmlDmMappingInfo m;
       
  1126         m.iURISeg = LastURISeg( iapNodes );
       
  1127         
       
  1128         HBufC8* uriSeg = HBufC8::NewLC( KNSmlDmBmAdapterAPURIMaxLength + 
       
  1129                                         m.iURISeg.Length() );
       
  1130         uriSeg->Des().Replace( 0, 
       
  1131                                uriSeg->Length(), 
       
  1132                                KNSmlDmBMAdapterIAPNode() );
       
  1133         uriSeg->Des().Append( KNSmlDmBmSeparator() );
       
  1134         uriSeg->Des().Append( m.iURISeg ); 
       
  1135 
       
  1136         luid = Callback().GetLuidAllocL( *uriSeg );
       
  1137         CleanupStack::PopAndDestroy( uriSeg );
       
  1138         CleanupStack::PushL( luid );
       
  1139         m.iURISegLUID.Set( *luid );
       
  1140         mappings->AppendL( m ); 
       
  1141         iapNodes = RemoveLastURISeg( iapNodes );
       
  1142         }
       
  1143         
       
  1144     // find out URIs matching argument IAP ids
       
  1145     for (TInt i(0); i < aIdArray.Count(); i++)
       
  1146         {
       
  1147         TBool found = EFalse;
       
  1148 
       
  1149         for ( TInt j( 0 ); j < mappings->Count(); j++ )
       
  1150             {
       
  1151             if ( aIdArray[i] == DesToIntL( mappings->At( j ).iURISegLUID ) )
       
  1152                 {
       
  1153                 // add to result
       
  1154                 iapList->Des().Append( KNSmlDmBMAdapterIAPURI() );
       
  1155                 iapList->Des().Append( KNSmlDmBmSeparator() );
       
  1156                 iapList->Des().Append( mappings->At(j).iURISeg );
       
  1157                 // not last -> add separator
       
  1158                 if ( i < aIdArray.Count() - 1 )
       
  1159                     {
       
  1160                     iapList->Des().Append( KNSmlDmBmUriListSeparator );
       
  1161                     }
       
  1162                 found = ETrue;
       
  1163                 break;
       
  1164                 }
       
  1165             }
       
  1166         if ( ! found )
       
  1167             {
       
  1168             BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::GetIapListL: \
       
  1169             Error IAP matching id not found" )
       
  1170             User::Leave( KErrNotFound );
       
  1171             }
       
  1172         }
       
  1173   
       
  1174     // cleanup each allocated luid
       
  1175     CleanupStack::PopAndDestroy( numAPs ); 
       
  1176     CleanupStack::PopAndDestroy( mappings );
       
  1177     CleanupStack::PopAndDestroy( fetchRes );
       
  1178     CleanupStack::Pop( iapList );
       
  1179     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::GetIapListL: End" )
       
  1180     return iapList;
       
  1181     }
       
  1182     
       
  1183 // -------------------------------------------------------------------------
       
  1184 // CNSmlDmBmAdapter::GetIdArrayL
       
  1185 // Returns array holding LUIDs matching the AP node in the argument list.
       
  1186 // -------------------------------------------------------------------------
       
  1187 RArray<TUint> CNSmlDmBmAdapter::GetIdArrayL( const TDesC8& aIAPList )
       
  1188     {
       
  1189     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::GetIdArrayL: Start" )
       
  1190     TPtrC8 uri;
       
  1191     RArray<TUint> iaps;
       
  1192     CleanupClosePushL( iaps );
       
  1193     uri.Set( aIAPList );
       
  1194     // fetch AP nodes so that mappings are created
       
  1195     MSmlDmAdapter::TError err;
       
  1196     CBufBase* fetchRes = CBufFlat::NewL( KSmlMaxURISegLen );
       
  1197     CleanupStack::PushL( fetchRes );
       
  1198     // fetch dynamic AP nodes, so that LUID mappings are created
       
  1199     Callback().FetchLinkL( KNSmlDmBMAdapterIAPURI, *fetchRes, err );
       
  1200     
       
  1201     for ( TInt i(0), n = NumOfURIs( aIAPList ); i < n; i++ )
       
  1202         {
       
  1203         TPtrC8 thisURI = FirstURI( uri );
       
  1204         // remove ./ from beginning
       
  1205         TPtrC8 apUri = thisURI.Mid( KNSmlDmBmAdapterURIPrefix().Length() );
       
  1206         HBufC8* luid = Callback().GetLuidAllocL( apUri );
       
  1207         CleanupStack::PushL( luid );
       
  1208         TInt id = DesToIntL( *luid );
       
  1209         CleanupStack::PopAndDestroy( luid );
       
  1210         iaps.Append( id );
       
  1211         uri.Set( RemoveFirstURI( uri ) );
       
  1212         }
       
  1213     
       
  1214     CleanupStack::PopAndDestroy( fetchRes );
       
  1215     CleanupStack::Pop( &iaps );
       
  1216     BMADAPTERLOGSTRING( "CNSmlDmBmAdapter::GetIdArrayL: End" )
       
  1217     return iaps;
       
  1218     }
       
  1219 
       
  1220 // --------------------------------------------------------------------------
       
  1221 // CNSmlDmBmAdapter::IntToDes8L
       
  1222 // Converts integer to 8bit descriptor
       
  1223 // --------------------------------------------------------------------------
       
  1224 HBufC8* CNSmlDmBmAdapter::IntToDes8L( TInt aLuid ) const
       
  1225     {
       
  1226     HBufC8* buf = HBufC8::NewL( KMaxLengthOf32bitInteger ); 
       
  1227     TPtr8 ptrBuf = buf->Des();
       
  1228 
       
  1229     // Unless aLuid is casted as TInt64, PC-Lint reports: 
       
  1230     // Significant prototype coercion
       
  1231     // 
       
  1232     ptrBuf.Num( TInt64( aLuid ) );
       
  1233     return buf;
       
  1234     }
       
  1235 
       
  1236 // --------------------------------------------------------------------------
       
  1237 // CNSmlDmBmAdapter::DesToIntL
       
  1238 // Converts 8bit descriptor to int
       
  1239 // --------------------------------------------------------------------------
       
  1240 TUint CNSmlDmBmAdapter::DesToIntL( const TDesC8& aLuid ) const
       
  1241     {
       
  1242     __UHEAP_MARK;
       
  1243     TLex8 lex( aLuid );
       
  1244     TUint value( 0 );
       
  1245     User::LeaveIfError( lex.Val( value ) );
       
  1246     __UHEAP_MARKEND;
       
  1247     return value;
       
  1248     }
       
  1249     
       
  1250 // --------------------------------------------------------------------------
       
  1251 // CNSmlDmBmAdapter::DesToBool
       
  1252 // Converts 8bit descriptor to a boolean value
       
  1253 // --------------------------------------------------------------------------
       
  1254 TBool CNSmlDmBmAdapter::DesToBool(const TDesC8& aBoolDes, TBool& aBool ) const
       
  1255     {
       
  1256     __UHEAP_MARK;
       
  1257     if ( !aBoolDes.Compare( KNSmlDmBMBooleanTrue ) )
       
  1258         {
       
  1259         aBool = ETrue;
       
  1260         }
       
  1261     else if ( !aBoolDes.Compare( KNSmlDmBMBooleanFalse ) )
       
  1262         {
       
  1263         aBool = EFalse;
       
  1264         }
       
  1265     else
       
  1266         {
       
  1267         __UHEAP_MARKEND;
       
  1268         return EFalse;
       
  1269         }
       
  1270     __UHEAP_MARKEND;
       
  1271     return ETrue;
       
  1272     }
       
  1273 
       
  1274 // --------------------------------------------------------------------------
       
  1275 // CNSmlDmBmAdapter::BoolToDes8LC
       
  1276 // Converts boolean value to 8bit descriptor
       
  1277 // --------------------------------------------------------------------------
       
  1278 
       
  1279 HBufC8* CNSmlDmBmAdapter::BoolToDes8LC( TBool aBool) const
       
  1280     {
       
  1281     HBufC8* ret;
       
  1282     if( aBool )
       
  1283         {
       
  1284         ret = HBufC8::NewLC( KNSmlDmBMBooleanTrue().Size() );
       
  1285         ret->Des().Append( KNSmlDmBMBooleanTrue() ); 
       
  1286         }
       
  1287     else
       
  1288         {
       
  1289         ret = HBufC8::NewLC( KNSmlDmBMBooleanFalse().Size() );
       
  1290         ret->Des().Append( KNSmlDmBMBooleanFalse() ); 
       
  1291         }
       
  1292     return ret;
       
  1293     }
       
  1294 
       
  1295 
       
  1296 // --------------------------------------------------------------------------
       
  1297 // CNSmlDmBmAdapter::GetLuidAllocL
       
  1298 // The function calls the GetLuidAllocL function of the MSmlDmCallback to get
       
  1299 // the LUID which is mapped to aURI.
       
  1300 // --------------------------------------------------------------------------
       
  1301 HBufC8* CNSmlDmBmAdapter::GetLuidAllocL( const TDesC8& aURI )
       
  1302     {
       
  1303     return Callback().GetLuidAllocL( aURI );
       
  1304     }
       
  1305 
       
  1306    
       
  1307 // --------------------------------------------------------------------------
       
  1308 // CNSmlDmBmAdapter::GetSnapIfBuffered
       
  1309 // Returns a pointer to the snap CSmlDmBmSettingsElement object if found in 
       
  1310 // the buffer 
       
  1311 // --------------------------------------------------------------------------
       
  1312 CSmlDmBmSettingsElement* CNSmlDmBmAdapter::GetSnapIfBuffered( const TDesC8& 
       
  1313                                                               aMappingName )
       
  1314     {
       
  1315     CSmlDmBmSettingsElement* settings = NULL;
       
  1316     for ( TInt i( 0 ); i<iBuffer.Count(); i++ )
       
  1317         {
       
  1318         if ( !iBuffer[i]->MappingName()->Compare( aMappingName ) )
       
  1319             {
       
  1320             settings = iBuffer[i];
       
  1321             break;
       
  1322             }
       
  1323         }
       
  1324     return settings;
       
  1325     }
       
  1326 // -------------------------------------------------------------------------
       
  1327 // CNSmlDmBmAdapter::FirstURI
       
  1328 // Returns the first URI from a list of URIs
       
  1329 // -------------------------------------------------------------------------
       
  1330 TPtrC8 CNSmlDmBmAdapter::FirstURI( const TDesC8& aURIList ) const
       
  1331     {
       
  1332     __UHEAP_MARK;
       
  1333     TInt i;
       
  1334     for ( i = 0; i < aURIList.Length(); i++ )
       
  1335         {
       
  1336         if ( aURIList[i] == ',' )
       
  1337             {
       
  1338             break;
       
  1339             }
       
  1340         }
       
  1341     if ( i == aURIList.Length() - 1 )
       
  1342         {
       
  1343         __UHEAP_MARKEND;
       
  1344         return aURIList;
       
  1345         }
       
  1346     else
       
  1347         {
       
  1348         __UHEAP_MARKEND;
       
  1349         return aURIList.Mid( 0, i );
       
  1350         }
       
  1351     }
       
  1352     
       
  1353 // --------------------------------------------------------------------------
       
  1354 // CNSmlDmBmAdapter::NumOfURIs
       
  1355 // Returns the num of uris
       
  1356 // --------------------------------------------------------------------------
       
  1357 TInt CNSmlDmBmAdapter::NumOfURIs( const TDesC8& aURIList ) const
       
  1358     {
       
  1359     __UHEAP_MARK;
       
  1360     if ( !aURIList.Length() )
       
  1361         {
       
  1362         return 0;
       
  1363         }
       
  1364     TInt numOfURIs( 1 );
       
  1365     for ( TInt i(0); i < aURIList.Length(); i++ )
       
  1366         {
       
  1367         if ( aURIList[i] == ',' )
       
  1368             {
       
  1369             numOfURIs++;
       
  1370             }
       
  1371         }
       
  1372     __UHEAP_MARKEND;
       
  1373     return numOfURIs;
       
  1374     }
       
  1375     
       
  1376 // --------------------------------------------------------------------------
       
  1377 // CNSmlDmBmAdapter::RemoveFirstURI
       
  1378 // extracts first uri an returns the remaining part of the uri list 
       
  1379 // --------------------------------------------------------------------------
       
  1380 TPtrC8 CNSmlDmBmAdapter::RemoveFirstURI( const TDesC8& aURIList ) const
       
  1381     {
       
  1382     __UHEAP_MARK;
       
  1383     TInt i;
       
  1384     for ( i = 0; i < aURIList.Length(); i++ )
       
  1385         {
       
  1386         if ( aURIList[i] == ',' )
       
  1387             {
       
  1388             break;
       
  1389             }
       
  1390         }
       
  1391     if ( i <  aURIList.Length() ) 
       
  1392         {
       
  1393         __UHEAP_MARKEND;
       
  1394         return aURIList.Mid( i + 1 );
       
  1395         }
       
  1396     else
       
  1397         {
       
  1398         __UHEAP_MARKEND;
       
  1399         return aURIList.Mid( i ); 
       
  1400         }
       
  1401         
       
  1402     }
       
  1403 // --------------------------------------------------------------------------
       
  1404 // CNSmlDmBmAdapter::LastURISeg
       
  1405 // Returns the last uri segemnt of a uri. 
       
  1406 // --------------------------------------------------------------------------
       
  1407 TPtrC8 CNSmlDmBmAdapter::LastURISeg( const TDesC8& aURI ) const
       
  1408     {
       
  1409     __UHEAP_MARK;
       
  1410     TInt i;
       
  1411     for ( i=aURI.Length()-1; i >= 0; i-- )
       
  1412         {
       
  1413         if ( aURI[i]=='/' )
       
  1414             {
       
  1415             break;
       
  1416             }
       
  1417         }
       
  1418     if ( i==0 )
       
  1419         {
       
  1420         __UHEAP_MARKEND;
       
  1421         return aURI;
       
  1422         }
       
  1423     else
       
  1424         {
       
  1425         __UHEAP_MARKEND;
       
  1426         return aURI.Mid( i + 1 );
       
  1427         }
       
  1428     }
       
  1429 
       
  1430 // --------------------------------------------------------------------------
       
  1431 // CNSmlDmBmAdapter::RemoveLastURISeg
       
  1432 // returns parent uri, i.e. removes last uri segment
       
  1433 // --------------------------------------------------------------------------
       
  1434 TPtrC8 CNSmlDmBmAdapter::RemoveLastURISeg( const TDesC8& aURI ) const
       
  1435     {
       
  1436     __UHEAP_MARK;
       
  1437     TInt i;
       
  1438     for ( i = aURI.Length()-1; i >= 0; i-- )
       
  1439         {
       
  1440         if ( aURI[i]=='/' )
       
  1441             {
       
  1442             break;
       
  1443             }
       
  1444         }
       
  1445     if ( i > -1 )
       
  1446         {
       
  1447         __UHEAP_MARKEND;
       
  1448         return aURI.Left( i );
       
  1449         }
       
  1450     else
       
  1451         {
       
  1452         __UHEAP_MARKEND;
       
  1453         return aURI;
       
  1454         }
       
  1455     
       
  1456     }
       
  1457 
       
  1458 
       
  1459 
       
  1460 // --------------------------------------------------------------------------
       
  1461 // CNSmlDmBmAdapter::NumOfURISegs
       
  1462 // Returns the num of uri segs
       
  1463 // --------------------------------------------------------------------------
       
  1464 TInt CNSmlDmBmAdapter::NumOfURISegs( const TDesC8& aURI ) const
       
  1465     {
       
  1466     __UHEAP_MARK;
       
  1467     TInt numOfURISegs( 1 );
       
  1468     for ( TInt i(0); i < aURI.Length(); i++ )
       
  1469         {
       
  1470         if ( aURI[i]=='/' )
       
  1471             {
       
  1472             numOfURISegs++;
       
  1473             }
       
  1474         }
       
  1475     __UHEAP_MARKEND;
       
  1476     return numOfURISegs;
       
  1477     }
       
  1478 
       
  1479 TInt CNSmlDmBmAdapter::MapPredefinedSnapsL( const TDesC8& aURI, const TDesC8& aLUID )
       
  1480 {
       
  1481     TInt snapId( KErrNotFound ); 
       
  1482     // If this is an add to pre-defined SNAPs then LUID we get is empty, but we still need
       
  1483     // to handle it.
       
  1484     if( aLUID.Length() == 0 && ( ( snapId = GetPredefinedSnapIdFromUri( aURI ) ) != KErrNotFound ) )
       
  1485         {               
       
  1486         // Check if SNAP with given ID exists (from CmManager)
       
  1487         iCmManagerExt.OpenL();
       
  1488         TRAPD( err, RCmDestinationExt dest = iCmManagerExt.DestinationL( snapId ) );
       
  1489         iCmManagerExt.Close();
       
  1490         
       
  1491         // If exists -> Call SetMapping to set LUID.
       
  1492         if( err == KErrNone )
       
  1493             {
       
  1494             HBufC8* uri = HBufC8::NewLC( KNSmlDmBMAdapterBM().Length() + 
       
  1495                                          KNSmlDmBmSeparator().Length() +
       
  1496                                          KSmlMaxURISegLen );
       
  1497                 
       
  1498             TPtr8 uriPtr = uri->Des(); 
       
  1499             uriPtr.Format( KNSmlDmBMAdapterBM );
       
  1500             uriPtr.Append( KNSmlDmBmSeparator );
       
  1501             uriPtr.Append( KNSmlDmBMSNAPNamePrefix ); 
       
  1502             HBufC8* luidBuf = IntToDes8L( snapId );
       
  1503             CleanupStack::PushL( luidBuf );
       
  1504             uriPtr.Append( *luidBuf );
       
  1505     
       
  1506             Callback().SetMappingL( uriPtr, *luidBuf );
       
  1507             
       
  1508             BMADAPTERLOGSTRING2( "Creating mapping for URI %S ", &uriPtr ) 
       
  1509             CleanupStack::PopAndDestroy( luidBuf );
       
  1510             CleanupStack::PopAndDestroy( uri );
       
  1511             }                                          
       
  1512         }                       
       
  1513     return snapId;
       
  1514 }
       
  1515 
       
  1516 TInt CNSmlDmBmAdapter::GetPredefinedSnapIdFromUri( const TDesC8& aURI ) const
       
  1517     {    
       
  1518     TInt ret = KErrNotFound;
       
  1519     
       
  1520     // First check that URI starts with BearerManagementSNAP
       
  1521     TInt startIndex = aURI.Find( KNSmlDmBMAdapterBM );
       
  1522     
       
  1523     if( startIndex == KErrNotFound )
       
  1524         {
       
  1525         return KErrNotFound;
       
  1526         }
       
  1527     
       
  1528     // Then assume there is separator
       
  1529     startIndex += KNSmlDmBMAdapterBM().Length() + KNSmlDmBmSeparator().Length();
       
  1530     
       
  1531     if( startIndex >= aURI.Length() )
       
  1532         {
       
  1533         // No separator. This was an access to ./BearerManagementSNAP
       
  1534         return KErrNotFound;
       
  1535         }
       
  1536     
       
  1537     TPtrC8 predefinedUriStart = aURI.Mid( startIndex  );
       
  1538     
       
  1539     startIndex = predefinedUriStart.Find( KNSmlDmBMSNAPNamePrefix );
       
  1540     
       
  1541     // Result should be zero ( = start of string)
       
  1542     if( startIndex != 0 )
       
  1543         {
       
  1544         return KErrNotFound;
       
  1545         }
       
  1546     
       
  1547     startIndex += KNSmlDmBMSNAPNamePrefix().Length();     
       
  1548     
       
  1549     TInt endIndex = 0;
       
  1550     
       
  1551     endIndex = predefinedUriStart.Find( KNSmlDmBmSeparator );
       
  1552     
       
  1553     
       
  1554     
       
  1555     if ( endIndex == KErrNotFound )
       
  1556         {
       
  1557         TPtrC8 snapId = predefinedUriStart.Mid( startIndex );
       
  1558         TRAPD( err, ret = DesToIntL( snapId ) );
       
  1559         if( err != KErrNone )
       
  1560             {
       
  1561             ret = KErrNotFound;
       
  1562             }       
       
  1563         }
       
  1564     else
       
  1565         {
       
  1566         TPtrC8 snapId = predefinedUriStart.Mid( startIndex, endIndex - startIndex );
       
  1567         TRAPD( err, ret = DesToIntL( snapId ) );
       
  1568         if( err != KErrNone )
       
  1569             {
       
  1570             ret = KErrNotFound;
       
  1571             }       
       
  1572         }    
       
  1573     return ret;    
       
  1574     }
       
  1575 
       
  1576 
       
  1577 
       
  1578 //---------------------- CSmlDmBmCommandElement -------------------------//
       
  1579 
       
  1580 // --------------------------------------------------------------------------
       
  1581 // CSmlDmBmCommandElement* CSmlDmBmCommandElement::NewLC
       
  1582 // --------------------------------------------------------------------------
       
  1583 
       
  1584 CSmlDmBmCommandElement* CSmlDmBmCommandElement::NewLC( TBool aLeaf,
       
  1585                                                        TInt aStatusRef, 
       
  1586                                                        TInt aResultRef, 
       
  1587                                                        CNSmlDmBmAdapter::TCommandType aCmdType,
       
  1588                                                        const TDesC8& aLastUriSeg, 
       
  1589                                                        const TDesC8& aData )
       
  1590     {
       
  1591     CSmlDmBmCommandElement* self = new (ELeave) CSmlDmBmCommandElement( aLeaf, 
       
  1592                                                                         aStatusRef, 
       
  1593                                                                         aResultRef, 
       
  1594                                                                         aCmdType );
       
  1595     CleanupStack::PushL(self);
       
  1596     self->ConstructL( aLastUriSeg, aData );
       
  1597     return self;
       
  1598     }
       
  1599     
       
  1600 // --------------------------------------------------------------------------
       
  1601 // CSmlDmBmCommandElement::~CSmlDmBmCommandElement
       
  1602 // --------------------------------------------------------------------------
       
  1603 CSmlDmBmCommandElement::~CSmlDmBmCommandElement()
       
  1604     {
       
  1605     delete iLastUriSeg;
       
  1606     delete iData;
       
  1607     }
       
  1608     
       
  1609 // --------------------------------------------------------------------------
       
  1610 // CSmlDmBmCommandElement::CSmlDmBmCommandElement
       
  1611 // --------------------------------------------------------------------------
       
  1612 CSmlDmBmCommandElement::CSmlDmBmCommandElement( TBool aLeaf,
       
  1613                                                 TInt aStatusRef, 
       
  1614                                                 TInt aResultRef, 
       
  1615                                                 CNSmlDmBmAdapter::TCommandType  aCmdType )
       
  1616                                                 : iStatus( CSmlDmAdapter::EError ),
       
  1617                                                 iLeaf( aLeaf ),
       
  1618                                                 iStatusRef( aStatusRef ),
       
  1619                                                 iResultRef( aResultRef ),
       
  1620                                                 iCmdType( aCmdType ),
       
  1621                                                 iData( NULL )
       
  1622                                                 
       
  1623     {
       
  1624     }
       
  1625 
       
  1626 // --------------------------------------------------------------------------
       
  1627 // CSmlDmBmCommandElement::ConstructL
       
  1628 // --------------------------------------------------------------------------
       
  1629 void CSmlDmBmCommandElement::ConstructL( const TDesC8& aLastUriSeg, 
       
  1630                                          const TDesC8& aData )
       
  1631     {
       
  1632     iLastUriSeg = aLastUriSeg.AllocL();
       
  1633     iData = aData.AllocL();
       
  1634     }
       
  1635 
       
  1636 //---------------------- CSmlDmBmSettingsElement -------------------------//
       
  1637 
       
  1638 // --------------------------------------------------------------------------
       
  1639 // CSmlDmBmSettingsElement* CSmlDmBmSettingsElement::NewLC
       
  1640 // --------------------------------------------------------------------------
       
  1641 CSmlDmBmSettingsElement* CSmlDmBmSettingsElement::NewLC( const TDesC8& aMappingName )
       
  1642     {
       
  1643     CSmlDmBmSettingsElement* self = new (ELeave) CSmlDmBmSettingsElement();
       
  1644     CleanupStack::PushL(self);
       
  1645     self->ConstructL( aMappingName );
       
  1646     return self;
       
  1647     }
       
  1648 // --------------------------------------------------------------------------
       
  1649 // CSmlDmBmSettingsElement::~CSmlDmBmSettingsElement
       
  1650 // --------------------------------------------------------------------------
       
  1651 CSmlDmBmSettingsElement::~CSmlDmBmSettingsElement()
       
  1652     {
       
  1653     // deallocate all elements
       
  1654     iNodeBuf.ResetAndDestroy();
       
  1655     iNodeBuf.Close();
       
  1656     delete iMappingName;
       
  1657     }
       
  1658 
       
  1659 // --------------------------------------------------------------------------
       
  1660 // CSmlDmBmSettingsElement::CSmlDmBmSettingsElement
       
  1661 // --------------------------------------------------------------------------
       
  1662 CSmlDmBmSettingsElement::CSmlDmBmSettingsElement()
       
  1663                                                 : iExecuted( EFalse ),
       
  1664                                                   iLuid( 0 ),
       
  1665                                                   iMappingName( NULL ) 
       
  1666     {
       
  1667     
       
  1668     }
       
  1669 // --------------------------------------------------------------------------
       
  1670 // CSmlDmBmSettingsElement::ConstructL
       
  1671 // --------------------------------------------------------------------------
       
  1672 void CSmlDmBmSettingsElement::ConstructL( const TDesC8& aMappingName )
       
  1673     {
       
  1674     iMappingName = aMappingName.AllocL();
       
  1675     }