resourcemgmt/hwresourcesmgr/server/inc/HWRMPowerService.h
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23  @internalTechnology 
       
    24 */
       
    25 
       
    26 #ifndef HWRMPOWERSERVICE_H
       
    27 #define HWRMPOWERSERVICE_H
       
    28 
       
    29 //  INCLUDES
       
    30 #include <e32base.h>
       
    31 #include "HWRMGenericTimer.h"
       
    32 #include "HWRMPowerCommands.h"
       
    33 #include "HWRMPower.h"
       
    34 #include "HWRMService.h"
       
    35 #include "HWRMPowerCommonData.h"
       
    36 
       
    37 // CONSTANTS
       
    38 // None
       
    39 const TInt KHWRMPowerMaxMeasurementsBatchSize = 20;
       
    40 // MACROS
       
    41 // None
       
    42 
       
    43 // DATA TYPES
       
    44 // None
       
    45 
       
    46 // FUNCTION PROTOTYPES
       
    47 // None
       
    48 
       
    49 // FORWARD DECLARATIONS
       
    50 class CHWRMPowerCommonData;
       
    51 class CHWRMPluginHandler;
       
    52 class TPowerMeasurementsClientData;
       
    53 class THWRMPluginPowerIntervalRequestData;
       
    54 
       
    55 // CLASS DECLARATION
       
    56 
       
    57 /**
       
    58 *  Hardware Resource Manager server side service object for Power sessions.
       
    59 *
       
    60 */
       
    61 class CHWRMPowerService : public CHWRMService                         
       
    62     {    
       
    63     public: // Constructors and Destructor
       
    64     
       
    65         /**
       
    66         * Two-phased constructor.
       
    67         *
       
    68         * @param aPluginHandler The plugin handler to use with this service.
       
    69         * @param aPowerCommonData Reference to power common data
       
    70         */
       
    71         static CHWRMPowerService* NewL(CHWRMPluginHandler* aPluginHandler, CHWRMPowerCommonData& aCommonData);
       
    72         
       
    73         /**
       
    74         * Destructor.
       
    75         */
       
    76         virtual ~CHWRMPowerService();
       
    77     
       
    78     public: // Base class methods
       
    79     
       
    80         // From CHWRMService
       
    81     	virtual TBool ExecuteMessageL(const RMessage2& aMessage);
       
    82     	virtual void ProcessResponseL( TInt aCommandId,  TUint8 aTransId, TDesC8& aData, TBool aTimeout );
       
    83     	virtual void SuspendSubResource(TInt aSubResource);
       
    84     	virtual void ResumeSubResource(TInt aSubResource);
       
    85         virtual void ActivateSubResource(TInt aSubResource, TBool aActivate);
       
    86         
       
    87     public:
       
    88     	/**
       
    89      	* Issues a plugin command to stop the power measurements. Not 
       
    90      	* associated with a client RMessage2
       
    91      	*/
       
    92         void StopPowerMeasurementsL();
       
    93 
       
    94         /**
       
    95         * Issues a plugin command to Set the Plugin Interval Multiple. Not 
       
    96         * associated with a client RMessage2
       
    97         * Specifically added for charge rate current reporting.
       
    98         */
       
    99         void SetPluginIntervalMultipleL(HWRMPowerCommand::TPowerCmd aCommand,
       
   100                                         TUint aIntervalMultiple);
       
   101 
       
   102         
       
   103         /**
       
   104          * Gets the Battery consumption info
       
   105          * 
       
   106          * Handles EHWRMGetBatteryInfo requests.
       
   107          */      
       
   108          void GetBatteryInfoL(const RMessage2& aMessage);
       
   109          
       
   110 
       
   111          /**
       
   112          * Gets the Baterry voltage info
       
   113          * 
       
   114          * Handles EHWRMGetBatteryVoltageInfo requests.
       
   115          */      
       
   116          void GetBatteryVoltageInfoL(const RMessage2& aMessage);
       
   117 
       
   118 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   119 
       
   120          /**
       
   121         * Issues a plugin command to stop the Charging Current measurements. Not 
       
   122         * associated with a client RMessage2
       
   123         */
       
   124         void StopChargingCurrentMeasurementsL();
       
   125 
       
   126         /**
       
   127         * Issues a plugin command to stop the BatteryFull charging time measurements. Not 
       
   128         * associated with a client RMessage2
       
   129         */
       
   130         void StopChargingTimeMeasurementsL();
       
   131 
       
   132 
       
   133          /**
       
   134          * Gets the charger type
       
   135          * 
       
   136          * Handles EHWRMGetBatteryChargerType request.
       
   137          */      
       
   138          void GetChargerTypeL(const RMessage2& aMessage);
       
   139 
       
   140 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   141          
       
   142     private: 
       
   143     
       
   144         /**
       
   145         * C++ default constructor.
       
   146         */
       
   147         CHWRMPowerService(CHWRMPowerCommonData& aPowerCommonData);
       
   148 
       
   149         /**
       
   150         * By default Symbian 2nd phase constructor is private.
       
   151         */
       
   152         void ConstructL(CHWRMPluginHandler* aPluginHandler);
       
   153 
       
   154     private:
       
   155 
       
   156         /**
       
   157         * Starts the periodic reporting of avegage battery power value 
       
   158         * (period = TIntervalMultiple * BaseTimeInterval)
       
   159         * 
       
   160         * Handles EStartAverageBatteryPowerReportingCmdId requests.
       
   161         */      
       
   162         void StartAverageBatteryPowerReportingL(const RMessage2& aMessage);
       
   163 
       
   164         /**
       
   165         * Stops the periodic reporting of avegage battery power value
       
   166         * 
       
   167         * Handles EHWRMStopAverageBatteryPowerReporting requests.
       
   168         */      
       
   169         void StopAverageBatteryPowerReportingL(const RMessage2& aMessage);
       
   170 
       
   171 
       
   172 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   173 
       
   174         /**
       
   175         * Starts the periodic reporting of average charging current value 
       
   176         * (period = TIntervalMultiple * BaseTimeInterval)
       
   177         * 
       
   178         * Handles EHWRMStartAverageChargingCurrentReporting requests.
       
   179         */      
       
   180 
       
   181 
       
   182         void StartAverageChargingCurrentReportingL(const RMessage2& aMessage);
       
   183 
       
   184         /**
       
   185         * Stops the periodic reporting of average charging current value/
       
   186         * 
       
   187         * Handles  requests.
       
   188         */      
       
   189         void StopAverageChargingCurrentReportingL(const RMessage2& aMessage);
       
   190 
       
   191         /**
       
   192         * Starts the reporting of battery full charging time measurements.
       
   193         * Period is decided by plugin.
       
   194         * 
       
   195         * Handles EHWRMStartBatteryFullChargingTimeReporting requests.
       
   196         */      
       
   197         void StartChargingTimeReportingL(const RMessage2& aMessage);
       
   198 
       
   199 
       
   200         /**
       
   201         * Stops the reporting of battery full charging time measurements.
       
   202         * 
       
   203         * Handles EHWRMStopBatteryFullChargingTimeReporting requests.
       
   204         */      
       
   205         void StopChargingTimeReportingL(const RMessage2& aMessage);
       
   206 
       
   207 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   208         
       
   209         /**
       
   210         * Handles EHWRMCleanupBattery requests.
       
   211         * 
       
   212         * Cleans up the power service so that session can be closed.
       
   213         */        
       
   214         void CleanupPowerL();
       
   215         
       
   216         /**
       
   217          * Executes a plugin command and handles related transaction.
       
   218          *
       
   219          * @param aCommandId Command ID of the command.  
       
   220          */
       
   221         void ExecutePluginCommand(HWRMPowerCommand::TPowerCmd aCommand);
       
   222 
       
   223         /**
       
   224          * Executes a plugin command and handles related transaction.
       
   225          *
       
   226          * @param aCommandId Command ID of the command.  
       
   227          * @param aSplitCommand ETrue if this command is split into multiple transactions
       
   228          * @param aPckg Command package
       
   229          */
       
   230         void ExecutePluginCommand(HWRMPowerCommand::TPowerCmd aCommand,
       
   231                                                     TBool /* aSplitCommand */,
       
   232                                                     TDesC8& aPckg );
       
   233         
       
   234         /**
       
   235         * Executes a plugin command and handles related transaction.
       
   236         *
       
   237         * @param aMessage Message related to this command.
       
   238         * @param aCommandId Command ID of the command.  
       
   239         * @param aSplitCommand ETrue if this command is split into multiple transactions
       
   240         */
       
   241         void ExecutePluginCommandL(const RMessage2& aMessage,
       
   242                                     HWRMPowerCommand::TPowerCmd aCommandId,
       
   243                                     TBool aSplitCommand );
       
   244 
       
   245         /**
       
   246         * Executes a plugin command and handles related transaction.
       
   247         *
       
   248         * @param aMessage Message related to this command.
       
   249         * @param aCommandId Command ID of the command.  
       
   250         * @param aSplitCommand ETrue if this command is split into multiple transactions        
       
   251         * @param aPckg Command package
       
   252         */
       
   253         void ExecutePluginCommandL(const RMessage2& aMessage,
       
   254                                     HWRMPowerCommand::TPowerCmd aCommandId,
       
   255                                     TBool aSplitCommand,
       
   256                                     TDesC8& aPckg );
       
   257 
       
   258 
       
   259         /**
       
   260         * Executes a plugin command and handles related transaction.
       
   261         *
       
   262         * @param aMessage Message related to this command.
       
   263         * @param aCommandId Command ID of the command.  
       
   264         * @param aSplitCommand ETrue if this command is split into multiple transactions        
       
   265         * @param aPckg Command package  
       
   266         * @param aArg Generic integer parameter for THWRMPowerPluginRequestData       
       
   267         */
       
   268         void ExecutePluginCommandL(const RMessage2& aMessage,
       
   269                                     HWRMPowerCommand::TPowerCmd aCommandId,
       
   270                                     TBool aSplitCommand,
       
   271                                     TDesC8& aPckg,
       
   272                                     TInt aArg );
       
   273         /**
       
   274         * Cancels a plugin command and handles the related transaction(s).
       
   275         *
       
   276         * @param aCommandId Command ID of the command.  
       
   277         */
       
   278         void CancelPluginCommandL(HWRMPowerCommand::TPowerCmd aCommandId);
       
   279           
       
   280         /**
       
   281         * Checks the response data size
       
   282         *
       
   283         * @return ETrue if aData.Size() is correct
       
   284         */
       
   285         TBool CheckResponseDataSize( TInt aCommandId, TDesC8& aData) ;
       
   286         
       
   287     private:  // data
       
   288     
       
   289         CHWRMPowerCommonData&       	iPowerCommonData;    // Pointer to Power data object common to all sessions. Not owned.
       
   290         
       
   291         TPowerMeasurementsClientData* 	iPowerVoltageCurrentMeasurementsClientData;	// pointer to the Voltage*Current(Power) data measurements of the client
       
   292 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   293         TPowerMeasurementsClientData* 	iPowerChargingCurrentMeasurementsClientData;	// pointer to the consumption data measurements of the client
       
   294         TPowerMeasurementsClientData* 	iPowerChargingTimeMeasurementsClientData;     		// pointer to the voltage data measurements of the client
       
   295 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   296         TBool                   	    iSuspended;          // Flag to indicate if this session is suspended.
       
   297     };
       
   298 
       
   299 /**
       
   300 * PowerService holds two objects of class TPowerMeasurementsClientData one for voltage and
       
   301 * one for consumptin measurements.
       
   302 * It holds the list of data measurements. Measurements from the plugin are propagated to this class
       
   303 * from the CCLientsData of the PowerCommonData. 
       
   304 * Caches Start and GetMeasuements messages from the client
       
   305 * and is responsible for completing or cancelling them. 
       
   306 */
       
   307 class TPowerMeasurementsClientData 
       
   308 	{ 
       
   309 public:// Constructors and Destructor
       
   310 	/**
       
   311 	 * C++ Constructor
       
   312 	 */
       
   313 	TPowerMeasurementsClientData();
       
   314 	
       
   315 	/**
       
   316 	 * C++ Destructor
       
   317 	 */
       
   318 	virtual ~TPowerMeasurementsClientData();
       
   319 public:
       
   320 
       
   321 	/**
       
   322 	 * Adds a Measurement to the iMeasurementsQue
       
   323 	 */
       
   324     virtual void AddMeasurementL(TDesC8& aMeasurement) = 0;
       
   325 	
       
   326 	
       
   327 	/**
       
   328 	* If at least one measurement is collected the data is written to 
       
   329 	* the messasge and the client is completed. If not the 
       
   330 	* message hanlde is stored and the client is completed
       
   331 	* when data is ready
       
   332 	*/       
       
   333     virtual TBool GetMeasurementsL(RMessage2 aMessage) = 0;
       
   334 	 
       
   335 	/**
       
   336 	* Check if we are receiving measurements.
       
   337 	*/        
       
   338 	TBool IsMeasuringOn();
       
   339 	
       
   340 	/**
       
   341 	* Set the measuring flag on.
       
   342 	*/        
       
   343 	void SetMeasuringOn();
       
   344 	
       
   345 	/**
       
   346 	* Set the measuring flag off.
       
   347 	*/        
       
   348 	void SetMeasuringOff();
       
   349 
       
   350 	/**
       
   351 	* If there exists a cached message of the client requesting measuremnts, it is completed with Error code aReason
       
   352 	*/        
       
   353 	void CompleteGetMeasurementsMessage(TInt aReason);
       
   354 	
       
   355 	/**
       
   356  	* If there exists a cached message of the client requesting measuremnts, it is completed with KErrCancel
       
   357 	*/	    
       
   358 	void CancelPendingGetMeasurementsMessage();
       
   359 	
       
   360 	/* 
       
   361 	 * The Measurements collected are written in the message area of the message.
       
   362 	 */
       
   363     virtual void WriteMeasurementsInMessageL() = 0;
       
   364 	
       
   365 	/**
       
   366 	* If there exists a cached message of the client requesting to STart measuremnts, it is completed with Error code aReason
       
   367 	*/        
       
   368 	void CompletePendingStart(TInt aReason);
       
   369 	
       
   370 	/**
       
   371 	* Resets the object in order to be ready for a new measurements session.
       
   372 	*/   
       
   373 	virtual void Reset();
       
   374 	
       
   375 	/**
       
   376 	* Called if the client has registerd for measurements and a new measurement is sent by the plugin.
       
   377 	*/   	
       
   378     virtual void NewBatteryMeasurementL(TDesC8& aValue, TUint aPluginInterval) = 0;
       
   379 public:
       
   380     //Changing to TUint as Charge current report needs it.     
       
   381 	TUint 	iRequestedIntervalMultiple;		//The interval multiple that the client requested
       
   382 	
       
   383 	TUint 							iNumOfBaseIntervalsPassed;		// number of Base intervals for which we have accumulated measurements
       
   384 																	// when this value is equal or greater than the Requested Interval Multiple
       
   385 																	// the average is calculated and added as a new measurement to the list
       
   386 	TBool 							iMeasuring;						// flag indicating if the client has started measuremnets
       
   387 	TUint 							iMeasurementsCount;				// number of collected measurements		
       
   388 	
       
   389 	RMessage2 						iRequestedBatchMessage;			// used to complete clients. NULL indicates no pending requests
       
   390 	RMessage2 						iRequestedStartMessage;			// used to complete clients. NULL indicates no pending requests
       
   391 	};
       
   392 	
       
   393 class TPowerIntMeasurementsClientData : public TPowerMeasurementsClientData
       
   394     {
       
   395 
       
   396    struct TPluginIntMeasurementFormat
       
   397     {
       
   398     TInt iError;        //Error Code.
       
   399     TInt iMeasurement;  //Measurement received from Plugin.
       
   400     };
       
   401 
       
   402     /**
       
   403     *  Holds a power measurement.
       
   404     */
       
   405 
       
   406     class TPowerIntMeasurement
       
   407         {
       
   408     public:
       
   409         TInt        iAverageValue;
       
   410         TSglQueLink iSglQueLink;
       
   411         };
       
   412     
       
   413     public:
       
   414         
       
   415     typedef TPckgBuf<TInt> TIntMeasurementsPckg;
       
   416 
       
   417     TPowerIntMeasurementsClientData();
       
   418 
       
   419     ~TPowerIntMeasurementsClientData();
       
   420     
       
   421     /**
       
   422      * Adds a Measurement to the iMeasurementsQue
       
   423      */
       
   424     virtual void AddMeasurementL(TDesC8& aMeasurement);
       
   425     
       
   426     /* 
       
   427      * The Measurements collected are written in the message area of the message.
       
   428      */
       
   429     
       
   430     virtual void WriteMeasurementsInMessageL();
       
   431     
       
   432     /**
       
   433      * Resets the object in order to be ready for a new measurements session.
       
   434      */   
       
   435 
       
   436     virtual void Reset();
       
   437     
       
   438     /**
       
   439      * Called if the client has registerd for measurements and a new measurement is sent by the plugin.
       
   440      */         
       
   441     
       
   442     virtual void NewBatteryMeasurementL(TDesC8& aValue, TUint aPluginInterval);
       
   443 
       
   444     /**
       
   445      * If at least one measurement is collected the data is written to 
       
   446      * the messasge and the client is completed. If not the 
       
   447      * message hanlde is stored and the client is completed
       
   448      * when data is ready
       
   449      */       
       
   450 
       
   451 
       
   452     virtual TBool GetMeasurementsL(RMessage2 aMessage);
       
   453 
       
   454     /**
       
   455      * Transfers the collecetd data from the list to a TFixedArray, appropriate for client-server
       
   456      * data trasnfer.
       
   457      */
       
   458     void TransferMeasurementsToFixedArrayL(TFixedArray<TInt,KHWRMPowerMaxMeasurementsBatchSize> &aFixedArray);
       
   459 
       
   460     private:
       
   461         
       
   462     TSglQue<TPowerIntMeasurement>      iMeasurementsQue;               // list of the measurements
       
   463     TSglQueIter<TPowerIntMeasurement>  iMeasurementsQueIter;
       
   464 
       
   465     TInt                            iAccumulator;                   // measurements are accumulated until there are enough values to calculate the average
       
   466 
       
   467 
       
   468     };
       
   469 
       
   470 class TPowerVoltageCurrentMeasurementsClientData : public TPowerMeasurementsClientData
       
   471     {
       
   472 
       
   473    /* Power(Voltage and Current) measurement from plugin 
       
   474       should in this format.
       
   475     */
       
   476    struct TPluginVoltageCurrentMeasurementFormat
       
   477     {
       
   478     TInt iError;                       //Error Code.
       
   479     TInt iAverageVoltageMeasurement;  //Voltage Measurement received from Plugin.
       
   480     TInt iAverageCurrentMeasurement;  //Current Measurement received from Plugin.
       
   481     };
       
   482 
       
   483     /**
       
   484     *  Holds a power measurement.
       
   485     */
       
   486 
       
   487     class TPowerVoltageCurrentMeasurement
       
   488         {
       
   489     public:
       
   490         TInt        iAverageVoltageValue;
       
   491         TInt        iAverageCurrentValue;
       
   492         TSglQueLink iSglQueLink;
       
   493         };
       
   494     
       
   495     struct TPowerVoltageCurrent
       
   496         {
       
   497         TInt        iAverageVoltage;
       
   498         TInt        iAverageCurrent;
       
   499         };
       
   500     
       
   501     public:
       
   502         
       
   503     typedef TPckgBuf<TPowerVoltageCurrent> TVoltageCurrentMeasurementsPckg;
       
   504 
       
   505     TPowerVoltageCurrentMeasurementsClientData();
       
   506 
       
   507     ~TPowerVoltageCurrentMeasurementsClientData();
       
   508     
       
   509     /**
       
   510      * Adds a Measurement to the iMeasurementsQue
       
   511      */
       
   512     virtual void AddMeasurementL(TDesC8& aMeasurement);
       
   513     
       
   514     /* 
       
   515      * The Measurements collected are written in the message area of the message.
       
   516      */
       
   517     
       
   518     virtual void WriteMeasurementsInMessageL();
       
   519     
       
   520     /**
       
   521      * Resets the object in order to be ready for a new measurements session.
       
   522      */   
       
   523 
       
   524     virtual void Reset();
       
   525     
       
   526     /**
       
   527      * Called if the client has registerd for measurements and a new measurement is sent by the plugin.
       
   528      */         
       
   529     
       
   530     virtual void NewBatteryMeasurementL(TDesC8& aValue, TUint aPluginInterval);
       
   531 
       
   532     /**
       
   533      * If at least one measurement is collected the data is written to 
       
   534      * the messasge and the client is completed. If not the 
       
   535      * message hanlde is stored and the client is completed
       
   536      * when data is ready
       
   537      */       
       
   538 
       
   539 
       
   540     virtual TBool GetMeasurementsL(RMessage2 aMessage);
       
   541 
       
   542     /**
       
   543      * Transfers the collecetd data from the list to a TFixedArray, appropriate for client-server
       
   544      * data trasnfer.
       
   545      */
       
   546     void TransferMeasurementsToFixedArrayL(TFixedArray<TPowerVoltageCurrent,KHWRMPowerMaxMeasurementsBatchSize> &aFixedArray);
       
   547 
       
   548     private:
       
   549         
       
   550     TSglQue<TPowerVoltageCurrentMeasurement>      iMeasurementsQue;               // list of the measurements
       
   551     TSglQueIter<TPowerVoltageCurrentMeasurement>  iMeasurementsQueIter;
       
   552 
       
   553     TInt                            iVoltageAccumulator;                   // measurements are accumulated until there are enough values to calculate the average voltage
       
   554     TInt                            iCurrentAccumulator;                   // measurements are accumulated until there are enough values to calculate the average current
       
   555 
       
   556 
       
   557     };
       
   558     
       
   559 /**
       
   560 * Data storage class for plugin requests.
       
   561 */
       
   562 class THWRMPluginPowerIntervalRequestData : public THWRMPluginTransactionListItem
       
   563     {
       
   564     public:
       
   565     	TUint iRequestedPluginIntervalMultiple;
       
   566 
       
   567         /**
       
   568 	    * Convenience constructor
       
   569 	    */
       
   570     	THWRMPluginPowerIntervalRequestData(TUint aRequestedPluginIntervalMultiple, TInt aCommandId)
       
   571 	        : THWRMPluginTransactionListItem(0, aCommandId), //TransId is updated later
       
   572 	        iRequestedPluginIntervalMultiple(aRequestedPluginIntervalMultiple)
       
   573 	            {
       
   574 	            };
       
   575 	    /**
       
   576 	    * Virtual destructor.
       
   577 	    */
       
   578 	    virtual ~THWRMPluginPowerIntervalRequestData()
       
   579 	        {
       
   580 	        };
       
   581     };
       
   582 		
       
   583     
       
   584 #endif  // HWRMPowerSERVICE_H
       
   585             
       
   586 // End of File