convergedcallengine/serviceselector/src/csssettingshandler.cpp
changeset 51 12bc758d6a02
parent 48 78df25012fda
child 53 25b8d29b7c59
equal deleted inserted replaced
48:78df25012fda 51:12bc758d6a02
     1 /*
       
     2 * Copyright (c) 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:  This module contains the implementation of 
       
    15 *              : CSsSettingsHandler class
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 //  INCLUDE FILES
       
    21 #include "csssettingshandler.h"
       
    22 #include "csslogger.h"
       
    23 #include <spdefinitions.h>
       
    24 #include <spproperty.h>
       
    25 #include <spentry.h>
       
    26 
       
    27 // CONSTANTS
       
    28 // Default voip service id that is not really a voip capable.
       
    29 const TInt KSPDefaultVoIPServiceId = 2;
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CSsSettingsHandler::CSsSettingsHandler
       
    35 // C++ constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CSsSettingsHandler::CSsSettingsHandler
       
    40         ( 
       
    41         // None.
       
    42         )
       
    43     {
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CSsSettingsHandler::ConstructL
       
    48 // Symbian 2nd phase constructor can leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 void CSsSettingsHandler::ConstructL()
       
    52     {
       
    53     iSettings = CSPSettings::NewL();
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CSsSettingsHandler::NewL
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CSsSettingsHandler* CSsSettingsHandler::NewL
       
    62         ( 
       
    63         // None.
       
    64         )
       
    65     {
       
    66     CSsSettingsHandler* self = new ( ELeave ) CSsSettingsHandler();
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop( self );
       
    70     return self;
       
    71     }
       
    72 
       
    73 // Destructor
       
    74 CSsSettingsHandler::~CSsSettingsHandler
       
    75         (
       
    76         // None.
       
    77         )
       
    78     {
       
    79     delete iSettings;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CSsSettingsHandler::GetRegisteredServices
       
    84 // Gets registered services.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 TInt CSsSettingsHandler::GetRegisteredServices
       
    88         (
       
    89         CSsConnectionHandler& aConnection, 
       
    90         RArray<TUint>& aServiceIds
       
    91         ) const
       
    92     {
       
    93     TRAPD( ret, DoGetRegisteredServicesL( aConnection,
       
    94                                           aServiceIds ) );
       
    95     
       
    96     return ret;
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CSsSettingsHandler::GetRegisteredServices
       
   101 // Gets all available services.
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 TInt CSsSettingsHandler::GetAllServices
       
   105         (
       
   106         RArray<TUint>& aServiceIds
       
   107         ) const
       
   108     {
       
   109     TRAPD( ret, DoGetAllServicesL( aServiceIds ));
       
   110     
       
   111     return ret;
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CSsSettingsHandler::DoGetRegisteredServicesL
       
   116 // Gets registered services.
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CSsSettingsHandler::DoGetRegisteredServicesL
       
   120         (
       
   121         CSsConnectionHandler& aConnection, 
       
   122         RArray<TUint>& aServiceIds
       
   123         ) const
       
   124     {
       
   125     CSSLOGSTRING("CSSelector::RegisteredServices");
       
   126     
       
   127     //Clear array
       
   128     aServiceIds.Reset();
       
   129     
       
   130     RArray<TUint> temp;
       
   131     CleanupClosePushL( temp );
       
   132     
       
   133     // Get all voip service ids.
       
   134     GetVoipServicesL( temp );
       
   135     
       
   136     for ( TInt ind=0; ind< temp.Count(); ind++ )
       
   137         {
       
   138         // Make sure that the service is registered
       
   139         if ( aConnection.IsVoipServiceRegistered( temp[ind] ) )
       
   140             {
       
   141             // Registered service found
       
   142             User::LeaveIfError( aServiceIds.Append( temp[ind] ) );
       
   143             }
       
   144         
       
   145         } 
       
   146     
       
   147     CSSLOGSTRING2("CSSelector::RegisteredServices count:%d", 
       
   148             aServiceIds.Count());
       
   149     
       
   150     if ( 0 == aServiceIds.Count() )
       
   151         {
       
   152         // Not any services found, leave.
       
   153         User::Leave( KErrNotFound );
       
   154         }
       
   155     
       
   156     CleanupStack::PopAndDestroy( &temp );
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CSsSettingsHandler::DoGetAllServicesL
       
   161 // Gets all available services.
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 void CSsSettingsHandler::DoGetAllServicesL
       
   165         (
       
   166         RArray<TUint>& aServiceIds
       
   167         ) const
       
   168     {
       
   169     CSSLOGSTRING("CSSelector::AllServices");
       
   170     //Clear array
       
   171     aServiceIds.Reset();
       
   172     
       
   173     // Get voip services
       
   174     GetVoipServicesL( aServiceIds );        
       
   175     
       
   176     CSSLOGSTRING2("CSSelector::AllServices count:%d", aServiceIds.Count());
       
   177     
       
   178     if ( 0 == aServiceIds.Count() )
       
   179         {
       
   180         // Not any services found, leave.
       
   181         User::Leave( KErrNotFound );
       
   182         }
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CSsSettingsHandler::GetVoipServicesL
       
   187 // Gets voip services.
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CSsSettingsHandler::GetVoipServicesL
       
   191         (
       
   192         RArray<TUint>& aServiceIds
       
   193         ) const
       
   194     {
       
   195     //Clear array
       
   196     aServiceIds.Reset();
       
   197     
       
   198     RArray<TUint> temp;
       
   199     CleanupClosePushL( temp );
       
   200     
       
   201     // Get all service ids.
       
   202     User::LeaveIfError( iSettings->FindServiceIdsL( temp ) );
       
   203     
       
   204     for ( TInt ind=0; ind< temp.Count(); ind++ )
       
   205         {
       
   206         // Make sure that the service is a voip capable.
       
   207         // For some reason the service id 2 is not voip capable
       
   208         // service (although contains the voip subservice properties) 
       
   209         // so ignore it.
       
   210         if ( KSPDefaultVoIPServiceId != temp[ind] )
       
   211             {
       
   212             TBool voip( EFalse );
       
   213             TRAPD( err, voip = IsVoipServiceL( temp[ind] ) );
       
   214             if ( !err && voip )
       
   215                 {
       
   216                 // Add voip service
       
   217                 User::LeaveIfError( aServiceIds.Append( temp[ind] ) );
       
   218                 }
       
   219             }
       
   220         
       
   221         }
       
   222     
       
   223     CleanupStack::PopAndDestroy( &temp );
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CSsSettingsHandler::IsVoipServiceL
       
   228 // Checks is the service as voip service.
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 TBool CSsSettingsHandler::IsVoipServiceL
       
   232         (
       
   233         TUint aServiceId 
       
   234         ) const
       
   235     {
       
   236     CSPProperty* property = CSPProperty::NewLC();
       
   237     
       
   238     TInt ret = iSettings->FindPropertyL( aServiceId, 
       
   239                                          EPropertyVoIPSubServicePluginId , 
       
   240                                          *property );
       
   241 
       
   242     CleanupStack::PopAndDestroy( property );
       
   243     
       
   244     // If Voip subservice properties found (ret = KErrNone) then return ETrue.
       
   245     if ( KErrNone != ret )
       
   246         {
       
   247         return EFalse;
       
   248         }
       
   249     return ETrue;
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CSsSettingsHandler::GetServiceNamesL
       
   254 // Checks is the service as voip service.
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 void CSsSettingsHandler::GetServiceNamesL
       
   258         (
       
   259         RArray<TUint>& aServiceIds,
       
   260         CDesCArray& aServiceNames
       
   261         ) const
       
   262     {
       
   263     if ( 0 == aServiceIds.Count() )
       
   264         {
       
   265         // Empty array, leave.
       
   266         User::Leave( KErrNotFound );
       
   267         }
       
   268     
       
   269     // Get names of the services.
       
   270     User::LeaveIfError( iSettings->FindServiceNamesL( aServiceIds,
       
   271                                                       aServiceNames ) );
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 // CSsSettingsHandler::BrandIdL
       
   276 // (other items were commented in a header).
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 void CSsSettingsHandler::BrandIdL( TInt aServiceId, TDes8& aBrandId )
       
   280     {
       
   281     CSSLOGSTRING( "CSsSettingsHandler::BrandIdL: =>" );
       
   282 
       
   283     CSPEntry* entry = CSPEntry::NewLC();
       
   284     const CSPProperty* property;
       
   285     RBuf brandId;
       
   286     brandId.CleanupClosePushL();
       
   287     brandId.CreateL( KSPMaxDesLength );
       
   288     
       
   289     User::LeaveIfError(
       
   290         iSettings->FindEntryL( aServiceId, *entry ) );
       
   291 
       
   292     User::LeaveIfError(
       
   293         entry->GetProperty( property, EPropertyBrandId ) );
       
   294 
       
   295     if ( property )
       
   296         {
       
   297         property->GetValue( brandId );
       
   298         }
       
   299 
       
   300     if ( brandId.Length() )
       
   301         {
       
   302         aBrandId.Copy( brandId );
       
   303         }
       
   304 
       
   305     CleanupStack::PopAndDestroy( &brandId );
       
   306     CleanupStack::PopAndDestroy( entry );
       
   307 
       
   308     CSSLOGSTRING( "CSsSettingsHandler::BrandIdL: <=" );
       
   309     }
       
   310 
       
   311 // ================= OTHER EXPORTED FUNCTIONS ===============================
       
   312 
       
   313 //  End of File