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