omadm/omadmextensions/adapters/nsmldmalwaysonadapter/src/nsmldmalwaysonsettingstore.cpp
changeset 1 4490afcb47b1
equal deleted inserted replaced
0:3ce708148e4d 1:4490afcb47b1
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Provides settings management in Central Repository.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <utf.h>
       
    21 #include <pdpcontextmanagerinternalcrkeys.h>
       
    22 
       
    23 #include "nsmldmalwaysonsettingstore.h"
       
    24 #include "nsmldmalwaysonadapter.h"
       
    25 #include "logger.h"
       
    26 
       
    27 // AWON-PDPC
       
    28 // Values are XY, where X is related to 3G flag and Y is related to 2G flag.
       
    29 // Possible values are:
       
    30 // "00", AlwaysOn is OFF for both 3G and 2G
       
    31 // "10", AlwaysOn is ON for 3G, OFF for 2G
       
    32 // "01", AlwaysOn is OFF for 3G, ON for 2G
       
    33 // "11", AlwaysOn is ON for 3G, ON for 2G
       
    34 const TInt KAwonPdpc_Off3G_Off2G = 00;
       
    35 const TInt KAwonPdpc_Off3G_On2G  = 01;
       
    36 const TInt KAwonPdpc_On3G_Off2G  = 10;
       
    37 const TInt KAwonPdpc_On3G_On2G   = 11;
       
    38 
       
    39 const TInt KBufSize = 10;
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CNSmlDmAOSettingStore::NewL
       
    43 // -----------------------------------------------------------------------------
       
    44 CNSmlDmAOSettingStore* CNSmlDmAOSettingStore::NewL( CNSmlDmAOAdapter * aAdapter )
       
    45     {
       
    46     CNSmlDmAOSettingStore* self = new (ELeave) CNSmlDmAOSettingStore( aAdapter );
       
    47     CleanupStack::PushL(self);
       
    48     self->ConstructL();
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CNSmlDmAOSettingStore::CNSmlDmAOSettingStore
       
    55 // -----------------------------------------------------------------------------
       
    56 CNSmlDmAOSettingStore::CNSmlDmAOSettingStore( CNSmlDmAOAdapter * aAdapter ) 
       
    57     : iAdapter( aAdapter )
       
    58     {
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CNSmlDmAOSettingStore::ConstructL
       
    63 // -----------------------------------------------------------------------------
       
    64 void CNSmlDmAOSettingStore::ConstructL()
       
    65     {   
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CNSmlDmAOSettingStore::~CNSmlDmAOSettingStore
       
    70 // -----------------------------------------------------------------------------
       
    71 CNSmlDmAOSettingStore::~CNSmlDmAOSettingStore()
       
    72     {
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CNSmlDmAOSettingStore::ExecuteCmdL
       
    77 // Executes a single command
       
    78 // -----------------------------------------------------------------------------
       
    79 void CNSmlDmAOSettingStore::ExecuteCmdL( CSmlDmAOCommandElement& aCmd, TUint aLuid)
       
    80     {   
       
    81     if( !aCmd.Leaf() )
       
    82         {
       
    83         ExecuteVendorConfigCmdL( aCmd, aLuid );
       
    84         }
       
    85     else 
       
    86         {
       
    87         CRepository* cenrep = CRepository::NewL( KCRUidPDPContextManager );
       
    88         CleanupStack::PushL( cenrep );
       
    89         
       
    90         // name
       
    91         if ( !aCmd.LastUriSeg()->Compare( KNSmlDmAOAdapterName ) )
       
    92             {
       
    93             ExecuteNameCmdL( aCmd, cenrep );            
       
    94             }
       
    95         // awon-pdpc
       
    96         else if ( !aCmd.LastUriSeg()->Compare( KNSmlDmAOAdapterAwonPdpc ) )
       
    97             {
       
    98             ExecuteAwonPdpcCmdL( aCmd, cenrep );
       
    99             } 
       
   100         // t-retry
       
   101         else if ( !aCmd.LastUriSeg()->Compare( KNSmlDmAOAdapterTRetry ) )
       
   102             {
       
   103             ExecuteTRetryCmdL( aCmd, cenrep ); 
       
   104             } 
       
   105         else
       
   106             {
       
   107             // invalid node
       
   108             LOGSTRING( "ExecuteCmdL: Error, Invalid node name" );
       
   109             aCmd.SetStatus( CSmlDmAdapter::ENotFound );
       
   110             }
       
   111                          				    
       
   112         aCmd.SetExecuted( ETrue );
       
   113         
       
   114         CleanupStack::PopAndDestroy( cenrep );    
       
   115         }   
       
   116     }    
       
   117 
       
   118 	 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CNSmlDmAOSettingStore::GetVendorConfigsL
       
   121 // Fetches all VENDORCONFIG ids
       
   122 // -----------------------------------------------------------------------------
       
   123 void CNSmlDmAOSettingStore::GetVendorConfigsL( RArray<TUint32>& aLUIDArray )
       
   124         {
       
   125         // Only one VENDORCONFIG node possible at the moment
       
   126         aLUIDArray.Append( KDefaultLuid );
       
   127         }
       
   128  
       
   129 // -----------------------------------------------------------------------------
       
   130 // CNSmlDmAOSettingStore::ExecuteVendorConfigCmdL
       
   131 // Executes a command for VENDORCONFIG node. Either delete or get, adds are handled 
       
   132 // in StoreVendorConfigL
       
   133 // -----------------------------------------------------------------------------
       
   134 void CNSmlDmAOSettingStore::ExecuteVendorConfigCmdL( CSmlDmAOCommandElement& aCmd, 
       
   135                                                      TUint /*aLuid*/ )
       
   136     {
       
   137     
       
   138     if ( aCmd.CmdType() == CNSmlDmAOAdapter::EGetCmd )
       
   139         {
       
   140         aCmd.SetData( KNSmlDmAOAllLeafNodes().AllocL() );
       
   141         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   142         aCmd.SetExecuted( ETrue );
       
   143         }
       
   144     else if ( aCmd.CmdType() == CNSmlDmAOAdapter::EDeleteCmd )
       
   145         {
       
   146         // Should not be possible to delete
       
   147         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   148         aCmd.SetExecuted( ETrue );
       
   149         }
       
   150     else
       
   151         {
       
   152         LOGSTRING( "ExecuteVendorConfigCmdL: Error, Invalid cmd type" );
       
   153         aCmd.SetStatus( CSmlDmAdapter::EError );
       
   154         }
       
   155     }
       
   156 
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CNSmlDmAOSettingStore::ExecuteNameCmdL
       
   160 // Executes NAME command (add or get )
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CNSmlDmAOSettingStore::ExecuteNameCmdL( CSmlDmAOCommandElement& aCmd, 
       
   164                                              CRepository*         /*aCenrep*/ )
       
   165     {
       
   166     if ( aCmd.CmdType() == CNSmlDmAOAdapter::EAddCmd )
       
   167         {
       
   168         HBufC* name = HBufC::NewLC( aCmd.Data()->Size() );
       
   169         TPtr namePtr = name->Des();
       
   170         CnvUtfConverter::ConvertToUnicodeFromUtf8( namePtr, *aCmd.Data() );
       
   171 
       
   172         // name is not written to the CentralRepository
       
   173         // Add write to CR here
       
   174 
       
   175         CleanupStack::PopAndDestroy( name );
       
   176         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   177         }        		
       
   178     else if ( aCmd.CmdType() == CNSmlDmAOAdapter::EGetCmd ||
       
   179               aCmd.CmdType() == CNSmlDmAOAdapter::EGetSizeCmd )
       
   180         {
       
   181         // name is not written/read to/from the CentralRepository
       
   182         // Add read from CR here
       
   183         
       
   184         //HBufC* data = ...read name
       
   185         
       
   186         //HBufC8* data8 = HBufC8::NewLC( data->Size() );
       
   187         //TPtr8 toPtr = data8->Des();        
       
   188         //CnvUtfConverter::ConvertFromUnicodeToUtf8( toPtr, *data );
       
   189         //aCmd.SetData( data8 );
       
   190         //CleanupStack::Pop( data8 );
       
   191         //CleanupStack::PopAndDestroy( data );
       
   192 
       
   193         // for size command, set the command data to be the 
       
   194         // size of the fetched data
       
   195         
       
   196         //if( aCmd.CmdType() == CNSmlDmAOAdapter::EGetSizeCmd )
       
   197         //    {            
       
   198         //    HBufC8* size = iAdapter->IntToDes8L( aCmd.Data()->Size() );
       
   199         //    aCmd.SetData( size );
       
   200         //    }                
       
   201         
       
   202         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   203         aCmd.SetExecuted( ETrue );
       
   204         }
       
   205     else    
       
   206         {
       
   207         // unsupported command
       
   208         // this is checked by framework
       
   209         aCmd.SetStatus( CSmlDmAdapter::EError );
       
   210         LOGSTRING( "ExecuteNameCmdL: Error, Only Add, Get and Get size commands supported" );
       
   211         }  
       
   212     }
       
   213     
       
   214 // ---------------------------------------------------------------------------
       
   215 // CNSmlDmAOSettingStore::ExecuteAwonPdpcCmdL
       
   216 // Executes AWON-PDPC command (add or get )
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 void CNSmlDmAOSettingStore::ExecuteAwonPdpcCmdL( CSmlDmAOCommandElement& aCmd, 
       
   220                                                  CRepository*         aCenrep )
       
   221     {
       
   222     if ( aCmd.CmdType() == CNSmlDmAOAdapter::EAddCmd )
       
   223         {
       
   224         HBufC* data = HBufC::NewLC( aCmd.Data()->Size() );
       
   225         TPtr dataPtr = data->Des();
       
   226         CnvUtfConverter::ConvertToUnicodeFromUtf8( dataPtr, *aCmd.Data() );
       
   227 
       
   228         // write to the CentralRepository
       
   229         TInt value( 0 );
       
   230         TInt hplmn( 0 );
       
   231         TInt vplmn( 0 );
       
   232         
       
   233         ParseIntegerL( dataPtr, value );
       
   234         ParseAwonPdpcValuesL( value, hplmn, vplmn );
       
   235         
       
   236         User::LeaveIfError( aCenrep->Set( KPDPContextManagerEnableWhenHome,
       
   237         hplmn ) );
       
   238         User::LeaveIfError( aCenrep->Set( KPDPContextManagerEnableWhenRoaming,
       
   239         vplmn ) );
       
   240 
       
   241         CleanupStack::PopAndDestroy( data );
       
   242         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   243         }        		
       
   244     else if ( aCmd.CmdType() == CNSmlDmAOAdapter::EGetCmd ||
       
   245               aCmd.CmdType() == CNSmlDmAOAdapter::EGetSizeCmd )
       
   246         {
       
   247         // read from CentralRepository
       
   248         TInt hplmn( 0 );
       
   249         TInt vplmn( 0 );
       
   250         
       
   251         User::LeaveIfError(
       
   252         aCenrep->Get( KPDPContextManagerEnableWhenHome, hplmn ) );
       
   253         User::LeaveIfError(
       
   254         aCenrep->Get( KPDPContextManagerEnableWhenRoaming, vplmn ) );
       
   255         
       
   256         HBufC* data    = HBufC::NewLC( KBufSize );
       
   257         TPtr   dataPtr = data->Des();
       
   258         
       
   259         dataPtr.Zero();
       
   260         dataPtr.FillZ();
       
   261         dataPtr.AppendNum( hplmn );
       
   262         dataPtr.AppendNum( vplmn );
       
   263         
       
   264         HBufC8* data8 = HBufC8::NewLC( data->Size() );
       
   265         TPtr8 toPtr = data8->Des();        
       
   266         CnvUtfConverter::ConvertFromUnicodeToUtf8( toPtr, *data );
       
   267         aCmd.SetData( data8 );
       
   268         CleanupStack::Pop( data8 );
       
   269         CleanupStack::PopAndDestroy( data );
       
   270 
       
   271         // for size command, set the command data to be the 
       
   272         // size of the fetched data
       
   273         if( aCmd.CmdType() == CNSmlDmAOAdapter::EGetSizeCmd )
       
   274             {            
       
   275             HBufC8* size = iAdapter->IntToDes8L( aCmd.Data()->Size() );
       
   276             aCmd.SetData( size );
       
   277             }                
       
   278         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   279         aCmd.SetExecuted( ETrue );
       
   280         }
       
   281     else    
       
   282         {
       
   283         // unsupported command
       
   284         // this is checked by framework
       
   285         aCmd.SetStatus( CSmlDmAdapter::EError );
       
   286         LOGSTRING( "ExecuteNameCmdL: Error, Only Add, Get and Get size commands supported" );
       
   287         }  
       
   288     }
       
   289     
       
   290  // ---------------------------------------------------------------------------
       
   291 // CNSmlDmAOSettingStore::ExecuteTRetryCmdL
       
   292 // Executes T-RETRY command (add or get )
       
   293 // ---------------------------------------------------------------------------
       
   294 //
       
   295 void CNSmlDmAOSettingStore::ExecuteTRetryCmdL( CSmlDmAOCommandElement& aCmd, 
       
   296                                                CRepository*            aCenrep )
       
   297     {
       
   298     if ( aCmd.CmdType() == CNSmlDmAOAdapter::EAddCmd )
       
   299         {
       
   300         HBufC* data = HBufC::NewLC( aCmd.Data()->Size() );
       
   301         TPtr dataPtr = data->Des();
       
   302         CnvUtfConverter::ConvertToUnicodeFromUtf8( dataPtr, *aCmd.Data() );
       
   303 
       
   304         // write to the CentralRepository
       
   305         TInt value( 0 );
       
   306         ParseIntegerL( dataPtr, value );
       
   307         
       
   308         User::LeaveIfError( aCenrep->Set( KPDPContextManagerRetryTimer,
       
   309                             value ) );
       
   310 
       
   311         CleanupStack::PopAndDestroy( data );
       
   312         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   313         }        		
       
   314     else if ( aCmd.CmdType() == CNSmlDmAOAdapter::EGetCmd ||
       
   315               aCmd.CmdType() == CNSmlDmAOAdapter::EGetSizeCmd )
       
   316         {
       
   317         // Read from CentralRepository
       
   318         TInt value( 0 );
       
   319         User::LeaveIfError( aCenrep->Get( KPDPContextManagerRetryTimer,
       
   320                             value ) );
       
   321         
       
   322         HBufC* data    = HBufC::NewLC( KBufSize );
       
   323         TPtr   dataPtr = data->Des();
       
   324         
       
   325         dataPtr.Zero();
       
   326         dataPtr.FillZ();
       
   327         dataPtr.AppendNum( value );
       
   328         
       
   329         HBufC8* data8 = HBufC8::NewLC( data->Size() );
       
   330         TPtr8 toPtr = data8->Des();        
       
   331         CnvUtfConverter::ConvertFromUnicodeToUtf8( toPtr, *data );
       
   332         aCmd.SetData( data8 );
       
   333         CleanupStack::Pop( data8 );
       
   334         CleanupStack::PopAndDestroy( data );
       
   335 
       
   336         // for size command, set the command data to be the 
       
   337         // size of the fetched data
       
   338         if( aCmd.CmdType() == CNSmlDmAOAdapter::EGetSizeCmd )
       
   339             {            
       
   340             HBufC8* size = iAdapter->IntToDes8L( aCmd.Data()->Size() );
       
   341             aCmd.SetData( size );
       
   342             }                
       
   343         aCmd.SetStatus( CSmlDmAdapter::EOk );
       
   344         aCmd.SetExecuted( ETrue );
       
   345         }
       
   346     else    
       
   347         {
       
   348         // unsupported command
       
   349         // this is checked by framework
       
   350         aCmd.SetStatus( CSmlDmAdapter::EError );
       
   351         LOGSTRING( "ExecuteNameCmdL: Error, Only Add, Get and Get size commands supported" );
       
   352         }  
       
   353     }
       
   354     
       
   355 // -----------------------------------------------------------------------------
       
   356 // CNSmlDmAOSettingStore::ParseIntegerL
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 void CNSmlDmAOSettingStore::ParseIntegerL( const TDesC& aPtr, TInt& aInt )
       
   360     {
       
   361     TLex lex( aPtr );
       
   362     User::LeaveIfError( lex.Val( aInt ) );
       
   363     }
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CNSmlDmAOSettingStore::ParseAwonPdpcValuesL
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 void CNSmlDmAOSettingStore::ParseAwonPdpcValuesL( const TInt aInt,
       
   370                                                   TInt& aHplmn,
       
   371                                                   TInt& aVplmn )
       
   372     {
       
   373     switch( aInt )
       
   374         {
       
   375         case KAwonPdpc_Off3G_Off2G:
       
   376             aHplmn = 0;
       
   377             aVplmn = 0;
       
   378             break;
       
   379         case KAwonPdpc_Off3G_On2G:
       
   380             aHplmn = 0;
       
   381             aVplmn = 1;
       
   382             break;
       
   383         case KAwonPdpc_On3G_Off2G:
       
   384             aHplmn = 1;
       
   385             aVplmn = 0;
       
   386             break;
       
   387         case KAwonPdpc_On3G_On2G:
       
   388             aHplmn = 1;
       
   389             aVplmn = 1;
       
   390             break;
       
   391         default:
       
   392             User::Leave( KErrNotSupported );
       
   393             break;
       
   394         }
       
   395     }           
       
   396