sysstatemgmt/ssmmapperutility/src/ssmmapperutility.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 * Implementation of CSsmMapperUtility class.
       
    16 *
       
    17 */
       
    18 
       
    19 #include <e32property.h>
       
    20 #include <featdiscovery.h>
       
    21 #include <centralrepository.h>
       
    22 #include <ssm/ssmdomaindefs.h>
       
    23 #include <ssm/ssmstateawaresession.h>
       
    24 #include "ssmmapperutility.h"
       
    25 #include "trace.h"
       
    26 
       
    27 typedef CSsmMapperUtility* (*CreateMapperUtilExtL)();
       
    28 
       
    29 _LIT_SECURE_ID( KStifTestServerSid, 0x102073E4 );
       
    30 _LIT_SECURE_ID( KStifConsoleUiSid, 0x102073DA );
       
    31 _LIT_SECURE_ID( KStifGuiSid, 0x102073DC );
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CSsmMapperUtility::NewL
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 EXPORT_C CSsmMapperUtility* CSsmMapperUtility::NewL()
       
    40     {
       
    41     FUNC_LOG;
       
    42 
       
    43     CSsmMapperUtility* self = new ( ELeave ) CSsmMapperUtility;
       
    44     CleanupStack::PushL( self );
       
    45     self->ConstructL();
       
    46     CleanupStack::Pop( self );
       
    47 
       
    48     return self;
       
    49     }
       
    50 
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CSsmMapperUtility::~CSsmMapperUtility
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CSsmMapperUtility::~CSsmMapperUtility()
       
    57     {
       
    58     FUNC_LOG;
       
    59 
       
    60     delete iExtension;
       
    61     iExtensionLib.Close();
       
    62     }
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CSsmMapperUtility::PsUid
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 TUid CSsmMapperUtility::PsUid( const TUid& aUid )
       
    70     {
       
    71     FUNC_LOG;
       
    72 
       
    73     TUid uid( aUid );
       
    74     if ( iExtension )
       
    75         {
       
    76         uid = iExtension->PsUid( aUid );
       
    77         INFO_2( "PS Uid 0x%08x mapped to 0x%08x", aUid.iUid, uid.iUid );
       
    78         }
       
    79 
       
    80     return uid;
       
    81     }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CSsmMapperUtility::CrUid
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 TUid CSsmMapperUtility::CrUid( const TUid& aUid )
       
    89     {
       
    90     FUNC_LOG;
       
    91 
       
    92     TUid uid( aUid );
       
    93     if ( iExtension )
       
    94         {
       
    95         uid = iExtension->CrUid( aUid );
       
    96         INFO_2( "CR Uid 0x%08x mapped to 0x%08x", aUid.iUid, uid.iUid );
       
    97         }
       
    98 
       
    99     return uid;
       
   100     }
       
   101 
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CSsmMapperUtility::FeatureUid
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 TUid CSsmMapperUtility::FeatureUid( const TUid& aUid )
       
   108     {
       
   109     FUNC_LOG;
       
   110 
       
   111     TUid uid( aUid );
       
   112     if ( iExtension )
       
   113         {
       
   114         uid = iExtension->FeatureUid( aUid );
       
   115         INFO_2( "Feature Uid 0x%08x mapped to 0x%08x", aUid.iUid, uid.iUid );
       
   116         }
       
   117 
       
   118     return uid;
       
   119     }
       
   120 
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CSsmMapperUtility::GetCurrentState
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 TInt CSsmMapperUtility::GetCurrentState( TSsmState& aState ) const
       
   127     {
       
   128     FUNC_LOG;
       
   129 
       
   130     TInt err( KErrNone );
       
   131 
       
   132     if ( iExtension )
       
   133         {
       
   134         err = iExtension->GetCurrentState( aState );
       
   135         ERROR( err, "Error getting state" );
       
   136         }
       
   137     else
       
   138         {
       
   139         RSsmStateAwareSession sas;
       
   140 
       
   141         err = sas.Connect( KUIFrameworkDomain3 );
       
   142         ERROR( err, "Error connecting RSsmStateAwareSession" );
       
   143         if ( err == KErrNone )
       
   144             {
       
   145             aState = sas.State();
       
   146             sas.Close();
       
   147             }
       
   148         }
       
   149 
       
   150     INFO_2( "Current state is %04x.%04x", aState.MainState(), aState.SubState() );
       
   151 
       
   152     return err;
       
   153     }
       
   154 
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CSsmMapperUtility::FeatureStatus
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C TBool CSsmMapperUtility::FeatureStatus( const TUid& aUid )
       
   161     {
       
   162     FUNC_LOG;
       
   163 
       
   164     TBool status( EFalse );
       
   165     CFeatureDiscovery* feat = NULL;
       
   166     TRAPD( err, feat = CFeatureDiscovery::NewL() );
       
   167     ERROR( err, "Error creating CFeatureDiscovery" );
       
   168 
       
   169     if ( err == KErrNone )
       
   170         {
       
   171         TUid uid( FeatureUid( aUid ) );
       
   172         status = feat->IsSupported( uid );
       
   173         INFO_2( "Feature 0x%08x status is %d", uid.iUid, status );
       
   174         delete feat;
       
   175         }
       
   176 
       
   177     return status;
       
   178     }
       
   179 
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // CSsmMapperUtility::CrValue
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 EXPORT_C TInt CSsmMapperUtility::CrValue( const TUid& aUid, TUint32 aKey, TInt& aValue )
       
   186     {
       
   187     FUNC_LOG;
       
   188 
       
   189     TUid uid( CrUid( aUid ) );
       
   190     TInt err( KErrNone );
       
   191     CRepository* repository = NULL;
       
   192 
       
   193     TRAP( err, repository = CRepository::NewL( uid ) );
       
   194     ERROR_1( err, "Error opening repository 0x%08x", uid.iUid );
       
   195 
       
   196     if ( err == KErrNone )
       
   197         {
       
   198         err = repository->Get( aKey, aValue );
       
   199         ERROR_1( err, "Failed to read value of key 0x%08x", aKey );
       
   200         delete repository;
       
   201         }
       
   202 
       
   203     INFO_3( "CR 0x%08x::0x%08x value is %d", uid.iUid, aKey, aValue );
       
   204 
       
   205     return err;
       
   206     }
       
   207 
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // CSsmMapperUtility::CrValue
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 EXPORT_C TInt CSsmMapperUtility::CrValue( const TUid& aUid, TUint32 aKey, TDes& aValue )
       
   214     {
       
   215     FUNC_LOG;
       
   216 
       
   217     TUid uid( CrUid( aUid ) );
       
   218     TInt err( KErrNone );
       
   219     CRepository* repository = NULL;
       
   220 
       
   221     TRAP( err, repository = CRepository::NewL( uid ) );
       
   222     ERROR_1( err, "Error opening repository 0x%08x", uid.iUid );
       
   223 
       
   224     if ( err == KErrNone )
       
   225         {
       
   226         err = repository->Get( aKey, aValue );
       
   227         ERROR_1( err, "Failed to read value of key 0x%08x", aKey );
       
   228         delete repository;
       
   229         }
       
   230 
       
   231     INFO_3( "CR 0x%08x::0x%08x value is '%S'", uid.iUid, aKey, &aValue );
       
   232 
       
   233     return err;
       
   234     }
       
   235 
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CSsmMapperUtility::GetCommandListPath
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 EXPORT_C void CSsmMapperUtility::GetCommandListPath( TDes& aCmdListPath )
       
   242     {
       
   243     FUNC_LOG;
       
   244 
       
   245     if ( iExtension )
       
   246         {
       
   247         iExtension->GetCommandListPath( aCmdListPath );
       
   248         }
       
   249     }
       
   250 
       
   251 
       
   252 // ---------------------------------------------------------------------------
       
   253 // CSsmMapperUtility::CrValue
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 EXPORT_C TBool CSsmMapperUtility::CheckCaps( const RMessagePtr2& aMessage )
       
   257     {
       
   258     FUNC_LOG;
       
   259 
       
   260     TBool ret( EFalse );
       
   261 
       
   262     if ( iExtension )
       
   263         {
       
   264         ret = ETrue;
       
   265         }
       
   266     else if ( aMessage.HasCapability( ECapabilityPowerMgmt ) )
       
   267         {
       
   268         ret = ETrue;
       
   269         }
       
   270     else
       
   271         {
       
   272         INFO( "Client missing the PowerMgmt capability" );
       
   273         }
       
   274 
       
   275     return ret;
       
   276     }
       
   277 
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // CSsmMapperUtility::CSsmMapperUtility
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 EXPORT_C CSsmMapperUtility::CSsmMapperUtility()
       
   284     {
       
   285     FUNC_LOG;
       
   286     }
       
   287 
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CSsmMapperUtility::ConstructL
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CSsmMapperUtility::ConstructL()
       
   294     {
       
   295     FUNC_LOG;
       
   296 
       
   297     TSecureId sid = User::CreatorSecureId();
       
   298 
       
   299     if ( sid.iId == KStifTestServerSid.iId ||
       
   300          sid.iId == KStifConsoleUiSid.iId ||
       
   301          sid.iId == KStifGuiSid.iId )
       
   302         {
       
   303         INFO( "Loading mapper utility stub" );
       
   304         // If the loading process is STIF, load the stub library dynamically.
       
   305         // Errors loading library are not treated worth leaving. With this
       
   306         // approach better coverage for mapper utility can be achieved.
       
   307         _LIT( KSsmMapperUtilityStubLib, "ssmmapperutilstub.dll" );
       
   308 
       
   309         TInt err( iExtensionLib.Load( KSsmMapperUtilityStubLib ) );
       
   310         ERROR( err, "Failed to load stub library!" );
       
   311         User::LeaveIfError( err );
       
   312 
       
   313         // Function at ordinal 1 creates derived CSsmMapperUtility instance
       
   314         TLibraryFunction entry = iExtensionLib.Lookup( 1 );
       
   315 
       
   316         if ( entry )
       
   317             {
       
   318             CreateMapperUtilExtL newL =
       
   319                 reinterpret_cast<CreateMapperUtilExtL >( entry );
       
   320             iExtension = ( *newL )();
       
   321             }
       
   322         else
       
   323             {
       
   324             ERROR( KErrNotFound, "Entry not found!" );
       
   325             User::Leave( KErrNotFound );
       
   326             }
       
   327         }
       
   328     }