callcontinuity/settingsreader/src/vccsettingsreader.cpp
changeset 0 a4daefaec16c
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Implements VCC setting reader
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <spsettings.h>
       
    21 #include <spproperty.h>
       
    22 #include <spdefinitions.h>
       
    23 #include <spentry.h>
       
    24 
       
    25 #include "vccsettingsreader.h"
       
    26 #include "vccdefinitions.h"
       
    27 
       
    28 #include "rubydebug.h"
       
    29 
       
    30 // CS Service Entry name in SP settings table
       
    31 _LIT( KCSEntryName, "CS" );
       
    32 
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // Returns the domain transfer number from sp settings
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 HBufC* VccSettingsReader::DomainTransferNumberL()
       
    39     {
       
    40     RUBY_DEBUG_BLOCK( "VccSettingsReader::GetDomainTransferNumberL" );
       
    41 
       
    42     return VccSettingsReader::PropertyValueByNameL( ESubPropertyVccVDN );
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Returns the domain transfer URI from sp settings
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 HBufC* VccSettingsReader::DomainTransferUriL()
       
    50     {
       
    51     RUBY_DEBUG_BLOCK( "VccSettingsReader::GetDomainTransferUriL" );
       
    52 
       
    53     return VccSettingsReader::PropertyValueByNameL( ESubPropertyVccVDI );
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // Returns a VCC property value from SP-settings table by
       
    58 // given property name
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 HBufC* VccSettingsReader::PropertyValueByNameL(
       
    62         TServicePropertyName aPropertyName )
       
    63     {
       
    64     RUBY_DEBUG_BLOCK( "VccSettingsReader::GetValueL" );
       
    65 
       
    66     // Create settings object and then the property one
       
    67     CSPSettings* settings = CSPSettings::NewLC();
       
    68 
       
    69     CSPProperty* property = CSPProperty::NewLC();
       
    70 
       
    71     // First we must find what is our vcc service id in sp-settings table
       
    72     // This is done by searching the vcc entry name.
       
    73     TInt vccServiceId( KErrNone );
       
    74 
       
    75      vccServiceId = VccSettingsReader::VccServiceIdL(); 
       
    76     
       
    77     // If the VCC service id was not found, leave.
       
    78     User::LeaveIfError( vccServiceId );
       
    79 
       
    80     settings->FindPropertyL( vccServiceId, aPropertyName, *property );
       
    81 
       
    82     HBufC* value = HBufC::NewLC( KMaxFileName );
       
    83     TPtr valuePtr = value->Des();
       
    84 
       
    85     TInt error = property->GetValue( valuePtr );
       
    86 
       
    87     User::LeaveIfError( error );
       
    88 
       
    89     // Cleanup and return
       
    90     CleanupStack::Pop( value );
       
    91     CleanupStack::PopAndDestroy( property );
       
    92     CleanupStack::PopAndDestroy( settings );
       
    93 
       
    94     RUBY_DEBUG2( "..Value of %d = %S", aPropertyName, value );
       
    95 
       
    96     return value;
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // Returns service id of the CS service
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 TInt VccSettingsReader::CSServiceIdL()
       
   104     {
       
   105     RUBY_DEBUG_BLOCK( "VccSettingsReader::CSServiceIdL" );
       
   106 
       
   107     // Get the service id by entry name
       
   108     return VccSettingsReader::ServiceIdByNameL( KCSEntryName );
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // Returns service id of the VoIP service
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 TInt VccSettingsReader::VoIPServiceIdL()
       
   116     {
       
   117     RUBY_DEBUG_BLOCK( "VccSettingsReader::VoIPServiceIdL" );
       
   118 
       
   119     // Get the VoIP service id.
       
   120     return VccSettingsReader::DoVoIPServiceIdL(
       
   121                     ESubPropertyVccDtVoipServiceId );
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // Returns the id of VCC enabled VoIP service.
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 TInt VccSettingsReader::DoVoIPServiceIdL(
       
   129                 TServicePropertyName aPropertyName )
       
   130     {
       
   131     RUBY_DEBUG_BLOCK( "VccSettingsReader::DoVoIPServiceIdL" );
       
   132 
       
   133     // Create settings object and then the property one
       
   134     CSPSettings* settings = CSPSettings::NewLC();
       
   135 
       
   136     CSPProperty* property = CSPProperty::NewLC();
       
   137 
       
   138     // First we must find what is our vcc service id in sp-settings table
       
   139     // This is done by searching the vcc entry name.
       
   140 
       
   141     TInt vccServiceId( KErrNone );
       
   142 
       
   143     vccServiceId = VccSettingsReader::VccServiceIdL();
       
   144     
       
   145     // If the VCC service id was not found, leave.
       
   146     User::LeaveIfError( vccServiceId );
       
   147 
       
   148     // Now get the VCC enabled VoIP service id. The id is
       
   149     // saved into VCC settings.
       
   150     // First, get the property and then use the property to get its value.
       
   151     settings->FindPropertyL( vccServiceId, aPropertyName, *property );
       
   152 
       
   153     TInt voipId;
       
   154     TInt error = property->GetValue( voipId );
       
   155 
       
   156     User::LeaveIfError( error );
       
   157 
       
   158     // Cleanup and return
       
   159     CleanupStack::PopAndDestroy( property );
       
   160     CleanupStack::PopAndDestroy( settings );
       
   161 
       
   162     RUBY_DEBUG2( "..Value of %d = %d", aPropertyName, voipId );
       
   163 
       
   164     return voipId;
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // Returns the service id by given service entry name
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 TInt VccSettingsReader::ServiceIdByNameL( const TDesC& aEntryName )
       
   172     {
       
   173     RUBY_DEBUG_BLOCK( "VccSettingsReader::ServiceIdL" );
       
   174     RUBY_DEBUG1( "..Entry name to search = %S", &aEntryName );
       
   175 
       
   176     //  Array of service provider IDs
       
   177     // is defined as: typedef RArray<TServiceId> RIdArray
       
   178     // in spdefinitions.h
       
   179     RIdArray serviceIdArray;
       
   180 
       
   181     // KErrNotFound is the default return value if the entry
       
   182     // is not found.
       
   183     TInt serviceId( KErrNotFound );
       
   184 
       
   185     CleanupClosePushL( serviceIdArray );
       
   186 
       
   187     CSPSettings* settings = CSPSettings::NewLC();
       
   188 
       
   189     TInt error( KErrNone );
       
   190 
       
   191     // This should leave if error occurs
       
   192     error = settings->FindServiceIdsL( serviceIdArray );
       
   193 
       
   194     User::LeaveIfError( error );
       
   195 
       
   196     TBool foundEntry( EFalse );
       
   197 
       
   198     for ( TInt i( 0 ); i < serviceIdArray.Count() && !foundEntry; i++ )
       
   199         {
       
   200         CSPEntry* entry = CSPEntry::NewLC();
       
   201         error = settings->FindEntryL( serviceIdArray[i], *entry );
       
   202 
       
   203         User::LeaveIfError( error );
       
   204 
       
   205         if ( entry->GetServiceName() == aEntryName )
       
   206             {
       
   207             serviceId = entry->GetServiceId();
       
   208             foundEntry = ETrue;
       
   209             }
       
   210 
       
   211         CleanupStack::PopAndDestroy( entry );
       
   212         }
       
   213     CleanupStack::PopAndDestroy( settings );
       
   214     CleanupStack::PopAndDestroy( &serviceIdArray );
       
   215 
       
   216     RUBY_DEBUG1( "..Service id = %d", serviceId );
       
   217 
       
   218     return serviceId;
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // Returns service id of the VCC service
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 TInt VccSettingsReader::VccServiceIdL()
       
   226     {
       
   227     RUBY_DEBUG_BLOCK( "VccSettingsReader::VccServiceIdL" );
       
   228 
       
   229     TInt vccServiceId( KErrNone );
       
   230     TInt error( KErrNone );
       
   231     
       
   232     //  Array of service provider IDs
       
   233     // is defined as: typedef RArray<TServiceId> RIdArray
       
   234     // in spdefinitions.h
       
   235     RIdArray serviceIdArray;
       
   236     
       
   237     CleanupClosePushL( serviceIdArray );
       
   238     
       
   239     CSPSettings* settings = CSPSettings::NewLC();
       
   240     
       
   241     // This should leave if error occurs
       
   242     error = settings->FindServiceIdsL( serviceIdArray );
       
   243     
       
   244     User::LeaveIfError( error );
       
   245     
       
   246     TBool foundEntry( EFalse );
       
   247     
       
   248     for ( TInt i( 0 ); i < serviceIdArray.Count() && !foundEntry; i++ )
       
   249           {
       
   250           CSPProperty* property = CSPProperty::NewLC(); 
       
   251           error = settings->FindPropertyL( serviceIdArray[i], ESubPropertyVccVDI, *property ); 
       
   252        
       
   253           if( error == KErrNone )
       
   254               {
       
   255               vccServiceId =  serviceIdArray[i];
       
   256               foundEntry = ETrue;
       
   257               }
       
   258              CleanupStack::PopAndDestroy( property );
       
   259           }
       
   260     CleanupStack::PopAndDestroy( settings );
       
   261     CleanupStack::PopAndDestroy( &serviceIdArray );
       
   262     RUBY_DEBUG1( "VccService id = %d", vccServiceId );
       
   263     
       
   264     return vccServiceId;
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // Returns service id VCC should use for specified call provider plugin 
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 TInt VccSettingsReader::ServiceIdL( TInt aCallProviderPluginUid )
       
   272     {
       
   273     RUBY_DEBUG_BLOCK( "VccSettingsReader::ServiceIdL" );
       
   274     TInt id( KErrNone );
       
   275     
       
   276     switch ( aCallProviderPluginUid )
       
   277     	{
       
   278     	case KVccCallProviderPlugId:
       
   279     		{
       
   280     		id = VccSettingsReader::VccServiceIdL();
       
   281     		}break;
       
   282         case KCSCallProviderPlugId:
       
   283             {
       
   284             id = VccSettingsReader::CSServiceIdL();
       
   285             }break;
       
   286         default:
       
   287             {
       
   288             id = VccSettingsReader::VoIPServiceIdL();
       
   289             }break;
       
   290        	}
       
   291     
       
   292     return id;
       
   293     }
       
   294 
       
   295