convergedconnectionhandler/cchserver/src/cchspshandler.cpp
branchRCL_3
changeset 21 f742655b05bf
parent 20 65a3ef1d5bd0
child 22 d38647835c2e
equal deleted inserted replaced
20:65a3ef1d5bd0 21:f742655b05bf
     1 /*
       
     2 * Copyright (c) 2007-2010 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:  CCCHSPSHandler implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <spsettings.h>
       
    21 #include <spentry.h>
       
    22 #include <spproperty.h>
       
    23 
       
    24 #include "cchspshandler.h"
       
    25 #include "cchlogger.h"
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 // None
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES
       
    31 // None
       
    32 
       
    33 // CONSTANTS
       
    34 // None
       
    35 
       
    36 // MACROS
       
    37 // None
       
    38 
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 // None
       
    41 
       
    42 // MODULE DATA STRUCTURES
       
    43 // None
       
    44 
       
    45 // LOCAL FUNCTION PROTOTYPES
       
    46 // None
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 // None
       
    50 
       
    51 // ============================= LOCAL FUNCTIONS =============================
       
    52 
       
    53 // ============================ MEMBER FUNCTIONS =============================
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CCCHSPSHandler::CCCHSPSHandler
       
    57 // C++ default constructor can NOT contain any code, that might leave.
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CCCHSPSHandler::CCCHSPSHandler( CCCHServerBase& aServer ):
       
    61     iServer( aServer )
       
    62     {
       
    63     // No implementation required
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CCCHSPSHandler::ConstructL
       
    68 // Symbian 2nd phase constructor can leave.
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 void CCCHSPSHandler::ConstructL()
       
    72     {
       
    73     iSettings = CSPSettings::NewL();
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CCCHSPSHandler::NewL
       
    78 // Two-phased constructor.
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 CCCHSPSHandler* CCCHSPSHandler::NewL( CCCHServerBase& aServer )
       
    82     {
       
    83     CCCHSPSHandler* self = CCCHSPSHandler::NewLC( aServer );
       
    84     CleanupStack::Pop( self );
       
    85     return self;
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CCCHSPSHandler::NewLC
       
    90 // Two-phased constructor.
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 CCCHSPSHandler* CCCHSPSHandler::NewLC( CCCHServerBase& aServer )
       
    94     {
       
    95     CCCHSPSHandler* self = new (ELeave) CCCHSPSHandler( aServer );
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL();
       
    98     return self;
       
    99     }
       
   100 
       
   101 // Destructor
       
   102 CCCHSPSHandler::~CCCHSPSHandler()
       
   103     {
       
   104     delete iSettings;
       
   105     iSettings = NULL;
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // CCCHSPSHandler::GetServicesCountL
       
   110 // (other items were commented in a header).
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 TInt CCCHSPSHandler::GetServicesCountL() const
       
   114     {
       
   115     CCHLOGSTRING2( "CCCHSPSHandler::GetServicesCountL : %d", 
       
   116         iSettings->SettingsCountL() );
       
   117             
       
   118     return iSettings->SettingsCountL();
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // CCCHSPSHandler::GetServiceIdsL
       
   123 // (other items were commented in a header).
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 void CCCHSPSHandler::GetServiceIdsL( RArray<TUint>& aServiceIds ) const
       
   127     {
       
   128     CCHLOGSTRING( "CCCHSPSHandler::GetServiceIdsL: IN" );
       
   129     
       
   130     TRAP_IGNORE( iSettings->FindServiceIdsL( aServiceIds ) );
       
   131     
       
   132     CCHLOGSTRING2
       
   133         ( "CCCHSPSHandler::GetServiceIdsL: OUT: %d", aServiceIds.Count() );
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CCCHSPSHandler::GetServiceInfoL
       
   138 // (other items were commented in a header).
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CCCHSPSHandler::GetServiceInfoL( const TUint32 aServiceId, 
       
   142     TCCHService& aService ) const
       
   143     {
       
   144     CCHLOGSTRING( "CCCHSPSHandler::GetServiceInfoL: IN" );
       
   145     
       
   146     aService.iSubservices.Reset();
       
   147     
       
   148     // Get entry
       
   149     TInt err( KErrNone );
       
   150     CSPEntry* entry = CSPEntry::NewLC();
       
   151     err = iSettings->FindEntryL( aServiceId, *entry );
       
   152     
       
   153     if ( KErrNone == err )
       
   154         {
       
   155         // Read service id and service name
       
   156         aService.iServiceId = aServiceId;
       
   157         RBuf buf;
       
   158         CleanupClosePushL( buf );
       
   159         buf.CreateL( entry->GetServiceName(), KCCHMaxServiceNameLength );
       
   160         aService.iServiceName.Copy( buf );
       
   161         CleanupStack::PopAndDestroy( &buf );
       
   162         
       
   163         // Check which subservices are supported
       
   164         RPropertyNameArray propertyNameArray;
       
   165         CleanupClosePushL( propertyNameArray );
       
   166         propertyNameArray.AppendL( EPropertyVoIPSubServicePluginId );
       
   167         propertyNameArray.AppendL( EPropertyPresenceSubServicePluginId );
       
   168         propertyNameArray.AppendL( EPropertyIMSubServicePluginId );
       
   169         propertyNameArray.AppendL( EPropertyVMBXSubServicePluginId );
       
   170         
       
   171         for ( TInt i( 0 ) ; i < propertyNameArray.Count() ; i++ )
       
   172             {
       
   173             CSPProperty* property = CSPProperty::NewLC();
       
   174         
       
   175             err = iSettings->FindPropertyL( 
       
   176                 aServiceId,
       
   177                 propertyNameArray[ i ],
       
   178                 *property );
       
   179             
       
   180             if ( !err && ValidSubserviceL( aServiceId, propertyNameArray[ i ] ) )
       
   181                 {
       
   182                 TCCHSubserviceType type = ECCHUnknown;        
       
   183                 switch ( propertyNameArray[ i ] )
       
   184                     {
       
   185                     case EPropertyVoIPSubServicePluginId:
       
   186                         {
       
   187                         type = ECCHVoIPSub;
       
   188                         }
       
   189                         break;
       
   190                     case EPropertyPresenceSubServicePluginId:
       
   191                         {
       
   192                         type = ECCHPresenceSub;
       
   193                         }
       
   194                         break;
       
   195                     case EPropertyIMSubServicePluginId:
       
   196                         {
       
   197                         type = ECCHIMSub;
       
   198                         }
       
   199                         break;
       
   200                     case EPropertyVMBXSubServicePluginId:
       
   201                         {
       
   202                         type = ECCHVMBxSub;
       
   203                         }
       
   204                         break;
       
   205                     default:
       
   206                         {
       
   207                         type = ECCHUnknown;
       
   208                         break;
       
   209                         }
       
   210                     }
       
   211             
       
   212                 CCHLOGSTRING2( "CCCHSPSHandler::GetServiceInfoL: subservice type=%d", type );
       
   213                 
       
   214                 aService.iSubservices[ i ].iConnectionInfo.iServiceSelection.iType = type;
       
   215                 aService.iSubservices[ i ].iConnectionInfo.iServiceSelection.iServiceId = aServiceId;
       
   216                 
       
   217                 // These are just initialized here. Correct values are got from connectivity plugin
       
   218                 aService.iSubservices[ i ].iState = ECCHUninitialized;
       
   219                 aService.iSubservices[ i ].iSubserviceId = KErrNone;
       
   220                 aService.iSubservices[ i ].iConnectionInfo.iSNAPId = KErrNone;
       
   221                 aService.iSubservices[ i ].iConnectionInfo.iIapId = KErrNone;
       
   222                 aService.iSubservices[ i ].iConnectionInfo.iSNAPLocked = EFalse;
       
   223                 }
       
   224         
       
   225             CleanupStack::PopAndDestroy( property );
       
   226             }
       
   227         
       
   228         CleanupStack::PopAndDestroy( &propertyNameArray );
       
   229         }
       
   230     else
       
   231         {
       
   232         CCHLOGSTRING2( "CCCHSPSHandler::GetServiceInfoL: error getting entry err=%d", err );
       
   233         User::Leave( err );
       
   234         }
       
   235             
       
   236     CleanupStack::PopAndDestroy( entry );
       
   237     
       
   238     CCHLOGSTRING( "CCCHSPSHandler::GetServiceInfoL: OUT" );
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // CCCHSPSHandler::GetConnectivityPluginUidL
       
   243 // (other items were commented in a header).
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 void CCCHSPSHandler::GetConnectivityPluginUidL( TUint32 aServiceId,
       
   247     TCCHSubserviceType aType, 
       
   248     TUid& aUid ) const
       
   249     {
       
   250     CCHLOGSTRING( "CCCHSPSHandler::GetConnectivityPluginUidL: IN" );
       
   251     CCHLOGSTRING2( "CCCHSPSHandler::GetConnectivityPluginUidL: aServiceId %d",
       
   252         aServiceId );
       
   253     CCHLOGSTRING2( "CCCHSPSHandler::GetConnectivityPluginUidL: aType %d",
       
   254         aType );
       
   255         
       
   256     TInt pUid( 0 );
       
   257     TInt error( KErrNone );
       
   258     TServicePropertyName propertyType( EPropertyUnknown ); 
       
   259     
       
   260     switch( aType )
       
   261         {        
       
   262         case ECCHVoIPSub:
       
   263             {
       
   264             propertyType = EPropertyVoIPSubServicePluginId;
       
   265             }
       
   266             break;
       
   267         case ECCHPresenceSub:
       
   268             {
       
   269             propertyType = EPropertyPresenceSubServicePluginId;
       
   270             }
       
   271             break;
       
   272         case ECCHIMSub:
       
   273             {
       
   274             propertyType = EPropertyIMSubServicePluginId;
       
   275             }
       
   276             break;
       
   277         case ECCHVMBxSub:
       
   278             {
       
   279             propertyType = EPropertyVMBXSubServicePluginId;
       
   280             }
       
   281             break;
       
   282         default:
       
   283             error = KErrNotFound;
       
   284             break;
       
   285         }
       
   286    
       
   287     if ( KErrNone == error )
       
   288         {
       
   289         CSPProperty* property = CSPProperty::NewLC();
       
   290         error = iSettings->FindPropertyL( aServiceId, 
       
   291             propertyType, *property );
       
   292             
       
   293         if ( KErrNone == error )
       
   294             {
       
   295             property->GetValue( pUid );
       
   296             // Convert TUint32 to TUid
       
   297             aUid = TUid::Uid( pUid );
       
   298             }
       
   299         else
       
   300             {
       
   301             CCHLOGSTRING2( "CCH: iSettings->FindPropertyL err: %d" , error );
       
   302             User::Leave( error );
       
   303             }
       
   304         CleanupStack::PopAndDestroy( property );
       
   305         }
       
   306         
       
   307     CCHLOGSTRING2( 
       
   308         "CCCHSPSHandler::GetConnectivityPluginUidL: aUid 0x%X", aUid );   
       
   309     }
       
   310         
       
   311 // ---------------------------------------------------------------------------
       
   312 // CCCHSPSHandler::LoadAtStartUpL
       
   313 // (other items were commented in a header).
       
   314 // ---------------------------------------------------------------------------
       
   315 //
       
   316 void CCCHSPSHandler::LoadAtStartUpL( TUint32 aServiceId,
       
   317     TCCHSubserviceType aType,
       
   318     TBool& aEnabled ) const
       
   319     {
       
   320     CCHLOGSTRING2( "CCCHSPSHandler::LoadAtStartUpL: aType %d", aType );   
       
   321     
       
   322     
       
   323     TSPItemType propertyType( EItemTypeNotDefined );
       
   324     TServicePropertyName propertyName( EPropertyUnknown );
       
   325     RPropertyArray subproperties;
       
   326     CleanupClosePushL( subproperties );
       
   327     
       
   328     ChangeToPropertyStyleL( aType, propertyType, propertyName );
       
   329            
       
   330     // Find correct subservice
       
   331     TInt err( iSettings->FindSubServicePropertiesL( 
       
   332         aServiceId, propertyType, subproperties ) );
       
   333     CCHLOGSTRING2( "CCH: iSettings->FindSubServicePropertiesL err: %d" , err );
       
   334     for ( TInt i( 0 ); i < subproperties.Count(); i++ )
       
   335         {
       
   336         // Read subservice's On/Off information 
       
   337         if ( propertyName == subproperties[ i ]->GetName() )
       
   338             {
       
   339             TOnOff onOff( EOONotSet );                
       
   340             subproperties[ i ]->GetValue( onOff );
       
   341             aEnabled = onOff == EOn;
       
   342             i = subproperties.Count();               
       
   343             }
       
   344         }    
       
   345     subproperties.ResetAndDestroy( );
       
   346     CleanupStack::PopAndDestroy( &subproperties );
       
   347     
       
   348     CCHLOGSTRING2( "CCCHSPSHandler::LoadAtStartUpL: aEnabled %d", aEnabled );  
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // CCCHSPSHandler::SetLoadAtStartUpL
       
   353 // (other items were commented in a header).
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 void CCCHSPSHandler::SetLoadAtStartUpL( const TUint32 aServiceId,
       
   357     const TCCHSubserviceType aType,
       
   358     const TBool aOnOff ) const
       
   359     {
       
   360     CCHLOGSTRING2( "CCCHSPSHandler::SetLoadAtStartUpL: aType %d", aType );      
       
   361     CCHLOGSTRING2( "CCCHSPSHandler::SetLoadAtStartUpL: aOnOff %d", aOnOff );   
       
   362     TSPItemType propertyType( EItemTypeNotDefined );
       
   363     TServicePropertyName propertyName( EPropertyUnknown );
       
   364     RPropertyArray subproperties;
       
   365     CleanupClosePushL( subproperties );
       
   366     
       
   367     TOnOff onOff( EOONotSet );
       
   368     onOff = aOnOff ? EOn : EOff;
       
   369     
       
   370     // Get property name
       
   371     ChangeToPropertyStyleL( aType, propertyType, propertyName );
       
   372    
       
   373     CSPProperty* propLoadAtStartUp = CSPProperty::NewLC();
       
   374     
       
   375     propLoadAtStartUp->SetName( propertyName );
       
   376     propLoadAtStartUp->SetValue( onOff );
       
   377     
       
   378     subproperties.Append( propLoadAtStartUp );
       
   379     CleanupStack::Pop( propLoadAtStartUp );
       
   380     TInt err( iSettings->AddOrUpdatePropertiesL( aServiceId, subproperties ) );
       
   381     CCHLOGSTRING2( "CCH: iSettings->AddOrUpdatePropertiesL err: %d" , err );
       
   382     subproperties.ResetAndDestroy();
       
   383     CleanupStack::PopAndDestroy( &subproperties );
       
   384     }
       
   385 
       
   386 // ---------------------------------------------------------------------------
       
   387 // CCCHSPSHandler::ChangeToPropertyStyleL
       
   388 // (other items were commented in a header).
       
   389 // ---------------------------------------------------------------------------
       
   390 //
       
   391 void CCCHSPSHandler::ChangeToPropertyStyleL( 
       
   392     TCCHSubserviceType aType,
       
   393     TSPItemType& aPropertyType,
       
   394     TServicePropertyName& aPropertyName ) const
       
   395     {
       
   396     switch( aType )
       
   397         {
       
   398         case ECCHVoIPSub:
       
   399             {
       
   400             aPropertyType = EItemTypeVoIPSubProperty;
       
   401             aPropertyName = ESubPropertyVoIPEnabled;
       
   402             }
       
   403             break;
       
   404         case ECCHPresenceSub:
       
   405             {
       
   406             aPropertyType = EItemTypePresenceSubProperty;
       
   407             aPropertyName = ESubPropertyPresenceEnabled;
       
   408             }
       
   409             break;
       
   410         case ECCHIMSub:
       
   411             {            
       
   412             aPropertyType = EItemTypeIMSubProperty;
       
   413             aPropertyName = ESubPropertyIMEnabled;
       
   414             }
       
   415             break;
       
   416         case ECCHVMBxSub:
       
   417             {
       
   418             aPropertyType = EItemTypeVMBXSubProperty;
       
   419             aPropertyName = ESubPropertyVMBXEnabled;
       
   420             }
       
   421             break;
       
   422         default:
       
   423             {
       
   424             User::Leave( KErrNotFound );
       
   425             }            
       
   426             break;
       
   427         }        
       
   428     }
       
   429 
       
   430 // ---------------------------------------------------------------------------
       
   431 // CCCHSPSHandler::ValidSubserviceL
       
   432 // (other items were commented in a header).
       
   433 // ---------------------------------------------------------------------------
       
   434 //
       
   435 TBool CCCHSPSHandler::ValidSubserviceL( 
       
   436     const TUint32 aServiceId,
       
   437     TServicePropertyName aPropertyName ) const
       
   438     {
       
   439     CCHLOGSTRING2
       
   440         ( "CCCHSPSHandler::ValidSubservice aServiceId: %d" , aServiceId );
       
   441         
       
   442     TBool valid( EFalse );
       
   443     TInt propertyId( KErrNone );
       
   444     
       
   445     CSPProperty* property = CSPProperty::NewLC();
       
   446     
       
   447     switch( aPropertyName )
       
   448         {
       
   449         case EPropertyVoIPSubServicePluginId:
       
   450             {
       
   451             CCHLOGSTRING( "Subservice: EPropertyVoIPSubServicePluginId" );
       
   452             
       
   453             // Until further notice VoIP property is always valid
       
   454             valid = ETrue;
       
   455             break;
       
   456             }
       
   457         case EPropertyPresenceSubServicePluginId:
       
   458             {
       
   459             CCHLOGSTRING( "Subservice: EPropertyPresenceSubServicePluginId" );
       
   460             
       
   461             valid = KErrNone != iSettings->FindPropertyL( aServiceId, 
       
   462                 ESubPropertyPresenceSettingsId, *property ) ? EFalse :
       
   463                     KErrNone == property->GetValue( propertyId );
       
   464                                 
       
   465             CCHLOGSTRING2( "CCH:     property id: %d" , propertyId );
       
   466             break;
       
   467             }
       
   468         case EPropertyIMSubServicePluginId:
       
   469             {
       
   470             CCHLOGSTRING( "Subservice: EPropertyIMSubServicePluginId" );
       
   471             
       
   472             valid = KErrNone != iSettings->FindPropertyL( aServiceId, 
       
   473                 ESubPropertyIMSettingsId, *property ) ? EFalse :
       
   474                     KErrNone == property->GetValue( propertyId );
       
   475             
       
   476             CCHLOGSTRING2( "CCH:     property id: %d" , propertyId );
       
   477             break;
       
   478             }
       
   479         case EPropertyVMBXSubServicePluginId:
       
   480             {
       
   481             CCHLOGSTRING( "Subservice: EPropertyVMBXSubServicePluginId" );
       
   482             
       
   483             valid = KErrNone != iSettings->FindPropertyL( aServiceId, 
       
   484                 ESubPropertyVMBXSettingsId, *property ) ? EFalse :
       
   485                     KErrNone == property->GetValue( propertyId );
       
   486             
       
   487             CCHLOGSTRING2( "CCH:     property id: %d" , propertyId );
       
   488             break;
       
   489             }
       
   490         default:
       
   491             {
       
   492             // Let other properties go through
       
   493             valid = EFalse;
       
   494             break;
       
   495             }
       
   496         }
       
   497     
       
   498     CleanupStack::PopAndDestroy( property );
       
   499     
       
   500     CCHLOGSTRING2
       
   501         ( "CCCHSPSHandler::ValidSubservice valid: %d" , valid );
       
   502                     
       
   503     return valid;        
       
   504     }
       
   505         
       
   506 // ========================== OTHER EXPORTED FUNCTIONS =======================
       
   507 
       
   508 //  End of File