resourcemgmt/hwresourcesmgr/power/src/HWRMBatteryChargeTimeMeasurementsAO.cpp
changeset 0 4e1aa6a622a0
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 "HWRMBatteryMeasurementsAO.h"
       
    18 #include "HWRMBatteryChargeTimeMeasurementsAO.h"
       
    19 #include "HWRMtrace.h"
       
    20 
       
    21 // ============================ MEMBER FUNCTIONS ===============================
       
    22 
       
    23 // -----------------------------------------------------------------------------
       
    24 // HWRMBatteryChargeTimeMeasurementsAO::HWRMBatteryChargeTimeMeasurementsAO
       
    25 // C++ constructor can NOT contain any code, that
       
    26 // might leave.
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 CHWRMBatteryChargeTimeMeasurementsAO::CHWRMBatteryChargeTimeMeasurementsAO(MHWRMBatteryFullChargingTimeObserver* aCallback, RHWRMClient& aClient)
       
    30     : CHWRMBatteryMeasurementsAttributeAO<TInt>(aClient), iCallback(aCallback)
       
    31     {        
       
    32     CActiveScheduler::Add(this);        
       
    33     }
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // HWRMBatteryChargeTimeMeasurementsAO::NewL
       
    37 // Two-phased constructor
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CHWRMBatteryChargeTimeMeasurementsAO* CHWRMBatteryChargeTimeMeasurementsAO::NewL(MHWRMBatteryFullChargingTimeObserver* aCallback, RHWRMClient& aClient)
       
    41     {
       
    42 
       
    43     CHWRMBatteryChargeTimeMeasurementsAO* newInstance = new (ELeave) CHWRMBatteryChargeTimeMeasurementsAO(aCallback, aClient);
       
    44 
       
    45 	CleanupStack::PushL( newInstance );
       
    46 	
       
    47 	newInstance->ConstructL();
       
    48 
       
    49 	CleanupStack::Pop();
       
    50 
       
    51 	return newInstance;
       
    52     }
       
    53 
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // Destructor
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CHWRMBatteryChargeTimeMeasurementsAO::~CHWRMBatteryChargeTimeMeasurementsAO()
       
    60     {
       
    61     Cancel();
       
    62     }
       
    63 
       
    64 void CHWRMBatteryChargeTimeMeasurementsAO::DoCancel()
       
    65     {    
       
    66     	SendCancel(EHWRMCancelBatteryFullChargingTimeReporting);
       
    67     }
       
    68 // -----------------------------------------------------------------------------
       
    69 // HWRMBatteryChargeTimeMeasurementsAO::ConstructL
       
    70 // Symbian 2nd phase constructor can leave.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CHWRMBatteryChargeTimeMeasurementsAO::ConstructL()
       
    74     {
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // HWRMBatteryChargeTimeMeasurementsAO::RunL
       
    79 // invoked when request issued to hwrm server in AsynchGetBatch
       
    80 // completes
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CHWRMBatteryChargeTimeMeasurementsAO::RunL()
       
    84     {    
       
    85     TInt err = iStatus.Int();
       
    86 
       
    87     if( (KErrNone != err) && (KErrTimedOut != err) )
       
    88     	{
       
    89     	//if there is an error and it is not a timed out error 
       
    90     	iCallback->BatteryFullChargingTimeChange(err, 0); 
       
    91     	return;
       
    92     	}
       
    93 
       
    94     iCount = iCountPckg();
       
    95     
       
    96     //dispatch results received from server         
       
    97     TUint index = 0;
       
    98     while(index < iCount)
       
    99     	{   
       
   100         iCallback->BatteryFullChargingTimeChange(KErrNone, iResultsArray[index]); 
       
   101         ++index;
       
   102     	}
       
   103 
       
   104     iResultsArray.Reset();
       
   105     iCount = 0;
       
   106     
       
   107     // Re-order measurements only if reporting period has not expired on server
       
   108     if(KErrTimedOut != err)
       
   109     	{
       
   110     	//re-order measuremens batch from server.
       
   111     	GetAsyncBatch(EHWRMGetBatteryFullChargingTimeMeasurements); 
       
   112     	}
       
   113     else
       
   114     	{
       
   115     	//it is a timed out error
       
   116     	iCallback->BatteryFullChargingTimeChange(err, 0); 
       
   117     	}
       
   118     }
       
   119 
       
   120 void CHWRMBatteryChargeTimeMeasurementsAO::CancelClientNotification()
       
   121     {
       
   122     iCallback->BatteryFullChargingTimeChange(KErrCancel, 0); 
       
   123     }
       
   124 
       
   125 void CHWRMBatteryChargeTimeMeasurementsAO::SetCallBack(TAny* aCallBack)
       
   126     {
       
   127     iCallback = (MHWRMBatteryFullChargingTimeObserver*)aCallBack;
       
   128     }
       
   129 
       
   130 
       
   131 // End of File