resourcemgmt/hwresourcesmgr/server/src/HWRMLightCommonData.cpp
changeset 0 4e1aa6a622a0
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 "HWRMtrace.h"
       
    21 #include "HWRMLightDomainCRKeys.h"
       
    22 #include "HWRMLightCommonData.h"
       
    23 #include "HWRMClientServer.h"
       
    24 #include "HWRMPrivatePSKeys.h"
       
    25 #include "HWRMConfiguration.h"
       
    26 #include "HWRMLightClientServer.h"
       
    27 #include "HWRMLightService.h"
       
    28 #include "HWRMLightCommands.h"
       
    29 #include "HWRMFeatureMgr.h"
       
    30 #include <featureuids.h>
       
    31 
       
    32 
       
    33 #include "HWRMTargetModifierPlugin.h"
       
    34 
       
    35 // EXTERNAL DATA STRUCTURES
       
    36 // None
       
    37 
       
    38 // EXTERNAL FUNCTION PROTOTYPES  
       
    39 // None
       
    40 
       
    41 // CONSTANTS
       
    42 /**
       
    43 * Minimum allowed sensor sensitivity setting for Light
       
    44 */
       
    45 const TInt KHWRMLightMinSensitivity(1);
       
    46 
       
    47 /**
       
    48 * Maximum allowed sensor sensitivity setting for Light
       
    49 */
       
    50 const TInt KHWRMLightMaxSensitivity(100);
       
    51 
       
    52 /**
       
    53 * Maximum inactivity time for lights on in seconds
       
    54 */
       
    55 const TInt KHWRMLightMaxInactivity(60);
       
    56 
       
    57 /**
       
    58 * Minimum inactivity time for lights on in seconds
       
    59 */
       
    60 const TInt KHWRMLightMinInactivity(5);
       
    61 
       
    62 /**
       
    63 * Default inactivity time for lights on in seconds.
       
    64 * Used if observer cannot be set up.
       
    65 */
       
    66 const TInt KHWRMLightDefaultInactivity(15);
       
    67 
       
    68 // MACROS
       
    69 // None
       
    70 
       
    71 // LOCAL CONSTANTS AND MACROS
       
    72 // None
       
    73 
       
    74 // MODULE DATA STRUCTURES
       
    75 // None
       
    76 
       
    77 // LOCAL FUNCTION PROTOTYPES
       
    78 // None
       
    79 
       
    80 // FORWARD DECLARATIONS
       
    81 // None
       
    82 
       
    83 // ============================= LOCAL FUNCTIONS ===============================
       
    84 
       
    85 // ============================ MEMBER FUNCTIONS ===============================
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CHWRMLightCommonData::CHWRMLightCommonData
       
    89 // C++ constructor
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CHWRMLightCommonData::CHWRMLightCommonData()
       
    93     {
       
    94     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMLightCommonData::CHWRMLightCommonData()" ) );
       
    95     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMLightCommonData::CHWRMLightCommonData - return" ) );
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CHWRMLightCommonData::ConstructL
       
   100 // Symbian 2nd phase constructor can leave.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CHWRMLightCommonData::ConstructL(CHWRMPluginHandler* aPluginHandler,
       
   104                                       CHWRMReservationHandler* aReservationHandler)
       
   105     {    
       
   106     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMLightCommonData::ConstructL()" ) );
       
   107     
       
   108     //The feature UID NFeature::KAmbientLightSensor is defined in featureuids.h
       
   109     iSensorSupported = HWRMFeatureMgr::IsFeatureSupported( NFeature::KAmbientLightSensor );
       
   110     // Load target modifier plugin, if such a thing exists.
       
   111     // Plugin is not mandatory for HWRM functionality,
       
   112     // but the light control logic will be broken if the plugin is dropped from the image.
       
   113     TRAPD( err, iTargetModifier = CHWRMTargetModifierPlugin::NewL( KHWRMLightApiEComMatch ) );
       
   114     if ( err != KErrNone )
       
   115         {
       
   116         COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::ConstructL - Target modifier plugin not loaded; cause: %d" ), err );
       
   117         }  
       
   118     
       
   119     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::ConstructL - Sensor support: 0x%x" ), iSensorSupported );
       
   120       
       
   121     ResetCenrepL();
       
   122     
       
   123     // Initialize full system target. Ensure that only supported targets are included.
       
   124     if ( iTargetModifier )
       
   125         {        
       
   126         iFullSystemTarget = iTargetModifier->GetFullSystemTarget() & iSupportedTargets;
       
   127         COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::ConstructL - Full System Target: 0x%x" ), iFullSystemTarget );
       
   128         }
       
   129         
       
   130     // Set up status P&S values
       
   131     User::LeaveIfError(RProperty::Define(KPSUidHWResourceNotification, KHWRMLightStatus, RProperty::EByteArray, KNoCapability, KHWRMSidOnlyPolicy));
       
   132     User::LeaveIfError(iLightStatusProperty.Attach(KPSUidHWResourceNotification, KHWRMLightStatus));
       
   133     
       
   134     TInt currentTarget( KHWRMLightFirstTarget );
       
   135     
       
   136     for( TInt i = 0; i < KHWRMLightMaxTargets; i++ )
       
   137         {
       
   138         THWRMStatusInfo info;
       
   139         info.iTarget = currentTarget;
       
   140         info.iStatus = CHWRMExtendedLight::ELightStatusUnknown;
       
   141         iStatusList.AppendL( info );
       
   142         // shift the mask and target ready for next loop
       
   143         currentTarget <<= 1;
       
   144         }
       
   145         
       
   146     TInt arraySize = ( sizeof( THWRMStatusInfo ) ) * KHWRMLightMaxTargets;
       
   147     TPtr8 arrayPtr( ( TUint8* )&iStatusList[0], arraySize, arraySize );
       
   148       
       
   149     User::LeaveIfError( iLightStatusProperty.Set( arrayPtr ) );
       
   150     
       
   151     // Construct light service last so that the common data is in order to be used
       
   152     // in service construction.
       
   153     iLightService = CHWRMLightService::NewL(aPluginHandler, aReservationHandler, *this);
       
   154     
       
   155     // Reset intensity and sensitivity to update values to plugin, 
       
   156     // as lightservice is not yet available when ResetCenrepL was called earlier.
       
   157     SetDefaultIntensity(iDefaultIntensity, ETrue);
       
   158 
       
   159     if ( iSensorSupported )
       
   160         {
       
   161         SetDefaultSensitivity(iDefaultSensitivity, ETrue);	
       
   162         }
       
   163 
       
   164     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMLightCommonData::ConstructL - return " ) );
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CHWRMLightCommonData::NewL
       
   169 // Two-phased constructor.
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 CHWRMLightCommonData* CHWRMLightCommonData::NewL(CHWRMPluginHandler* aPluginHandler,
       
   173                                                  CHWRMReservationHandler* aReservationHandler)
       
   174     {
       
   175     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMLightCommonData::NewL()" ) );
       
   176 
       
   177     CHWRMLightCommonData* self = new( ELeave ) CHWRMLightCommonData();
       
   178     
       
   179     CleanupStack::PushL( self );
       
   180     self->ConstructL(aPluginHandler, aReservationHandler);
       
   181     CleanupStack::Pop();
       
   182 
       
   183     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::NewL - return 0x%x" ), self );
       
   184     
       
   185     return self;
       
   186     }
       
   187    
       
   188 // ---------------------------------------------------------
       
   189 // Destructor
       
   190 // ---------------------------------------------------------
       
   191 //
       
   192 CHWRMLightCommonData::~CHWRMLightCommonData()
       
   193     {
       
   194     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMLightCommonData::~CHWRMLightCommonData()" ) );
       
   195 
       
   196     delete iLightService;
       
   197     iLightService = NULL;
       
   198     
       
   199     // Destroy target modifier plugin
       
   200     delete iTargetModifier;
       
   201     iTargetModifier = NULL;
       
   202     
       
   203     // Clean up central repository related data
       
   204     CleanCenrep();
       
   205 
       
   206     iLightStatusProperty.Close();
       
   207 
       
   208     // NULL these references so that pc-lint will not complain. 
       
   209     // They are cleaned in CleanCenrep();
       
   210     iIntensityNotifyHandler = NULL;
       
   211     iSensitivityNotifyHandler = NULL;
       
   212     iSensorNotifyHandler = NULL;
       
   213     iRepository = NULL;     
       
   214     iLightsTimeoutObserver = NULL;   
       
   215 
       
   216     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMLightCommonData::~CHWRMLightCommonData - return" ) );
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CHWRMLightCommonData::PublishLightStatus
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 void CHWRMLightCommonData::PublishLightStatus(TInt aTarget, CHWRMLight::TLightStatus aStatus)
       
   224     {
       
   225     COMPONENT_TRACE3(_L("HWRM Server - CHWRMLightCommonData::PublishLightStatus(0x%x, 0x%x)"), aTarget, aStatus); 
       
   226 
       
   227     // Publish Light status to P&S. If publishing fails, something is very wrong
       
   228     // with P&S, so ignore it. If it is memory issue, hopefully it will work 
       
   229     // next time. If it is not, we can't do anything about it anyway.
       
   230 
       
   231     TInt err(KErrNone);
       
   232     
       
   233     // Loop through target and update correct indexes of iStatusList
       
   234     TInt currentTarget(KHWRMLightFirstTarget);
       
   235     TInt currentStatus = aStatus;
       
   236             
       
   237     for ( int i = 0; i < KHWRMLightMaxTargets; i++ )
       
   238         {
       
   239         if ( aTarget & currentTarget )
       
   240             {
       
   241             THWRMStatusInfo info;
       
   242             info.iTarget = currentTarget;
       
   243             info.iStatus = currentStatus;
       
   244             const TInt& target( info.iTarget );
       
   245             TInt j = iStatusList.FindInOrder( target, FindByTarget ); 
       
   246             
       
   247             if ( j >= 0 && j < KHWRMLightMaxTargets )
       
   248                 {
       
   249                 iStatusList[j].iStatus = currentStatus;   
       
   250             }
       
   251             }    
       
   252         // shift the mask and target ready for next loop
       
   253         currentTarget <<= 1;
       
   254         }
       
   255     
       
   256     COMPONENT_TRACE1( (_L("HWRM Server - CHWRMLightCommonData::PublishLightStatus - Setting light status property.") ) ); 
       
   257     
       
   258     TInt arraySize = ( sizeof( THWRMStatusInfo ) ) * KHWRMLightMaxTargets;
       
   259     TPtr8 arrayPtr( ( TUint8* )&iStatusList[0], arraySize, arraySize );
       
   260       
       
   261     err = iLightStatusProperty.Set( arrayPtr );
       
   262     
       
   263     if ( err != KErrNone )
       
   264         {
       
   265         COMPONENT_TRACE2(_L("HWRM Server - CHWRMLightCommonData::PublishLightStatus - Property set failed: %d"), err );     
       
   266         }
       
   267     COMPONENT_TRACE1(_L("HWRM Server - CHWRMLightCommonData::PublishLightStatus - return")); 
       
   268     }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // CHWRMLightCommonData::DefaultSensitivity
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 TInt CHWRMLightCommonData::DefaultSensitivity() 
       
   275     {
       
   276     if ( !iRepository )
       
   277         {
       
   278         TRAP_IGNORE(ResetCenrepL());
       
   279         }
       
   280         
       
   281     return iDefaultSensitivity;
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CHWRMLightCommonData::SensorEnabled
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 TBool CHWRMLightCommonData::SensorEnabled() 
       
   289     {
       
   290     TBool retval(EFalse);
       
   291     
       
   292     if ( iSensorSupported )
       
   293         {
       
   294         if ( !iRepository )
       
   295             {
       
   296             TRAP_IGNORE(ResetCenrepL());
       
   297             }
       
   298         
       
   299         retval = iSensorOn;
       
   300         }
       
   301         
       
   302     return retval;
       
   303     }
       
   304     
       
   305 // -----------------------------------------------------------------------------
       
   306 // CHWRMLightCommonData::DefaultState
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 CHWRMLight::TLightStatus CHWRMLightCommonData::DefaultState() const
       
   310     {   
       
   311     CHWRMLight::TLightStatus retval(CHWRMLight::ELightOn);
       
   312     
       
   313     if ( (User::InactivityTime()).Int() >= iInactivityLimit )
       
   314         {
       
   315         retval = CHWRMLight::ELightOff;
       
   316         }
       
   317         
       
   318     COMPONENT_TRACE4(_L("HWRM Server - CHWRMLightCommonData::DefaultState - Inactivitity time: %d, Limit: %d, State: %d"), (User::InactivityTime()).Int(), iInactivityLimit, retval);                 
       
   319         
       
   320     return retval;
       
   321     }
       
   322     
       
   323     
       
   324 // -----------------------------------------------------------------------------
       
   325 // CHWRMLightCommonData::HandleNotifyInt
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 void CHWRMLightCommonData::HandleNotifyInt(TUint32 aId, TInt aNewValue)
       
   329     {
       
   330     COMPONENT_TRACE3(_L("HWRM Server - CHWRMLightCommonData::HandleNotifyInt(0x%x, 0x%x)"), aId, aNewValue) ; 
       
   331 
       
   332     switch(aId)
       
   333         {
       
   334         case KLightIntensity:
       
   335             {
       
   336             SetDefaultIntensity(aNewValue);
       
   337             break;
       
   338             }
       
   339         case KLightSensorSensitivity:
       
   340             {
       
   341             SetDefaultSensitivity(aNewValue);
       
   342             break;
       
   343             }
       
   344         case KLightSensorInUse:
       
   345             {
       
   346             iSensorOn = (aNewValue != 0);
       
   347             COMPONENT_TRACE2(_L("HWRM Server - CHWRMLightCommonData::HandleNotifyInt - Sensor set: %d"), iSensorOn); 
       
   348             
       
   349             // Set lights on unless sensor is not supported or inactivity time passed
       
   350             if ( iLightService && 
       
   351                  iSensorSupported &&
       
   352                  DefaultState() == CHWRMLight::ELightOn )
       
   353                 {        
       
   354                 iLightService->SystemLightsOn();
       
   355                 }
       
   356             
       
   357             break;
       
   358             }
       
   359         default:
       
   360             {
       
   361             // Do nothing, as key does not concern us. 
       
   362             COMPONENT_TRACE2(_L("HWRM Server - CHWRMLightCommonData::HandleNotifyInt - Invalid key notified: 0x%x"), aId ); 
       
   363             break;
       
   364             }
       
   365         }
       
   366 
       
   367     COMPONENT_TRACE1(_L("HWRM Server - CHWRMLightCommonData::HandleNotifyInt - return") ); 
       
   368     }
       
   369 
       
   370 // -----------------------------------------------------------------------------
       
   371 // CHWRMLightCommonData::HandleNotifyError
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 #if  defined(COMPONENT_TRACE_FLAG) && defined(_DEBUG)
       
   375 void CHWRMLightCommonData::HandleNotifyError(TUint32 aId, TInt error, CCenRepListener* aHandler)
       
   376 #else
       
   377 void CHWRMLightCommonData::HandleNotifyError(TUint32 /*aId*/, TInt /*error*/, CCenRepListener* /*aHandler*/)
       
   378 #endif
       
   379     {
       
   380     COMPONENT_TRACE4(_L("HWRM Server - CHWRMLightCommonData::HandleNotifyError(0x%x, 0x%x, 0x%x)"), aId, error, aHandler); 
       
   381     
       
   382     // Try to restart cenrep related functionality. If it fails, clean up and try to restart when values are asked next.
       
   383     TRAPD(err, ResetCenrepL());
       
   384     
       
   385     if (err != KErrNone)
       
   386         {
       
   387         CleanCenrep();
       
   388         COMPONENT_TRACE2(_L("HWRM Server - CHWRMLightCommonData::HandleNotifyError - Cenrep reset failed: %d"), err );
       
   389         }
       
   390 
       
   391     COMPONENT_TRACE1(_L("HWRM Server - CHWRMLightCommonData::HandleNotifyError - return") ); 
       
   392     }
       
   393 
       
   394 // -----------------------------------------------------------------------------
       
   395 // CHWRMLightCommonData::SetDefaultIntensity
       
   396 // -----------------------------------------------------------------------------
       
   397 //
       
   398 void CHWRMLightCommonData::SetDefaultIntensity(TInt aValue, TBool aConstructCall)
       
   399     {
       
   400     iDefaultIntensity = aValue;
       
   401     
       
   402     if ( iDefaultIntensity < KHWRMLightMinIntensity )
       
   403         {
       
   404         iDefaultIntensity = KHWRMLightMinIntensity;
       
   405         }
       
   406     else if ( iDefaultIntensity > KHWRMLightMaxIntensity)
       
   407         {
       
   408         iDefaultIntensity = KHWRMLightMaxIntensity;
       
   409         }
       
   410     else
       
   411         {
       
   412         // no else
       
   413         }
       
   414         
       
   415     // Update value to plugin, if iLightService is initialized
       
   416     if ( iLightService )
       
   417         {        
       
   418         TInt target(iSupportedTargets);
       
   419         
       
   420         if(aConstructCall)
       
   421          {
       
   422              target = iFullSystemTarget; //During bootup, intensity of system targets supported in the platform are changed.
       
   423          }
       
   424                 
       
   425          TRAPD( err, iLightService->UpdateDefaultIntensityL(target, iDefaultIntensity) );
       
   426         
       
   427         if ( err != KErrNone )
       
   428             {
       
   429             COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::SetDefaultIntensity - Error updating plugin: %d" ), err );
       
   430             }
       
   431         else
       
   432             {
       
   433             // Intensity change successful. 
       
   434             // Set lights on unless sensor control is enabled or inactivity time passed or this is called from constructor
       
   435             if ( !aConstructCall &&
       
   436                  !(iSensorSupported && iSensorOn) && 
       
   437                  DefaultState() == CHWRMLight::ELightOn )
       
   438                 {
       
   439                 iLightService->SystemLightsOn();
       
   440                 }
       
   441             }
       
   442         }
       
   443         
       
   444         
       
   445     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::SetDefaultIntensity: %d" ), iDefaultIntensity );
       
   446     }
       
   447         
       
   448 // -----------------------------------------------------------------------------
       
   449 // CHWRMLightCommonData::SetDefaultSensitivity
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 void CHWRMLightCommonData::SetDefaultSensitivity(TInt aValue, TBool aConstructCall)
       
   453     {
       
   454     iDefaultSensitivity = aValue;
       
   455     
       
   456     if ( iDefaultSensitivity < KHWRMLightMinSensitivity )
       
   457         {
       
   458         iDefaultSensitivity = KHWRMLightMinSensitivity;
       
   459         }
       
   460     else if ( iDefaultSensitivity > KHWRMLightMaxSensitivity)
       
   461         {
       
   462         iDefaultSensitivity = KHWRMLightMaxSensitivity;
       
   463         }
       
   464     else
       
   465         {
       
   466         // no else
       
   467         }
       
   468         
       
   469     // Update value to plugin, if iLightService is initialized
       
   470     if ( iLightService && iSensorSupported)
       
   471         {        
       
   472         TRAPD( err, iLightService->UpdateDefaultSensitivityL(iDefaultSensitivity) );
       
   473         
       
   474         if ( err != KErrNone )
       
   475             {
       
   476             COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::SetDefaultSensitivity - Error updating plugin: %d" ), err );
       
   477             }
       
   478         else
       
   479             {
       
   480             // Sensitivity change successful.
       
   481             // Set lights on unless sensor control is not enabled or inactivity time passed or this is called from constructor
       
   482             if ( !aConstructCall &&
       
   483                  iSensorOn && 
       
   484                  DefaultState() == CHWRMLight::ELightOn )
       
   485                 {
       
   486                 iLightService->SystemLightsOn();
       
   487                 }
       
   488             }
       
   489         }
       
   490         
       
   491     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::SetDefaultSensitivity: %d" ), iDefaultSensitivity );
       
   492     }
       
   493     
       
   494 
       
   495 // -----------------------------------------------------------------------------
       
   496 // CHWRMLightCommonData::LightsTimeoutChange
       
   497 // -----------------------------------------------------------------------------
       
   498 //
       
   499 void CHWRMLightCommonData::LightsTimeoutChange(TInt aTimeout)
       
   500     {
       
   501     if ( aTimeout < KHWRMLightMinInactivity )
       
   502         {
       
   503         iInactivityLimit = KHWRMLightMinInactivity;
       
   504         }
       
   505     else if ( aTimeout > KHWRMLightMaxInactivity )
       
   506         {
       
   507         iInactivityLimit = KHWRMLightMaxInactivity;
       
   508         }
       
   509     else
       
   510         {
       
   511         iInactivityLimit = aTimeout;
       
   512         }
       
   513 
       
   514     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::LightsTimeoutChange: %d" ), iInactivityLimit );
       
   515     }
       
   516 
       
   517 // -----------------------------------------------------------------------------
       
   518 // CHWRMLightCommonData::CleanCenrep
       
   519 // Cleans the central repository related functionality. 
       
   520 // -----------------------------------------------------------------------------
       
   521 //
       
   522 void CHWRMLightCommonData::CleanCenrep()
       
   523     {
       
   524     COMPONENT_TRACE1(_L("HWRM Server - CHWRMLightCommonData::CleanCenrep()") ); 
       
   525 
       
   526     if ( iIntensityNotifyHandler )
       
   527         {
       
   528         iIntensityNotifyHandler->StopListening();        
       
   529         }
       
   530     if ( iSensitivityNotifyHandler )
       
   531         {
       
   532         iSensitivityNotifyHandler->StopListening();        
       
   533         }
       
   534     if ( iSensorNotifyHandler )
       
   535         {
       
   536         iSensorNotifyHandler->StopListening();        
       
   537         }
       
   538     
       
   539     delete iIntensityNotifyHandler;
       
   540     delete iSensitivityNotifyHandler;
       
   541     delete iSensorNotifyHandler;
       
   542     delete iRepository;   
       
   543     delete iLightsTimeoutObserver; 
       
   544     
       
   545     iIntensityNotifyHandler = NULL;
       
   546     iSensitivityNotifyHandler = NULL;
       
   547     iSensorNotifyHandler = NULL;
       
   548     iRepository = NULL;        
       
   549     iLightsTimeoutObserver = NULL;
       
   550 
       
   551     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMLightCommonData::CleanCenrep - return" ) );
       
   552     }
       
   553     
       
   554 // -----------------------------------------------------------------------------
       
   555 // CHWRMLightCommonData::ResetCenrepL
       
   556 // (Re)starts the central repository related functionality. 
       
   557 // -----------------------------------------------------------------------------
       
   558 //
       
   559 void CHWRMLightCommonData::ResetCenrepL()
       
   560     {
       
   561     COMPONENT_TRACE1(_L("HWRM Server - CHWRMLightCommonData::ResetCenrep()") ); 
       
   562 
       
   563     CleanCenrep();
       
   564 
       
   565     // Get read only values from cenrep
       
   566     iRepository = CRepository::NewL(KCRUidLightSettings);
       
   567 
       
   568     TInt value(0);
       
   569     User::LeaveIfError(iRepository->Get(KLightIntensity, value));
       
   570     SetDefaultIntensity(value);
       
   571     
       
   572     User::LeaveIfError(iRepository->Get(KLightTargetMask, iSupportedTargets));        
       
   573     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::ConstructL - iSupportedTargets: 0x%x" ), iSupportedTargets );
       
   574     
       
   575     // All target combinations up to all targets defined are legal, so snip the rest off
       
   576     iSupportedTargets &= KHWRMAllTargets;       
       
   577     
       
   578     if ( iSensorSupported )
       
   579         {        
       
   580         User::LeaveIfError(iRepository->Get(KLightSensorSensitivity, value));
       
   581         SetDefaultSensitivity(value);
       
   582 
       
   583         User::LeaveIfError(iRepository->Get(KLightSensorInUse, value));
       
   584         iSensorOn = (value != 0);
       
   585         COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::ConstructL - iSensorOn: %d" ), iSensorOn );
       
   586         
       
   587         TInt err = iRepository->Get(KLightSensorMask, iSensorTargets);
       
   588         
       
   589         if ( err == KErrNone )
       
   590             {
       
   591             // Sensor targets can only contain supported targets.
       
   592             iSensorTargets &= iSupportedTargets; 
       
   593             COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::ConstructL - iSensorTargets: 0x%x" ), iSensorTargets );
       
   594             }
       
   595         else
       
   596             {
       
   597             iSensorTargets = iSupportedTargets;
       
   598             COMPONENT_TRACE2(_L( "HWRM Server - CHWRMLightCommonData::ConstructL - Error getting sensor targets: %d, assuming all targets are sensor targets" ), err );
       
   599             }
       
   600         }
       
   601         
       
   602     // Set up cenrep notify handlers for each key 
       
   603     // (separate handlers to ensure that notifications correctly also in repository resets)
       
   604     iIntensityNotifyHandler = CCenRepListener::NewL(*this, 
       
   605                                                 *iRepository, 
       
   606                                                 KLightIntensity);
       
   607     iIntensityNotifyHandler->StartListeningL();
       
   608 
       
   609     if ( iSensorSupported )
       
   610         {        
       
   611         iSensitivityNotifyHandler = CCenRepListener::NewL(*this, 
       
   612                                                     *iRepository, 
       
   613                                                     KLightSensorSensitivity);
       
   614         iSensorNotifyHandler = CCenRepListener::NewL(*this, 
       
   615                                                     *iRepository, 
       
   616                                                     KLightSensorInUse);
       
   617         iSensitivityNotifyHandler->StartListeningL();
       
   618         iSensorNotifyHandler->StartListeningL();
       
   619         }
       
   620 
       
   621 
       
   622     TRAPD( err, iLightsTimeoutObserver = CHWRMLightsTimeoutObserver::NewL(this));
       
   623     
       
   624     if ( err != KErrNone )
       
   625         {
       
   626         // Use default value if timeout observer cannot be created
       
   627         iInactivityLimit = KHWRMLightDefaultInactivity;
       
   628         COMPONENT_TRACE2(_L("HWRM Server - CHWRMLightCommonData::ResetCenrep - Using default lights timeout value: %d "),iInactivityLimit ); 
       
   629         }
       
   630     
       
   631     COMPONENT_TRACE1(_L("HWRM Server - CHWRMLightCommonData::ResetCenrep - return") ); 
       
   632     }
       
   633     
       
   634 // -----------------------------------------------------------------------------
       
   635 // CHWRMLightCommonData::ModifyTargetL
       
   636 // Passes the call to target modifier plugin
       
   637 // -----------------------------------------------------------------------------
       
   638 //
       
   639 TInt CHWRMLightCommonData::ModifyTargetL(TInt aTarget)
       
   640     {
       
   641     // If target modifier plugin doesn't exist, just return the target
       
   642     if ( iTargetModifier )
       
   643         {
       
   644         return iTargetModifier->ModifyTargetL( aTarget);
       
   645         }
       
   646     else
       
   647         {
       
   648         COMPONENT_TRACE1(_L("HWRM Server - CHWRMLightCommonData::ModifyTargetL - Target modifier plugin NULL, no modification") ); 
       
   649         return aTarget;
       
   650         }
       
   651     }
       
   652     
       
   653 // -----------------------------------------------------------------------------
       
   654 // CHWRMLightCommonData::FindByTarget
       
   655 // Finds item from iStatusList by target.
       
   656 // -----------------------------------------------------------------------------
       
   657 //
       
   658 TInt CHWRMLightCommonData::FindByTarget( const TInt* aTarget, 
       
   659     const THWRMStatusInfo& aItem )
       
   660     {
       
   661     if ( *aTarget < aItem.iTarget )
       
   662         {
       
   663         return -1;
       
   664         }
       
   665     else if ( *aTarget > aItem.iTarget )
       
   666         {
       
   667         return 1;
       
   668         }
       
   669 
       
   670     return 0;
       
   671     }
       
   672 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   673 
       
   674 //  End of File