resourcemgmt/hwresourcesmgr/server/src/HWRMServer.cpp
changeset 0 4e1aa6a622a0
child 20 1ddbe54d0645
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <ecom/ecom.h>
       
    21 #include <centralrepository.h>
       
    22 #include <featureuids.h>
       
    23 #include "HWRMClient.h"            // THWRMResourceType
       
    24 #include "HWRMClientServer.h"
       
    25 #include "HWRMVibraClientServer.h"
       
    26 #include "HWRMLightClientServer.h"
       
    27 #include "HWRMPowerClientServer.h"
       
    28 #include "HWRMFmTxClientServer.h"
       
    29 #include "HWRMServer.h"
       
    30 #include "HWRMSession.h"
       
    31 #include "HWRMConfiguration.h"
       
    32 #include "HWRMPluginHandler.h"  
       
    33 #include "HWRMVibraCommands.h"  
       
    34 #include "HWRMLightCommands.h"  
       
    35 #include "HWRMPowerCommands.h" 
       
    36 #include "HWRMFmTxCommands.h"
       
    37 #include "HWRMtrace.h"
       
    38 #include "HWRMVibraCommonService.h"
       
    39 #include "HWRMVibraCommonData.h"
       
    40 #include "HWRMLightCommonData.h"
       
    41 #include "HWRMPowerCommonData.h"
       
    42 #include "HWRMFmTxCommonData.h"
       
    43 #include "HWRMFmTxStateUtility.h"
       
    44 #include "HWRMReservationHandler.h"
       
    45 #include "HWRMPolicy.h"
       
    46 #include "HWRMPowerStatePluginHandler.h"
       
    47 #include "HWRMPrivatePSKeys.h"
       
    48 #include "HWRMDomainPSKeys.h"
       
    49 #include "HWRMPrivateCRKeys.h"
       
    50 #include "HWRMFeatureMgr.h"
       
    51 
       
    52 // EXTERNAL DATA STRUCTURES
       
    53 // None
       
    54 
       
    55 // EXTERNAL FUNCTION PROTOTYPES  
       
    56 // None
       
    57 
       
    58 // CONSTANTS
       
    59 
       
    60 // ------------------- Policy Server Security Setup ----------------------
       
    61 
       
    62 const TUint  KRangeCount = 12;
       
    63 
       
    64 const TInt KIPCRanges[KRangeCount] =
       
    65 	{
       
    66 	EHWRMCreateVibraService,			// first createSevice IPC (==0)
       
    67 	EHWRMEndOfCreateServiceOpCodes,
       
    68 	EHWRMLightsOn,						// first light IPC (==1000)
       
    69 	EHWRMEndOfLightOpCodes,
       
    70 	EHWRMStartVibraDefaultIntensity,	// first vibra IPC (==2000)
       
    71 	EHWRMEndOfVibraOpCodes,
       
    72 	EHWRMGetBatteryInfo,				// first power IPC (==3000)
       
    73 	EHWRMEndOfPowerOpCodes,
       
    74 	EHWRMFmTxOn, 						// first fmTx IPC (==4000)
       
    75 	EHWRMFmTxSetRdsPty,
       
    76 	EHWRMFmTxReserve,
       
    77 	EHWRMEndOfFmTxOpCodes
       
    78 	};
       
    79 
       
    80 /**
       
    81  Specifies the appropriate action to take for each range in KRanges.
       
    82  The n:th element of KElementsIndex specifies the appropriate action to take for the n:th range in KRanges.
       
    83 */
       
    84 
       
    85 #ifdef HWRM_FMTX_POLICY_CHECKING_DISABLED
       
    86 const TUint8 KElementsIndex[KRangeCount] =
       
    87 	{
       
    88 	CPolicyServer::EAlwaysPass,
       
    89 	CPolicyServer::ENotSupported,
       
    90 	CPolicyServer::EAlwaysPass,
       
    91 	CPolicyServer::ENotSupported,
       
    92 	CPolicyServer::EAlwaysPass,
       
    93 	CPolicyServer::ENotSupported,
       
    94 	CPolicyServer::EAlwaysPass,
       
    95 	CPolicyServer::ENotSupported,
       
    96 	CPolicyServer::EAlwaysPass,
       
    97 	CPolicyServer::EAlwaysPass,
       
    98 	CPolicyServer::EAlwaysPass,
       
    99 	CPolicyServer::ENotSupported
       
   100 	};
       
   101 
       
   102 const CPolicyServer::TPolicyElement KHWRMPolicyElements[] ={{}};
       
   103 
       
   104 #else
       
   105 const TUint8 KElementsIndex[KRangeCount] =
       
   106 	{
       
   107 	CPolicyServer::EAlwaysPass,
       
   108 	CPolicyServer::ENotSupported,
       
   109 	CPolicyServer::EAlwaysPass,
       
   110 	CPolicyServer::ENotSupported,
       
   111 	CPolicyServer::EAlwaysPass,
       
   112 	CPolicyServer::ENotSupported,
       
   113 	CPolicyServer::EAlwaysPass,
       
   114 	CPolicyServer::ENotSupported,
       
   115 	0,
       
   116 	1,
       
   117 	CPolicyServer::EAlwaysPass,
       
   118 	CPolicyServer::ENotSupported
       
   119 	};
       
   120 
       
   121 /**
       
   122  Array containing the different security checks performed by this server
       
   123  */
       
   124 const CPolicyServer::TPolicyElement KHWRMPolicyElements[] =
       
   125 	{
       
   126 	{_INIT_SECURITY_POLICY_C1(ECapabilityMultimediaDD), CPolicyServer::EFailClient},
       
   127 	{_INIT_SECURITY_POLICY_C2(ECapabilityMultimediaDD, ECapabilityWriteUserData), CPolicyServer::EFailClient}
       
   128 	};
       
   129 #endif //HWRM_FMTX_POLICY_CHECKING_DISABLED 
       
   130 
       
   131 /**
       
   132  Setup a security policy.
       
   133 */
       
   134 const CPolicyServer::TPolicy KHWRMServerPolicy =
       
   135 	{
       
   136 	CPolicyServer::EAlwaysPass, // connection attempts always pass
       
   137 	KRangeCount,
       
   138 	KIPCRanges,
       
   139 	KElementsIndex,
       
   140 	KHWRMPolicyElements
       
   141 	}; 
       
   142 
       
   143 // MACROS
       
   144 // None
       
   145 
       
   146 // LOCAL CONSTANTS AND MACROS
       
   147 _LIT( KPanicCategory, "HWRMServer" );
       
   148 const TInt KDefaultPluginTimeout = 10000000;
       
   149 
       
   150 // MODULE DATA STRUCTURES
       
   151 // None
       
   152 
       
   153 // LOCAL FUNCTION PROTOTYPES
       
   154 // None
       
   155 
       
   156 // FORWARD DECLARATIONS
       
   157 // None
       
   158 
       
   159 // ============================= LOCAL FUNCTIONS ===============================
       
   160 
       
   161 // ============================ MEMBER FUNCTIONS ===============================
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CHWRMServer::CHWRMServer
       
   165 // C++ default constructor can NOT contain any code, that
       
   166 // might leave.
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 CHWRMServer::CHWRMServer( const TInt aPriority, const TServerType aType  )
       
   170     : CPolicyServer( aPriority, KHWRMServerPolicy, aType ),
       
   171     iPluginTimeout(KDefaultPluginTimeout)
       
   172     {
       
   173     // Nothing to do
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CHWRMServer::ConstructL
       
   178 // Symbian 2nd phase constructor can leave.
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CHWRMServer::ConstructL()
       
   182     {
       
   183     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMServer::ConstructL()" ) );
       
   184  
       
   185     TInt err(KErrNone);
       
   186     TInt chargerBlockVibra(ETrue);
       
   187     TInt chargerBlockFeedbackVibra(ETrue);
       
   188     
       
   189     // Open settings repository and get necessary values
       
   190     CRepository* repository = NULL;
       
   191     TRAP( err, repository = CRepository::NewL(KCRUidHWRMSettings) );
       
   192     
       
   193     if ( err == KErrNone )
       
   194         {
       
   195         TInt value(0);
       
   196         err = repository->Get(KHWRMPluginTimeout, value);
       
   197         if ( err == KErrNone )
       
   198             {
       
   199             if ( value > 0 )
       
   200                 {
       
   201                 iPluginTimeout = value*1000; // Value is in milliseconds
       
   202                 }
       
   203             }
       
   204         else
       
   205             {
       
   206             COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::ConstructL - KHWRMPluginTimeout value getting failed: %d, using default" ), err);
       
   207             }
       
   208             
       
   209         err = repository->Get(KHWRMInternalSettings, value);
       
   210         if ( err == KErrNone )
       
   211             {
       
   212             chargerBlockVibra = (value & KHWRMInternalSettingsChargerBlockVibra) ? ETrue : EFalse;
       
   213             chargerBlockFeedbackVibra = (value & KHWRMInternalSettingsChargerBlockFeedback) ? ETrue : EFalse;
       
   214             }
       
   215         else
       
   216             {
       
   217             COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::ConstructL - KHWRMInternalSettings value getting failed: %d, using default" ), err );
       
   218             }
       
   219         }
       
   220     else
       
   221         {
       
   222         COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::ConstructL - KCRUidHWRMSettings repository opening failed: %d" ), err);
       
   223         }
       
   224 
       
   225     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::ConstructL - pluginTimeout: %d" ), iPluginTimeout);
       
   226     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::ConstructL - chargerBlockVibra: %d" ), chargerBlockVibra);
       
   227     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::ConstructL - chargerBlockFeedbackVibra: %d" ), chargerBlockFeedbackVibra);
       
   228     
       
   229     // Read priority setting and set HWRM priority accordingly
       
   230     TInt priority(0);
       
   231     err = repository->Get(KHWRMPriority, priority);
       
   232     if ( err == KErrNone )
       
   233         {
       
   234         TProcessPriority procPrio( static_cast<TProcessPriority>(priority) );
       
   235         COMPONENT_TRACE3(_L("HWRM Server - CHWRMServer::ConstructL - current priority: %d \
       
   236             new priority %d" ), RProcess().Priority(), procPrio);
       
   237         RProcess().SetPriority( procPrio );
       
   238         COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::ConstructL - priority now: %d" ), RProcess().Priority() );
       
   239         }
       
   240     
       
   241     // Cleanup repository
       
   242     delete repository;
       
   243     repository = NULL;
       
   244 
       
   245     // Create light handlers and common data (vibra ones are created when vibra is first needed)
       
   246     TRAP(err, iLightPluginHandler = CHWRMPluginHandler::NewL( KHWRMLightApiEComMatch, iPluginTimeout ));
       
   247     if ( err != KErrNone )
       
   248         {
       
   249         // Light not supported by the device, set handler to null
       
   250         COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::ConstructL() - Light not supported, error: %d" ), err );
       
   251         iLightPluginHandler = NULL;
       
   252         }
       
   253     else
       
   254         {
       
   255         TRAP(err, iLightReservationHandler = CHWRMReservationHandler::NewL( KHWRMLightMaxTargets, KLightsPolicyFilename ));
       
   256         if ( err != KErrNone )
       
   257             {
       
   258             // Light not supported by the device, set handler to null
       
   259             COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::ConstructL() - iLightReservationHandler creation, error: %d" ), err );
       
   260             iLightReservationHandler = NULL;
       
   261             }
       
   262         else
       
   263             {
       
   264             TRAP(err, iLightCommonData = CHWRMLightCommonData::NewL(iLightPluginHandler, iLightReservationHandler));
       
   265             if ( err != KErrNone )
       
   266                 {
       
   267                 // Light not supported by the device, set common data to null
       
   268                 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::ConstructL() - CHWRMLightCommonData creation error: %d" ), err );
       
   269                 iLightCommonData = NULL;
       
   270                 }
       
   271             }
       
   272         }
       
   273 
       
   274     // Initialize vibra blocking key
       
   275     User::LeaveIfError(RProperty::Define(KPSUidHWRMPrivate, KHWRMInternalVibraBlocked, RProperty::EInt, KNoCapability, KWriteDeviceDataPolicy));
       
   276 
       
   277     // Initialize keys of HWRM Device Switch API
       
   278     User::LeaveIfError(RProperty::Define( KPSUidHWRM, KHWRMTwistStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy ));
       
   279     RProperty::Set( KPSUidHWRM, KHWRMTwistStatus, EPSHWRMTwistStatusUninitialized );
       
   280     User::LeaveIfError(RProperty::Define( KPSUidHWRM, KHWRMFlipStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy  ));
       
   281     RProperty::Set( KPSUidHWRM, KHWRMFlipStatus, EPSHWRMFlipStatusUninitialized );
       
   282     User::LeaveIfError(RProperty::Define( KPSUidHWRM, KHWRMGripStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy ));
       
   283     RProperty::Set( KPSUidHWRM, KHWRMGripStatus, EPSHWRMGripStatusUninitialized );
       
   284     
       
   285     // Initialize FmTx common data that is needed immediately like P&S keys etc
       
   286     TRAP( err, iFmTxCommonData = CHWRMFmTxCommonData::NewL() );
       
   287     if ( err != KErrNone )
       
   288        {
       
   289        COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::ConstructL() - FmTx common data, error: %d" ), err );
       
   290        iFmTxCommonData = NULL;
       
   291        }
       
   292 
       
   293     // create power state plugin    
       
   294     TRAP( err, iPowerStatePluginHandler = CHWRMPowerStatePluginHandler::NewL(chargerBlockVibra, chargerBlockFeedbackVibra) );
       
   295     if ( err != KErrNone )
       
   296         {
       
   297         // Power state API not supported by the device, set handler to null
       
   298         COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::ConstructL() - Power state not supported, error: %d" ), err );
       
   299         iPowerStatePluginHandler = NULL;
       
   300         }
       
   301 
       
   302     // Set server process system critical
       
   303     User::SetProcessCritical(User::ESystemPermanent);
       
   304     
       
   305     // Add server to active scheduler
       
   306     StartL( KServerProcessName );
       
   307     
       
   308     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMServer::ConstructL - return" ) );
       
   309     }
       
   310 
       
   311 // -----------------------------------------------------------------------------
       
   312 // CHWRMServer::NewL
       
   313 // Two-phased constructor.
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 CHWRMServer* CHWRMServer::NewL(const TInt aPriority)
       
   317     {
       
   318     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::NewL(0x%x)" ), aPriority );
       
   319 
       
   320     CHWRMServer* self = CHWRMServer::NewLC(aPriority);
       
   321     CleanupStack::Pop();
       
   322 
       
   323     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::NewL - return 0x%x" ), self );
       
   324 
       
   325     return self;
       
   326     }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CHWRMServer::NewLC
       
   330 // Two-phased constructor.
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 CHWRMServer* CHWRMServer::NewLC(const TInt aPriority)
       
   334     {
       
   335     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::NewLC(0x%x)" ), aPriority );
       
   336 
       
   337     CHWRMServer* self = new( ELeave ) CHWRMServer(aPriority, EUnsharableSessions);
       
   338     
       
   339     CleanupStack::PushL( self );
       
   340     self->ConstructL();
       
   341 
       
   342     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::NewLC - return 0x%x" ), self );
       
   343 
       
   344     return self;
       
   345     }
       
   346     
       
   347 // -----------------------------------------------------------------------------
       
   348 // Destructor
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 CHWRMServer::~CHWRMServer()
       
   352     {
       
   353     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMServer::~CHWRMServer()" ) );
       
   354 
       
   355     // Close all open sessions
       
   356 	CHWRMSession* session=NULL;
       
   357 	iSessionIter.SetToFirst();
       
   358 	while((session = static_cast<CHWRMSession*>(iSessionIter++)) != NULL)
       
   359 	{
       
   360 		delete session;
       
   361 	}
       
   362 
       
   363     // Delete plugin handlers    
       
   364     delete iPowerStatePluginHandler;
       
   365     delete iVibraPluginHandler;
       
   366     delete iLightPluginHandler;
       
   367 	delete iPowerPluginHandler;
       
   368     delete iFmTxPluginHandler;
       
   369     delete iFmTxWatcherPluginHandler;
       
   370 
       
   371     // Delete reservation handlers    
       
   372     delete iVibraReservationHandler;
       
   373     delete iLightReservationHandler;
       
   374     delete iFmTxReservationHandler;
       
   375 
       
   376     // Delete vibra common service
       
   377     delete iVibraCommonService;
       
   378 
       
   379     // Delete common data
       
   380     delete iVibraCommonData;
       
   381     delete iLightCommonData;
       
   382 	delete iPowerCommonData;
       
   383 	delete iFmTxStateUtility;
       
   384     delete iFmTxCommonData;
       
   385 
       
   386 	// Signal final closure of ecom session
       
   387 	REComSession::FinalClose();
       
   388 
       
   389     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMServer::~CHWRMServer - return") );
       
   390     }
       
   391 
       
   392 
       
   393 // -----------------------------------------------------------------------------
       
   394 // CHWRMServer::NewSessionL
       
   395 // Creates a new CSession2
       
   396 // -----------------------------------------------------------------------------
       
   397 //
       
   398 CSession2* CHWRMServer::NewSessionL( const TVersion& aVersion,
       
   399                                      const RMessage2& /*aMessage*/ ) const
       
   400     {
       
   401 #if defined(_DEBUG) && defined(COMPONENT_TRACE_FLAG)
       
   402     TVersionName name = aVersion.Name();
       
   403     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::NewSessionL(%S)" ), &name);
       
   404 #endif
       
   405 
       
   406     if ( !User::QueryVersionSupported( TVersion( KServerVersionMajor, 
       
   407                                                  KServerVersionMinor, 
       
   408                                                  KServerVersionBuild ), 
       
   409                                                  aVersion ) )
       
   410         {
       
   411         User::Leave( KErrNotSupported );
       
   412         }
       
   413     
       
   414     CSession2* session = CHWRMSession::NewL(*const_cast<CHWRMServer*>(this));
       
   415 
       
   416     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::NewSessionL - return 0x%x" ), session );
       
   417 
       
   418     return( session );
       
   419     }
       
   420 
       
   421 // -----------------------------------------------------------------------------
       
   422 // CHWRMServer::PanicClient
       
   423 // RMessage2::Panic() also completes the message. This is:
       
   424 // (a) important for efficient cleanup within the kernel
       
   425 // (b) a problem if the message is completed a second time
       
   426 // -----------------------------------------------------------------------------
       
   427 //
       
   428 void CHWRMServer::PanicClient(const RMessage2& aMessage,THWRMPanic aPanic)
       
   429     {
       
   430     COMPONENT_TRACE3(_L( "HWRM Server - CHWRMServer::PanicClient(0x%x, 0x%x)" ), aMessage.Handle(), aPanic);
       
   431 
       
   432 	aMessage.Panic(KPanicCategory,aPanic);
       
   433 
       
   434     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMServer::PanicClient - return" ) );
       
   435     }
       
   436 
       
   437    
       
   438 // -----------------------------------------------------------------------------
       
   439 // CHWRMServer::GetPluginHandler
       
   440 // Returns pointer to correct plugin handler.
       
   441 // In case resource is not supported, returns NULL
       
   442 // -----------------------------------------------------------------------------
       
   443 //  
       
   444 CHWRMPluginHandler* CHWRMServer::GetPluginHandler(THWRMResourceType aType)
       
   445     {
       
   446     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::GetPluginHandler(0x%x)" ), aType );
       
   447     
       
   448     CHWRMPluginHandler* retval = NULL;
       
   449     
       
   450     switch(aType)
       
   451         {
       
   452         case HWRMResourceTypeVibra:
       
   453             if ( !iVibraInitAttempted )
       
   454                 {
       
   455                 InitVibra();
       
   456                 }
       
   457             retval = iVibraPluginHandler;
       
   458             break;            
       
   459         case HWRMResourceTypeLight:
       
   460             retval = iLightPluginHandler;
       
   461             break;        
       
   462         case HWRMResourceTypePower:
       
   463         	if ( !iPowerInitAttempted )
       
   464         		{
       
   465             	InitPower();
       
   466             	}
       
   467         	retval = iPowerPluginHandler;
       
   468         	break;        
       
   469         case HWRMResourceTypeFmTx:    
       
   470             if ( !iFmTxInitAttempted )
       
   471                 {
       
   472                 TRAPD( initErr, InitFmTxL() );
       
   473                 if ( initErr != KErrNone )
       
   474                 	{
       
   475                 	COMPONENT_TRACE2( _L("HWRM Server - CHWRMServer::InitFmTxL() error = %d"), initErr );            	
       
   476                 	}
       
   477                 }
       
   478         	retval = iFmTxPluginHandler;
       
   479             break;                   
       
   480         case HWRMResourceTypeFmTxWatcher:
       
   481             retval = iFmTxWatcherPluginHandler;
       
   482         	break;
       
   483         default:
       
   484             // invalid type, just break (i.e. return NULL)
       
   485             break;   
       
   486         }
       
   487         
       
   488     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::GetPluginHandler - return 0x%x" ), retval );
       
   489 
       
   490     return retval;
       
   491     }
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CHWRMServer::GetReservationHandler
       
   495 // Returns pointer to correct reservation handler.
       
   496 // In case resource is not supported, returns NULL
       
   497 // -----------------------------------------------------------------------------
       
   498 //  
       
   499 CHWRMReservationHandler* CHWRMServer::GetReservationHandler(THWRMResourceType aType)
       
   500     {
       
   501     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::GetReservationHandler(0x%x)" ), aType );
       
   502     
       
   503     CHWRMReservationHandler* retval = NULL;
       
   504     
       
   505     switch(aType)
       
   506         {
       
   507         case HWRMResourceTypeVibra:
       
   508             retval = iVibraReservationHandler;
       
   509             break;            
       
   510         case HWRMResourceTypeLight:
       
   511             retval = iLightReservationHandler;
       
   512             break;         
       
   513         case HWRMResourceTypeFmTx:
       
   514         	retval = iFmTxReservationHandler;
       
   515         	break;
       
   516         default:
       
   517             // invalid type, just break (i.e. return NULL)
       
   518             break;   
       
   519         }
       
   520         
       
   521     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::GetReservationHandler - return 0x%x" ), retval );
       
   522 
       
   523     return retval;
       
   524     }
       
   525 
       
   526 // -----------------------------------------------------------------------------
       
   527 // CHWRMServer::GetVibraCommonService
       
   528 // Returns pointer to Vibra common service used to handle overlapping vibration 
       
   529 // requests from all sessions.
       
   530 // -----------------------------------------------------------------------------
       
   531 //  
       
   532 CHWRMVibraCommonService* CHWRMServer::GetVibraCommonService()
       
   533     {
       
   534     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMServer::GetVibraCommonService()" ));
       
   535 
       
   536     CHWRMVibraCommonService* retval = iVibraCommonService;
       
   537     
       
   538     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::GetVibraCommonService - return 0x%x" ), retval );
       
   539 
       
   540     return retval;
       
   541     }
       
   542 
       
   543 // -----------------------------------------------------------------------------
       
   544 // CHWRMServer::GetVibraCommonData
       
   545 // Returns pointer to Vibra common data
       
   546 // -----------------------------------------------------------------------------
       
   547 //  
       
   548 CHWRMVibraCommonData* CHWRMServer::GetVibraCommonData()
       
   549     {
       
   550     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMServer::GetVibraCommonData()" ));
       
   551     
       
   552     CHWRMVibraCommonData* retval = iVibraCommonData;
       
   553     
       
   554     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::GetVibraCommonData - return 0x%x" ), retval );
       
   555 
       
   556     return retval;
       
   557     }
       
   558 // -----------------------------------------------------------------------------
       
   559 // CHWRMServer::GetLightCommonData
       
   560 // Returns pointer to Light common data
       
   561 // -----------------------------------------------------------------------------
       
   562 //  
       
   563 CHWRMLightCommonData* CHWRMServer::GetLightCommonData()
       
   564     {
       
   565     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMServer::GetLightCommonData()" ));
       
   566     
       
   567     CHWRMLightCommonData* retval = iLightCommonData;
       
   568     
       
   569     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::GetLightCommonData - return 0x%x" ), retval );
       
   570 
       
   571     return retval;
       
   572     }
       
   573 
       
   574 // -----------------------------------------------------------------------------
       
   575 // CHWRMServer::GetPowerCommonData
       
   576 // Returns pointer to Power common data
       
   577 // -----------------------------------------------------------------------------
       
   578 //  
       
   579 CHWRMPowerCommonData* CHWRMServer::GetPowerCommonData()
       
   580     {
       
   581     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMServer::GetPowerCommonData()" ));
       
   582     
       
   583     CHWRMPowerCommonData* retval = iPowerCommonData;
       
   584     
       
   585     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::GetPowerCommonData - return 0x%x" ), retval );
       
   586 
       
   587     return retval;
       
   588     }
       
   589 
       
   590 // -----------------------------------------------------------------------------
       
   591 // CHWRMServer::GetFmTxCommonData
       
   592 // Returns pointer to FM Tx common data
       
   593 // -----------------------------------------------------------------------------
       
   594 //  
       
   595 CHWRMFmTxCommonData* CHWRMServer::GetFmTxCommonData()
       
   596     {
       
   597     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMServer::GetFmTxCommonData()" ) );
       
   598     
       
   599     CHWRMFmTxCommonData* retval = iFmTxCommonData;
       
   600     
       
   601     COMPONENT_TRACE2( _L( "HWRM Server - CHWRMServer::GetFmTxCommonData - return 0x%x" ), retval );
       
   602 
       
   603     return retval;
       
   604     }
       
   605 
       
   606 // -----------------------------------------------------------------------------
       
   607 // CHWRMServer::InitVibra
       
   608 // Initialises vibra
       
   609 // -----------------------------------------------------------------------------
       
   610 //  
       
   611 void CHWRMServer::InitVibra()
       
   612     {
       
   613     if ( !iVibraInitAttempted )
       
   614         {
       
   615         iVibraInitAttempted = ETrue;    
       
   616         TInt err;
       
   617         
       
   618         //The feature UID NFeature::KVibra is defined in featureuids.h
       
   619         TBool vibraSupported = HWRMFeatureMgr::IsFeatureSupported(NFeature::KVibra);
       
   620 
       
   621         if ( vibraSupported )
       
   622             {
       
   623             TRAP(err, iVibraPluginHandler = CHWRMPluginHandler::NewL( KHWRMVibraApiEComMatch, iPluginTimeout ));
       
   624             if ( err != KErrNone )
       
   625                 {
       
   626                 // Vibra not supported by the device, set handler to null
       
   627                 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::InitVibra() - Vibra not supported, error: %d" ), err );
       
   628                 iVibraPluginHandler = NULL;
       
   629                 }
       
   630             else
       
   631                 {
       
   632                 TRAP(err, iVibraReservationHandler = CHWRMReservationHandler::NewL( KHWRMVibraMaxTargets, KVibraPolicyFilename ));
       
   633                 if ( err != KErrNone )
       
   634                     {
       
   635                     // Vibra not supported by the device, set handler to null
       
   636                     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::InitVibra() - iVibraReservationHandler creation, error: %d" ), err );
       
   637                     iVibraReservationHandler = NULL;
       
   638                     }
       
   639                 else
       
   640                 	{                	               
       
   641                     TRAP(err, iVibraCommonService = CHWRMVibraCommonService::NewL(iVibraPluginHandler, iVibraReservationHandler));
       
   642                     if ( err != KErrNone )
       
   643                         {
       
   644                         COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::InitVibra() - iVibraCommonService creation, error: %d" ), err );
       
   645                         iVibraCommonService = NULL;
       
   646                         }                	
       
   647                 	else
       
   648                     	{                    	
       
   649 						TRAP(err, iVibraCommonData = CHWRMVibraCommonData::NewL(iVibraPluginHandler, iVibraReservationHandler, *iVibraCommonService));
       
   650                     	if ( err != KErrNone )
       
   651                         	{
       
   652                         	COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::InitVibra() - iVibraCommonData creation, error: %d" ), err );
       
   653                         	}
       
   654                     	}                               
       
   655                 	}
       
   656                 }
       
   657             }
       
   658         else
       
   659             {
       
   660             COMPONENT_TRACE1(_L( "HWRM Server - CHWRMServer::InitVibra() - Vibra not supported in the device." ) );
       
   661             }
       
   662         }
       
   663     }
       
   664 
       
   665 
       
   666 // -----------------------------------------------------------------------------
       
   667 // CHWRMServer::InitPower
       
   668 // Initialises power
       
   669 // -----------------------------------------------------------------------------
       
   670 //  
       
   671 void CHWRMServer::InitPower()
       
   672 	{
       
   673 	if ( !iPowerInitAttempted )
       
   674         {
       
   675         iPowerInitAttempted = ETrue;  
       
   676         TInt err;
       
   677 	
       
   678         TRAP(err, iPowerPluginHandler = CHWRMPluginHandler::NewL( KHWRMPowerApiEComMatch, iPluginTimeout));        
       
   679 		if ( err != KErrNone )
       
   680 		    {
       
   681 		    // Power not supported by the device, set handler to null
       
   682             COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::InitPower() - Power not supported, error: %d" ), err );
       
   683             iPowerPluginHandler = NULL;		    
       
   684 		    }
       
   685 		else
       
   686 		    {
       
   687 		    TRAP(err, iPowerCommonData = CHWRMPowerCommonData::NewL(iPowerPluginHandler));
       
   688 
       
   689 		    if ( err != KErrNone )
       
   690 	            {
       
   691 	            // Power not supported by the device, set common data to null
       
   692 	            COMPONENT_TRACE2(_L( "HWRM Server - CHWRMServer::InitPower() - CHWRMPowerCommonData creation error: %d" ), err );
       
   693 			    iPowerCommonData = NULL;
       
   694 	            }		        
       
   695 		    }
       
   696         }
       
   697 	}
       
   698 
       
   699 
       
   700 // -----------------------------------------------------------------------------
       
   701 // CHWRMServer::InitFmTxL
       
   702 // Initialises FM Tx
       
   703 // -----------------------------------------------------------------------------
       
   704 //  
       
   705 void CHWRMServer::InitFmTxL()
       
   706     {
       
   707 	COMPONENT_TRACE1( _L( "HWRM Server - CHWRMServer::InitFmTxL()" ) );
       
   708     	
       
   709     if ( !iFmTxInitAttempted )
       
   710         {
       
   711 		COMPONENT_TRACE1( _L( "HWRM Server - CHWRMServer::InitFmTxL() first attempt" ) );
       
   712         	
       
   713         iFmTxInitAttempted = ETrue;    
       
   714 
       
   715        
       
   716         //The feature UID NFeature::KFmTx is defined in featureuids.h
       
   717         TBool fmTxSupported = HWRMFeatureMgr::IsFeatureSupported(NFeature::KFmTx);
       
   718       
       
   719         if ( fmTxSupported )
       
   720             {
       
   721 			COMPONENT_TRACE1( _L( "HWRM Server - CHWRMServer::InitFmTxL() - FM Tx supported in the device" ) );
       
   722             	
       
   723             delete iFmTxPluginHandler;
       
   724             iFmTxPluginHandler = NULL;
       
   725             iFmTxPluginHandler = CHWRMPluginHandler::NewL( KHWRMFmTxApiEComMatch, iPluginTimeout );
       
   726             
       
   727             delete iFmTxWatcherPluginHandler;
       
   728             iFmTxWatcherPluginHandler = NULL;
       
   729             iFmTxWatcherPluginHandler = CHWRMPluginHandler::NewL( KHWRMFmTxWatcherApiEComMatch,
       
   730                                                                   iPluginTimeout );
       
   731 
       
   732             delete iFmTxReservationHandler;
       
   733             iFmTxReservationHandler = NULL;
       
   734 			iFmTxReservationHandler = CHWRMReservationHandler::NewL( KHWRMFmTxSubResourceCount, KFmTxPolicyFilename );
       
   735 			
       
   736             delete iFmTxCommonData;
       
   737             iFmTxCommonData = NULL;
       
   738 			iFmTxCommonData = CHWRMFmTxCommonData::NewL();		
       
   739 			
       
   740 			iFmTxPluginHandler->RegisterForIndications(iFmTxCommonData);
       
   741 			
       
   742 			iFmTxStateUtility = CHWRMFmTxStateUtility::NewL(iFmTxPluginHandler, 
       
   743 			         iFmTxWatcherPluginHandler, iFmTxReservationHandler, iFmTxCommonData);
       
   744 
       
   745 			iFmTxWatcherPluginHandler->RegisterForIndications(iFmTxStateUtility);
       
   746             }
       
   747         else
       
   748             {
       
   749             COMPONENT_TRACE1( _L( "HWRM Server - CHWRMServer::InitFmTx() - FM Tx not supported in the device." ) );
       
   750             }
       
   751         }
       
   752     }    
       
   753 
       
   754 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   755 // None
       
   756 
       
   757 //  End of File