resourcemgmt/hwresourcesmgr/power/src/HWRMPowerImpl.cpp
changeset 0 4e1aa6a622a0
child 70 653a8b91b95e
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2008-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 // INCLUDE FILES
       
    17 #include <e32svr.h>
       
    18 #include "HWRMBatteryPowerMeasurementsAO.h"
       
    19 #include "HWRMPowerClientServer.h"
       
    20 #include "HWRMtrace.h"
       
    21 #include "HWRMClient.h"
       
    22 #include "HWRMPowerImpl.h"
       
    23 
       
    24 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
    25 
       
    26 #include "HWRMBatteryChargeCurrentRateAO.h"
       
    27 #include "HWRMBatteryChargeTimeMeasurementsAO.h"
       
    28 #include "HWRMChargingStatusObserver.h"
       
    29 
       
    30 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
    31 
       
    32 // EXTERNAL DATA STRUCTURES
       
    33 
       
    34 // EXTERNAL FUNCTION PROTOTYPES  
       
    35 
       
    36 // CONSTANTS
       
    37 
       
    38 // MACROS
       
    39 
       
    40 // LOCAL CONSTANTS AND MACROS
       
    41 
       
    42 // MODULE DATA STRUCTURES
       
    43 
       
    44 // LOCAL FUNCTION PROTOTYPES
       
    45 
       
    46 // FORWARD DECLARATIONS
       
    47 
       
    48 // ============================= LOCAL FUNCTIONS ===============================
       
    49 
       
    50 // ============================ MEMBER FUNCTIONS ===============================
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CHWRMPowerImpl::NewL
       
    54 // Two-phased constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CHWRMPowerImpl* CHWRMPowerImpl::NewL()
       
    58 	{
       
    59     COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::NewL()"));
       
    60     
       
    61     CHWRMPowerImpl* powerImpl = new( ELeave ) CHWRMPowerImpl();
       
    62     
       
    63     CleanupStack::PushL( powerImpl );        
       
    64     powerImpl->ConstructL();        
       
    65     CleanupStack::Pop(); 
       
    66     
       
    67     COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::NewL - return" ));
       
    68     
       
    69     return powerImpl;
       
    70 	}
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CHWRMPowerImpl::CHWRMPowerImpl
       
    74 // C++ constructor
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CHWRMPowerImpl::CHWRMPowerImpl()
       
    78 	:iBatteryConsumptionDataPckg(NULL, 0, 0),
       
    79 	iBatteryVoltageDataPckg(NULL, 0, 0),
       
    80 	iPowerIntervalMultiplePckg(NULL,0,0)	
       
    81 	
       
    82 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
    83 	,iBatteryChargerTypePckg(NULL, 0, 0),
       
    84 	iChargingStatusImpl(NULL),
       
    85 	iCurrentRateIntervalMultiplePckg(NULL,0,0)
       
    86 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
    87 	{	
       
    88     COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::CHWRMPowerImpl()"));
       
    89     COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::CHWRMPowerImpl - return" ));
       
    90 	}
       
    91 
       
    92 // ---------------------------------------------------------
       
    93 // Destructor
       
    94 // ---------------------------------------------------------
       
    95 //
       
    96 CHWRMPowerImpl::~CHWRMPowerImpl()
       
    97 	{
       
    98 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::~CHWRMPowerImpl()" ));
       
    99 	
       
   100 	Close();	
       
   101 	
       
   102     
       
   103 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   104     
       
   105     iBatteryChargeCurrentRateAO = NULL;
       
   106     iBatteryChargingTimeAO = NULL;
       
   107     
       
   108 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   109     
       
   110 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::~CHWRMPowerImpl - return" ));
       
   111 	}
       
   112 // -----------------------------------------------------------------------------
       
   113 // CHWRMPowerImpl::ConstructL
       
   114 // Symbian 2nd phase constructor can leave.
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CHWRMPowerImpl::ConstructL()
       
   118 	{
       
   119 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::ConstructL()" ));
       
   120 	
       
   121 	OpenL();
       
   122 	
       
   123 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::ConstructL - return" ) );    
       
   124 	}
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CHWRMPowerImpl::OpenL
       
   128 // Opens session
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CHWRMPowerImpl::OpenL()
       
   132     {
       
   133     COMPONENT_TRACE1( _L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::Open()" ));
       
   134         
       
   135     User::LeaveIfError(iClient.Connect(HWRMResourceTypePower));
       
   136     
       
   137     COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::Open - Craeting Active objects for measurements reporting" ));
       
   138     
       
   139 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   140 
       
   141     //Create observer here, so that charging current/time notification can be stopped,
       
   142     //if charger is disconnected.
       
   143     
       
   144     iChargingStatusImpl = CHWRMChargingStatusObs::NewL(this);
       
   145 
       
   146 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   147     	
       
   148     COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::Open - return" ));
       
   149     
       
   150     }
       
   151 // -----------------------------------------------------------------------------
       
   152 // CHWRMPowerImpl::Close
       
   153 // Closes session.
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CHWRMPowerImpl::Close()
       
   157 	{
       
   158 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::Close()" ));
       
   159             
       
   160     if ( iBatteryPowerMeasurementsAO)
       
   161 		{
       
   162 		COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::Close - canceling BatteryPowerMeasurements notifications" ));
       
   163 		delete iBatteryPowerMeasurementsAO;
       
   164 		iBatteryPowerMeasurementsAO = NULL;
       
   165 		}
       
   166 
       
   167 
       
   168 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   169         
       
   170         delete iChargingStatusImpl;
       
   171         iChargingStatusImpl = NULL;
       
   172         COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::Close Deleted iChargingStatusImpl" ));        
       
   173 
       
   174         delete iBatteryChargeCurrentRateAO;
       
   175         iBatteryChargeCurrentRateAO = NULL;
       
   176 
       
   177         delete iBatteryChargingTimeAO;
       
   178         iBatteryChargingTimeAO = NULL;
       
   179 
       
   180 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   181 
       
   182 	// Inform session that we are cleaning up now.
       
   183 	// Ignore errors, just trace them
       
   184 	if (iClient.Handle())
       
   185 		{
       
   186 		iClient.ExecuteOperation(EHWRMCleanupBattery, TIpcArgs());
       
   187         }
       
   188 
       
   189     iClient.Close();
       
   190       
       
   191     COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::Close - return" ) );
       
   192     }    
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CHWRMPowerImpl::DoGetBatteryInfo
       
   196 // 
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CHWRMPowerImpl::DoGetBatteryInfo(TRequestStatus& aStatus, CHWRMPower::TBatteryConsumptionData& aBatteryConsumptionData )
       
   200 	{
       
   201 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoGetBatteryInfo()" ));
       
   202 
       
   203 	iBatteryConsumptionDataPckg.Set( TPckg<CHWRMPower::TBatteryConsumptionData> (aBatteryConsumptionData) );
       
   204 	
       
   205 	iClient.ExecuteAsyncOperation(EHWRMGetBatteryInfo, TIpcArgs(&iBatteryConsumptionDataPckg), aStatus);
       
   206 
       
   207 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoGetBatteryInfo - return" ));
       
   208 	}
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CHWRMPowerImpl::DoGetVoltageInfo
       
   212 // 
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CHWRMPowerImpl::DoGetBatteryVoltageInfo(TRequestStatus& aStatus, CHWRMPower::TBatteryVoltageData& aBatteryVoltageData)
       
   216 	{
       
   217 	COMPONENT_TRACE1(_L( "HWRM PowerClient - CHWRMPowerImpl::DoGetBatteryVoltageInfo()" ));
       
   218 	
       
   219 	iBatteryConsumptionDataPckg.Set( TPckg<CHWRMPower::TBatteryVoltageData> (aBatteryVoltageData) );
       
   220 	
       
   221 	iClient.ExecuteAsyncOperation(EHWRMGetBatteryVoltageInfo, TIpcArgs(&iBatteryConsumptionDataPckg), aStatus);
       
   222 	
       
   223 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoGetBatteryVoltageInfo - return" ));
       
   224 	}
       
   225 // -----------------------------------------------------------------------------
       
   226 // CHWRMPowerImpl::DoStartAveragePowerReporting
       
   227 // 
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 TInt CHWRMPowerImpl::DoStartAveragePowerReporting(TRequestStatus& aStatus, const TUint& aInterval)
       
   231 	{	
       
   232 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoStartAveragePowerReporting()" ));
       
   233 	
       
   234 	if (!iBatteryPowerMeasurementsAO)
       
   235 		{
       
   236 		COMPONENT_TRACE2(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoStartAveragePowerReporting - return( - return 0x%x" ), KErrBadHandle );
       
   237 		
       
   238 		return KErrBadHandle;
       
   239 		}
       
   240 	else 
       
   241 		{		
       
   242 		iPowerIntervalMultiplePckg.Set( TPckg<TUint> (aInterval) );
       
   243 		
       
   244 		iClient.ExecuteAsyncOperation(EHWRMStartAverageBatteryPowerReporting, TIpcArgs(&iPowerIntervalMultiplePckg), aStatus);
       
   245 		
       
   246 		//Issue request to retrieve battery power measurements	
       
   247 		if( !iBatteryPowerMeasurementsAO->IsActive())
       
   248 			{
       
   249 			iBatteryPowerMeasurementsAO->GetAsyncBatch( EHWRMGetPowerMeasurements );	
       
   250 			}		
       
   251 		COMPONENT_TRACE2(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoStartAveragePowerReporting - return( - return 0x%x" ), KErrNone );
       
   252 		
       
   253 	    return KErrNone;
       
   254 		}
       
   255 	}
       
   256 
       
   257 void CHWRMPowerImpl::DoStopAveragePowerReportingL()
       
   258 	{	
       
   259 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoStopAveragePowerReportingL()" ));
       
   260 	
       
   261 	if (iBatteryPowerMeasurementsAO)
       
   262 		{
       
   263 		COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::Close - canceling BatteryPowerMeasurements notifications" ));
       
   264 		iBatteryPowerMeasurementsAO->Cancel();		
       
   265 	
       
   266 		User::LeaveIfError(iClient.ExecuteOperation(EHWRMStopAverageBatteryPowerReporting, TIpcArgs()));
       
   267 		}
       
   268 
       
   269 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoStopAveragePowerReportingL - return" ));
       
   270 	}
       
   271 
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CHWRMPowerImpl::DoSetPowerReportObserverL
       
   275 // 
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CHWRMPowerImpl::DoSetPowerReportObserverL(MHWRMBatteryPowerObserver* aPowerReportCallback)
       
   279     {
       
   280     COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoSetPowerReportObserverL()" ));
       
   281 
       
   282 
       
   283     if(aPowerReportCallback)
       
   284         {
       
   285         if(iBatteryPowerMeasurementsAO)
       
   286             {
       
   287             iBatteryPowerMeasurementsAO->SetCallBack(aPowerReportCallback);
       
   288             }
       
   289         else
       
   290             {
       
   291             iBatteryPowerMeasurementsAO = CHWRMBatteryPowerMeasurementsAO::NewL(aPowerReportCallback, iClient);
       
   292             }
       
   293         COMPONENT_TRACE1(_L( "iBatteryPowerMeasurementsAO Created" ));    
       
   294         }
       
   295 
       
   296     COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoSetPowerReportObserverL - return" ));
       
   297     }
       
   298 
       
   299 
       
   300 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CHWRMPowerImpl::DoGetBatteryChargerType
       
   304 // 
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 
       
   308 
       
   309 TInt CHWRMPowerImpl::DoGetBatteryChargerType(CHWRMPower::TBatteryChargerType& aChargerType)
       
   310     {
       
   311 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoGetBatteryChargerType()" ));
       
   312 
       
   313 	iBatteryChargerTypePckg.Set( TPckg<CHWRMPower::TBatteryChargerType> (aChargerType) );
       
   314 	
       
   315 	TInt err = iClient.ExecuteOperation(EHWRMGetBatteryChargerType, TIpcArgs(&iBatteryChargerTypePckg));
       
   316 
       
   317     COMPONENT_TRACE3(_L( "HWRM CHWRMPowerImpl - Charger Type = %d err = %d" ), aChargerType, err);    
       
   318 
       
   319 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoGetBatteryChargerType - return" ));
       
   320 
       
   321     return err;
       
   322 	}
       
   323 
       
   324 TInt CHWRMPowerImpl::DoGetBatteryChargingStatus(CHWRMPower::TBatteryChargingStatus& aChargingStatus)
       
   325     {
       
   326     COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoGetBatteryChargingStatus()" ));
       
   327 
       
   328     TInt val;
       
   329 
       
   330     aChargingStatus = CHWRMPower::EChargingStatusError;
       
   331 
       
   332     TInt err = iChargingStatusImpl->Get(val);
       
   333 
       
   334     if(err == KErrNone)
       
   335         {
       
   336         aChargingStatus = static_cast<CHWRMPower::TBatteryChargingStatus>(val);
       
   337         }
       
   338 
       
   339 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoGetBatteryChargingStatus - return" ));
       
   340 
       
   341     return err;
       
   342     }
       
   343 
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CHWRMPowerImpl::DoSetBatteryChargingObserver
       
   347 // 
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 void CHWRMPowerImpl::DoSetBatteryChargingObserverL(
       
   351              MHWRMBatteryChargingStatusObserver*   aChargingStatusCallback,
       
   352              MHWRMBatteryChargingCurrentObserver*     aChrgCurrentCallback,
       
   353              MHWRMBatteryFullChargingTimeObserver* aChrgTimeCallback)
       
   354     {
       
   355     COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoSetBatteryChargingObserver()" ));
       
   356 
       
   357     if(aChargingStatusCallback)
       
   358         {
       
   359         iChargingStatusClientObserver = aChargingStatusCallback;
       
   360         COMPONENT_TRACE1(_L( "iChargingStatusImpl Created" ));        
       
   361         }
       
   362 
       
   363     if(aChrgCurrentCallback)
       
   364         {
       
   365         if(iBatteryChargeCurrentRateAO)
       
   366             {
       
   367             iBatteryChargeCurrentRateAO->SetCallBack(aChrgCurrentCallback);
       
   368             }
       
   369         else
       
   370             {
       
   371             iBatteryChargeCurrentRateAO = CHWRMBatteryChargeRateCurrentAO::NewL(aChrgCurrentCallback, iClient);
       
   372             }
       
   373         COMPONENT_TRACE1(_L( "iBatteryChargeCurrentRateAO Created" ));    
       
   374         }
       
   375 
       
   376     if(aChrgTimeCallback)
       
   377         {
       
   378         if(iBatteryChargingTimeAO)
       
   379             {
       
   380             iBatteryChargingTimeAO->SetCallBack(aChrgTimeCallback);
       
   381             }
       
   382         else
       
   383             {
       
   384             iBatteryChargingTimeAO = CHWRMBatteryChargeTimeMeasurementsAO::NewL(aChrgTimeCallback, iClient);
       
   385             }
       
   386         COMPONENT_TRACE1(_L( "iBatteryChargingTimeAO Created" ));    
       
   387         }
       
   388     
       
   389 
       
   390     COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoSetBatteryChargingObserver - return" ));
       
   391     }
       
   392 
       
   393 // -----------------------------------------------------------------------------
       
   394 // CHWRMPowerImpl::DoNotifyAverageChargingCurrent
       
   395 // 
       
   396 // -----------------------------------------------------------------------------
       
   397 //
       
   398 
       
   399 
       
   400 TInt CHWRMPowerImpl::DoNotifyAverageChargingCurrent(TRequestStatus& aStatus, const TUint& aInterval)
       
   401     {	
       
   402 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoNotifyAverageChargingCurrent()" ));
       
   403 
       
   404 	if (!iBatteryChargeCurrentRateAO)
       
   405 		{
       
   406 		COMPONENT_TRACE2(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoNotifyAverageChargingCurrent - return( - return 0x%x" ), KErrBadHandle );
       
   407 		
       
   408 		return KErrBadHandle;
       
   409 		}
       
   410 
       
   411     TInt err(KErrNone);
       
   412 
       
   413     CHWRMPower::TBatteryChargingStatus chargingStatus;
       
   414 
       
   415     err = DoGetBatteryChargingStatus(chargingStatus);
       
   416     
       
   417     if((err != KErrNone) || 
       
   418        (chargingStatus == CHWRMPower::EChargingStatusError) || 
       
   419        (chargingStatus == CHWRMPower::EChargingStatusNotConnected) || 
       
   420        (chargingStatus == CHWRMPower::EChargingStatusNotCharging))
       
   421         {
       
   422         err = KErrNotReady;
       
   423         }
       
   424 	else 
       
   425 		{		
       
   426 		iCurrentRateIntervalMultiplePckg.Set( TPckg<TUint> (aInterval) );
       
   427 		
       
   428 		iClient.ExecuteAsyncOperation(EHWRMStartAverageChargingCurrentReporting, TIpcArgs(&iCurrentRateIntervalMultiplePckg), aStatus);
       
   429 		
       
   430 		//Issue request to retrieve battery voltage measurements	
       
   431 		if( !iBatteryChargeCurrentRateAO->IsActive())
       
   432 			{
       
   433 			iBatteryChargeCurrentRateAO->GetAsyncBatch( EHWRMGetAverageChargingCurrentMeasurements );	
       
   434 			}		
       
   435 		
       
   436 
       
   437         err = KErrNone;
       
   438 		}
       
   439     
       
   440     
       
   441     COMPONENT_TRACE2(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoNotifyAverageChargingCurrent - return( - return 0x%x" ), err );
       
   442     
       
   443     return err;
       
   444 	}
       
   445 
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // CHWRMPowerImpl::DoNotifyBatteryFullChargingTime
       
   449 // 
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 TInt CHWRMPowerImpl::DoNotifyBatteryFullChargingTime(TRequestStatus& aStatus)
       
   453     {	
       
   454 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoNotifyBatteryFullChargingTime()" ));
       
   455 
       
   456 	if (!iBatteryChargingTimeAO)
       
   457 		{
       
   458 		COMPONENT_TRACE2(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoNotifyBatteryFullChargingTime - return( - return 0x%x" ), KErrBadHandle );
       
   459 		
       
   460 		return KErrBadHandle;
       
   461 		}
       
   462 
       
   463     TInt err;
       
   464 
       
   465     CHWRMPower::TBatteryChargingStatus chargingStatus;
       
   466 
       
   467     err = DoGetBatteryChargingStatus(chargingStatus);
       
   468     
       
   469     if((err != KErrNone) || 
       
   470        (chargingStatus == CHWRMPower::EChargingStatusError) || 
       
   471        (chargingStatus == CHWRMPower::EChargingStatusNotConnected) || 
       
   472        (chargingStatus == CHWRMPower::EChargingStatusNotCharging))
       
   473         {
       
   474         err = KErrNotReady;
       
   475         }
       
   476 	else 
       
   477 		{		
       
   478 				
       
   479 		iClient.ExecuteAsyncOperation(EHWRMStartBatteryFullChargingTimeReporting, TIpcArgs(), aStatus);
       
   480 		
       
   481 		//Issue request to retrieve battery full charge time measurements	
       
   482 		if( !iBatteryChargingTimeAO->IsActive())
       
   483 			{
       
   484 			iBatteryChargingTimeAO->GetAsyncBatch( EHWRMGetBatteryFullChargingTimeMeasurements );	
       
   485 			}		
       
   486         
       
   487 	    err = KErrNone;        
       
   488 		}
       
   489     
       
   490 
       
   491     COMPONENT_TRACE2(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoNotifyBatteryFullChargingTime - return( - return 0x%x" ), err );
       
   492     
       
   493     return err;
       
   494 	}
       
   495 
       
   496 // -----------------------------------------------------------------------------
       
   497 // CHWRMPowerImpl::DoStopChargingNotificationL
       
   498 // 
       
   499 // -----------------------------------------------------------------------------
       
   500 //
       
   501 void CHWRMPowerImpl::DoStopChargingNotificationL(CHWRMPower::TBatteryChargingNotifier aNotifier)
       
   502 	{	
       
   503 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoStopChargingNotificationL()" ));
       
   504 	
       
   505 	if (((aNotifier == CHWRMPower::EChargingNotifierAll)||(aNotifier == CHWRMPower::EChargingNotifierChargingCurrent))
       
   506         &&(iBatteryChargeCurrentRateAO))
       
   507 		{
       
   508 		COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::Close - canceling current measurement notifications" ));
       
   509 		iBatteryChargeCurrentRateAO->Cancel();		
       
   510 	
       
   511 		User::LeaveIfError(iClient.ExecuteOperation(EHWRMStopAverageChargingCurrentReporting, TIpcArgs()));
       
   512 
       
   513 		}
       
   514 
       
   515     
       
   516     if (((aNotifier == CHWRMPower::EChargingNotifierAll)||(aNotifier == CHWRMPower::EChargingNotifierBatteryFullChargingTime))
       
   517             &&(iBatteryChargingTimeAO))
       
   518             {
       
   519             COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::Close - canceling rem charging time measurement notifications" ));
       
   520             iBatteryChargingTimeAO->Cancel();      
       
   521         
       
   522             User::LeaveIfError(iClient.ExecuteOperation(EHWRMStopBatteryFullChargingTimeReporting, TIpcArgs()));
       
   523 
       
   524             }
       
   525 
       
   526 	COMPONENT_TRACE1(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::DoStopChargingNotificationL - return" ));
       
   527 	}
       
   528 
       
   529 void CHWRMPowerImpl::ChargingStatusChange(TInt aErrCode,CHWRMPower::TBatteryChargingStatus aChrgStatus)
       
   530     {
       
   531     if(iChargingStatusClientObserver)
       
   532         {
       
   533         iChargingStatusClientObserver->ChargingStatusChange(aErrCode, aChrgStatus);
       
   534         }
       
   535 
       
   536     //Test if notification is already stopped.
       
   537     //If already stopped, no need to cancel notification.
       
   538     TBool batteryChargeCurrentNotificationOn(EFalse);
       
   539     TBool batteryChargingTimeNotificationOn(EFalse);
       
   540     if(iBatteryChargeCurrentRateAO)
       
   541         {
       
   542         batteryChargeCurrentNotificationOn = iBatteryChargeCurrentRateAO->IsActive();
       
   543         }
       
   544     if(iBatteryChargingTimeAO)
       
   545         {
       
   546         batteryChargingTimeNotificationOn = iBatteryChargingTimeAO->IsActive();
       
   547         }
       
   548     COMPONENT_TRACE3(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::ChargingStatusChange batteryChargeCurrentNotificationOn=%d batteryChargingTimeNotificationOn=%d" ), batteryChargeCurrentNotificationOn, batteryChargingTimeNotificationOn );
       
   549     
       
   550     if(batteryChargeCurrentNotificationOn || batteryChargingTimeNotificationOn)
       
   551         {
       
   552         //Avoid using multiple TRAP's in "if and else" part below.
       
   553         //Just store whether notification(and corresponding code) needs to stopped or not.
       
   554         TBool                                stopchargingNotification(ETrue);
       
   555         CHWRMPower::TBatteryChargingNotifier cancelNotificationCode;
       
   556         
       
   557         //Stop charging notifications, if charger is not connected.
       
   558         if((aErrCode != KErrNone) || 
       
   559            (aChrgStatus == CHWRMPower::EChargingStatusError) || 
       
   560            (aChrgStatus == CHWRMPower::EChargingStatusNotConnected) || 
       
   561            (aChrgStatus == CHWRMPower::EChargingStatusNotCharging))
       
   562             {
       
   563             cancelNotificationCode       = CHWRMPower::EChargingNotifierAll;
       
   564             }
       
   565         //Stop remaining charging time notification, if charging is completed.
       
   566         else if(aChrgStatus == CHWRMPower::EChargingStatusChargingComplete)
       
   567             {
       
   568             cancelNotificationCode   = CHWRMPower::EChargingNotifierBatteryFullChargingTime;
       
   569             }
       
   570         else
       
   571             {
       
   572             stopchargingNotification = EFalse;
       
   573             }
       
   574 
       
   575         COMPONENT_TRACE2(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::ChargingStatusChange stopchargingNotification 0x%x" ), stopchargingNotification );
       
   576     
       
   577         if(stopchargingNotification)
       
   578             {
       
   579             
       
   580             TInt err;
       
   581             TRAP(err, DoStopChargingNotificationL(cancelNotificationCode));
       
   582     
       
   583             if(err == KErrNone)
       
   584                 {
       
   585                 //Since the measurements are stopped by HWRM(because of some external events),
       
   586                 //HWRM clients Notifications needs to be cancelled.
       
   587             
       
   588                 //Charging time notification is cancelled in both cases(EChargingNotifierAll and EChargingNotifierBatteryFullChargingTime)
       
   589                 if(batteryChargingTimeNotificationOn)
       
   590                     {
       
   591                     iBatteryChargingTimeAO->CancelClientNotification();
       
   592                     }
       
   593             
       
   594                 if(cancelNotificationCode == CHWRMPower::EChargingNotifierAll) 
       
   595                     {
       
   596                     if(batteryChargeCurrentNotificationOn)
       
   597                         {
       
   598                         iBatteryChargeCurrentRateAO->CancelClientNotification();
       
   599                         }
       
   600                     }
       
   601                 }
       
   602             else
       
   603                 {
       
   604                 //Just trace the error,as nothing can be done.
       
   605                 COMPONENT_TRACE2(_L( "HWRM CHWRMPowerImpl - CHWRMPowerImpl::ChargingStatusChange stop failed with 0x%x" ), err );
       
   606                 }
       
   607             }
       
   608         }
       
   609     }
       
   610 
       
   611 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   612