resourcemgmt/hwresourcesmgr/server/inc/HWRMPowerCommonData.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 HWRMPOWERCOMMONDATA_H
       
    27 #define HWRMPOWERCOMMONDATA_H
       
    28 
       
    29 //  INCLUDES
       
    30 #include <e32base.h>
       
    31 #include "HWRMPower.h"
       
    32 #include "HWRMPowerService.h"
       
    33 #include "HWRMGenericTimer.h"
       
    34 #include "HWRMPluginService.h"
       
    35 #include "HWRMPluginHandler.h"
       
    36 #include "cenrepobserver.h"
       
    37 
       
    38 
       
    39 // CONSTANTS
       
    40 // None
       
    41 
       
    42 // MACROS
       
    43 // None
       
    44 
       
    45 // DATA TYPES
       
    46 // None
       
    47 
       
    48 // FUNCTION PROTOTYPES
       
    49 // None
       
    50 
       
    51 // FORWARD DECLARATIONS
       
    52 class CHWRMPluginHandler;
       
    53 class CHWRMPowerService;
       
    54 class CClientsData;
       
    55 class TPowerMeasurementsClientData;
       
    56 
       
    57 // CLASS DECLARATION
       
    58 
       
    59 /** Item of the list that holds data for a GetBatteryInfo or GetBatteryVoltageInfo request.
       
    60  * Used by the PowerCommonData iBatteryVoltageInfoQue, iBatteryInfoQue and iChargerTypeInfoQue.
       
    61  */
       
    62 class TBatteryInfoData
       
    63 	{
       
    64 public:
       
    65 	TBatteryInfoData(const CHWRMPowerService& aPowerClientService, const RMessage2& aRequestedMessage);
       
    66 public:
       
    67 	const CHWRMPowerService& 		iPowerClientService; // Used to identify the client that the message belongs to.
       
    68 	RMessage2						iRequestedMessage;
       
    69 	TSglQueLink						iSglQueLink;
       
    70 	};    
       
    71 
       
    72 
       
    73 /**
       
    74 * Container for Power data that is common for all sessions.
       
    75 * Also handles Power related cenrep.
       
    76 * HWRM server upkeeps the instance.
       
    77 *
       
    78 */
       
    79 class CHWRMPowerCommonData : public CBase,
       
    80 							 public MHWRMIndicationHandler,
       
    81 							 public MHWRMGenericTimerCallback,
       
    82 							 public MCenRepObserver
       
    83     {
       
    84 public: // Constructors and Destructor
       
    85 
       
    86     /**
       
    87     * Two-phased constructor.
       
    88     *
       
    89     * @param aPluginHandler Pointer to plugin handler for Power
       
    90     */
       
    91     static CHWRMPowerCommonData* NewL(CHWRMPluginHandler* aPluginHandler);
       
    92     
       
    93     /**
       
    94     * Destructor.
       
    95     */
       
    96     virtual ~CHWRMPowerCommonData();
       
    97 
       
    98 public: // Functions from base classes	
       
    99 	/**
       
   100 	* Called by the PluginHandler to indicate a new event
       
   101 	* 
       
   102 	* From MHWRMIndicationHandler
       
   103 	*
       
   104     * @param aId  The indication ID
       
   105     * @param aData  Data associated with the indication 
       
   106 	*/
       
   107 	void ProcessIndicationL( const TUint32 aId, TDesC8& aData );
       
   108 	
       
   109 	/**
       
   110 	* Called when the timer is fired
       
   111 	* 
       
   112 	* From MHWRMGenericTimerCallback
       
   113 	*
       
   114 	* @param aTimerId Id used to distinguish among different timers
       
   115 	* @param aCutOff not used here
       
   116 	*/
       
   117 	void GenericTimerFired(TInt aTimerId, TBool /*aCutOff*/);
       
   118 
       
   119 public: // New functions
       
   120 
       
   121     /**
       
   122     * Issues a plugin command to stop the Consumption measurements.
       
   123     */    
       
   124     void DoStopPowerMeasurementsL();
       
   125     
       
   126     /**
       
   127      * Called when the Maximum Reporting period in Cenrep is changed
       
   128      * 
       
   129      * @param aNewMaxPeriod the new max reporting period in Cenrep 
       
   130      * @param aOldMaxPeriod the old max reporting period in Cenrep
       
   131      */
       
   132     void MaxPeriodChangedL(TTimeIntervalMicroSeconds32& aNewMaxPeriod,
       
   133                            TTimeIntervalMicroSeconds32& aOldMaxPeriod);
       
   134     /*
       
   135      * Invoked by MaxPeriodChangeL
       
   136      * 
       
   137      * @param aTimer A generic Timer that has to be altered depending on the reporting period
       
   138      * @param aNewMaxPeriod the new max reporting period in Cenrep 
       
   139      * @param aOldMaxPeriod the old max reporting period in Cenrep
       
   140      */
       
   141     void DoMaxReportingValueChangedL(CHWRMGenericTimer* aTimer, 
       
   142                                     TTimeIntervalMicroSeconds32& aNewMaxPeriod,
       
   143                                     TTimeIntervalMicroSeconds32& aOldMaxPeriod);
       
   144 
       
   145     // From MCenRepObserver
       
   146     void HandleNotifyInt(TUint32 aId, TInt aNewValue);
       
   147     void HandleNotifyError(TUint32 aId, TInt error, CCenRepListener* aHandler);
       
   148 
       
   149 
       
   150     /**
       
   151     * Issues a plugin command to set the plugin interval of charge current measurements.
       
   152     * 
       
   153     * @param aCommand distinguishes which interval is to be set (possible values: ESetVoltageIntervalMultipleCmdId, ESetCosnumptionIntervalMultipleCmdId)
       
   154     * @param aIntervalMultiple the value that the plugin interval will be set to
       
   155     */          
       
   156     void DoSetPluginIntervalMultipleL(HWRMPowerCommand::TPowerCmd aCommand,
       
   157                                     TUint aIntervalMultiple);
       
   158 
       
   159     /**
       
   160      * Issues a plugin command to get Battery Info. If there is an outstanding plugin request there isn't a new
       
   161  	 * one issued but the appropriate data are stored in a queue. This data are used later to complete or cancel the client.
       
   162      * 
       
   163      * @param aPowerService the service of the client session that issued the command.
       
   164      * @param aMessage the client message that requested the the Battery Info.
       
   165      */        
       
   166     void DoGetBatteryInfoL(const RMessage2& aMessage, const CHWRMPowerService& aPowerService);
       
   167     
       
   168     /**
       
   169      * Issues a plugin command to get Battery Voltage Info. If there is an outstanding plugin request there isn't a new
       
   170  	 * one issued but the appropriate data are stored in a queue. This data are used later to complete or cancel the client.
       
   171      * 
       
   172      * @param aPowerService the service of the client session that issued the command.
       
   173      * @param aMessage the client message that requested the the Battery Info.
       
   174      */       
       
   175     void DoGetBatteryVoltageInfoL(const RMessage2& aMessage, const CHWRMPowerService& aPowerService);
       
   176     
       
   177     /**
       
   178      * Completes any pending GetBatteryInfo requests.
       
   179      * 
       
   180      * @param aReason	the Error code that is used for completion.
       
   181      * @param aDataPckg data that will be written in the response message (can be an empty Des).
       
   182      */       
       
   183     void CompletePendingGetBatteryInfo(TInt aReason, TPckg<CHWRMPower::TBatteryConsumptionData> &aDataPckg);
       
   184 
       
   185     /**
       
   186      * Completes any pending GetBatteryVoltageInfo requests.
       
   187      * 
       
   188      * @param aReason	the Error code that is used for completion.
       
   189      * @param aDataPckg data that will be written in the response message (can be an empty Des).
       
   190      */       
       
   191     void CompletePendingGetBatteryVoltageInfo(TInt aReason, TPckg<CHWRMPower::TBatteryVoltageData> &aDataPckg);
       
   192     
       
   193     /**
       
   194      * Cancels any pending GetBatteryInfo requests.
       
   195      * 
       
   196      * @param aPowerService the service of the client session that issued the command. Used to identify the requests taht belong to the client.
       
   197      */          
       
   198     void CancelPendingGetBatteryInfo(CHWRMPowerService& aPowerService);
       
   199 
       
   200     /**
       
   201      * Cancels any pending GetBatteryVoltageInfo requests.
       
   202      * 
       
   203      * @param aPowerService the service of the client session that issued the command. Used to identify the requests taht belong to the client.
       
   204      */          
       
   205     void CancelPendingGetBatteryVoltageInfo(CHWRMPowerService& aPowerService);
       
   206 
       
   207 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   208     /**
       
   209     * Issues a plugin command to stop the charging current measurements.
       
   210     */    
       
   211     void DoStopChargingCurrentMeasurementsL();
       
   212 
       
   213     /**
       
   214     * Issues a plugin command to stop the BatteryFull charging time measurements.
       
   215     */    
       
   216     void DoStopChargingTimeMeasurementsL();
       
   217 
       
   218      /**
       
   219      * Issues a plugin command to get charger type. If there is an outstanding plugin request there isn't a new
       
   220  	 * one issued but the appropriate data are stored in a queue. This data are used later to complete the request.
       
   221      * 
       
   222      * @param aPowerService the service of the client session that issued the command.
       
   223      * @param aMessage the client message that requested the charger type.
       
   224      */        
       
   225     void DoGetChargerTypeL(const RMessage2& aMessage, const CHWRMPowerService& aPowerService);
       
   226 
       
   227      /**
       
   228      * Completes any pending ChargerType Info requests.
       
   229      * 
       
   230      * @param aReason	the Error code that is used for completion.
       
   231      * @param aDataPckg data that will be written in the response message (can be an empty Des).
       
   232      */       
       
   233     void CompletePendingGetChargerType(TInt aReason, TPckg<CHWRMPower::TBatteryChargerType> &aDataPckg);
       
   234 
       
   235     /**
       
   236      * Cancels any pending GetChargetType requests.
       
   237      * 
       
   238      * @param aPowerService the service of the client session that issued the command. Used to identify the requests taht belong to the client.
       
   239      */        
       
   240     void CancelPendingGetChargerType(CHWRMPowerService& aPowerService);
       
   241 
       
   242 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   243     
       
   244 private:
       
   245 
       
   246 	/**
       
   247 	* C++ default constructor.
       
   248 	*/
       
   249 	CHWRMPowerCommonData();
       
   250 	
       
   251 	/**
       
   252 	* By default Symbian 2nd phase constructor is private.
       
   253 	*
       
   254 	* @param aPluginHandler Pointer to plugin handler for Power
       
   255 	*/
       
   256 	void ConstructL(CHWRMPluginHandler* aPluginHandler);
       
   257 
       
   258 public:
       
   259     CRepository*                    iRepository;                        // Cenrep client
       
   260     CCenRepListener*                iMaxReportingPeriodNotifyHandler;   // Cenrep notifyhandler
       
   261     CClientsData*                   iPowerReportClientsData;            // List of clients that have registered for Average Power Measurements Reporting
       
   262 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   263 	CClientsData*					iChargingCurrentClientsData;	// List of clients that have registered for Average Charging Current Measurements Reporting
       
   264 	CClientsData*					iChargingTimeClientsData;	    // List of clients that have registered for Battery Full Charging Time Measurements Reporting
       
   265 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   266 	
       
   267 	TSglQue<TBatteryInfoData> 		iBatteryInfoQue;				// list of the pending GetBatteryInfo requests
       
   268 	TSglQueIter<TBatteryInfoData> 	iBatteryInfoIter;				// iterator of the list
       
   269 	
       
   270 	TSglQue<TBatteryInfoData> 		iBatteryVoltageInfoQue;			// list of the pending GetBatteryVoltageInfo requests
       
   271 	TSglQueIter<TBatteryInfoData> 	iBatteryVoltageInfoIter;		// iterator of the list
       
   272 
       
   273 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   274     TSglQue<TBatteryInfoData> 		iChargerTypeInfoQue;			// list of the pending GetChargerType requests
       
   275 	TSglQueIter<TBatteryInfoData> 	iChargerTypeInfoIter;			// iterator of the list
       
   276 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   277 
       
   278 
       
   279     
       
   280 private:
       
   281 	TUint							iBaseTimeInterval;				// Value of Base Time Interval is cached here from CenRep
       
   282 	TUint 							iMaximumReportingPeriod;		// Value of Maximum Reporting Period is cached here from CenRep
       
   283   
       
   284     CHWRMGenericTimer*   			iPowerReportMeasurementsTimer;      // Cutoff timer. Owned.
       
   285 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   286     CHWRMGenericTimer*  	 		iChargingCurrentMeasurementsTimer; 	// Cutoff timer. Owned.    
       
   287     CHWRMGenericTimer*  	 		iChargingTimeMeasurementsTimer; 	// Cutoff timer. Owned.    
       
   288 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   289 
       
   290 
       
   291 	CHWRMPowerService*    			iPowerService;  				// Power service used to stop measurements 
       
   292 																	// or setting the plugin interval
       
   293     };
       
   294    
       
   295 /** IDs used to distinguish bewtween the two timers that the CommonData own */
       
   296 enum TClientsIds
       
   297 	{
       
   298 	EPowerReportClientsId = 0
       
   299 	
       
   300 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   301     ,EChargingCurrentClientsId,
       
   302 	EChargingTimeClientsId
       
   303 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   304     
       
   305 	};
       
   306 
       
   307 /** Item of the list that class CClientsData holds. One exists for each client
       
   308  * that registers for measurements. Holds a pointer to the TPowerMeasurementsClientData
       
   309  * that are owned by the HWRMPowerService of each client.   
       
   310  */
       
   311 class TClientData
       
   312 	{
       
   313 public:
       
   314 	TClientData(TPowerMeasurementsClientData& aPowerMeasurementsClientData);
       
   315 public:
       
   316 	TPowerMeasurementsClientData& 	iPowerMeasurementsClientData; 
       
   317 	TSglQueLink						iSglQueLink;
       
   318 	};
       
   319 
       
   320 /**
       
   321  * Contains all the clients that have registered for a type of measurements reporting.
       
   322  * Handles indications for this type of measurements and informs every registered
       
   323  * client for the event. Also holds the Max Period timer.
       
   324  * 
       
   325  * One instance of this class exists for Voltage and one for Consumption measurements.
       
   326  * It is a central point where the measurements are indicated and then dispatched 
       
   327  * to each of the clients.
       
   328  * 
       
   329  * It is populated during the reporting session and reset after the end of the session
       
   330  * either because the last client called stop, or because the maximum reporting 
       
   331  * period was reached. 
       
   332  * 
       
   333  * When the last client calls stop CLientsData will stop the plugin.
       
   334  * 
       
   335  * When multiple clients registered the Greatest Common Devisor of the 
       
   336  * Requested Time Intervals is calculated and used by the plugin. 
       
   337  * All the calculations are carried by this class.
       
   338  * 
       
   339  * When the Max period is reached all the clients are completed, reset and the 
       
   340  * plugin is stopped.
       
   341  *
       
   342  */
       
   343 class CClientsData : public CBase					 
       
   344 	{
       
   345 public:
       
   346 	static CClientsData* NewL(CHWRMGenericTimer& aMeasurementsTimer);
       
   347 	
       
   348 	virtual ~CClientsData();
       
   349 		
       
   350 public:
       
   351 	/**
       
   352     * Called when a measurement indication is received from the plugin.
       
   353     * 
       
   354     * @param aValue value of the indicated measurement
       
   355     */
       
   356 	void BatteryMeasurementIndicationL(TDesC8& aValue);
       
   357 
       
   358 	/**
       
   359     * Getter for the active interval multiple.
       
   360     * 
       
   361     * @param aIntervalMultiple holds the returned value
       
   362     */
       
   363     void GetPluginIntervalMultiple(TUint &aIntervalMultiple);
       
   364     
       
   365     /**
       
   366     * Setter for the plugin's voltage time interval.
       
   367     * 
       
   368     * @param aIntervalMultiple value that the plugin's voltage time interval is set to
       
   369     */
       
   370     void UpdatePluginIntervalMultiple(TUint aIntervalMultiple);
       
   371 
       
   372     /**
       
   373     * Checks if the plugin measurements are On.
       
   374     */        
       
   375     TBool IsMeasuringOn();
       
   376     
       
   377     /**
       
   378     * Sets the plugin measurements flag On.
       
   379     */        
       
   380     void SetMeasuringOn();
       
   381     
       
   382     /**
       
   383     * Sets the plugin measurements flag On.
       
   384     */        
       
   385     void SetMeasuringOff();
       
   386      
       
   387     /**
       
   388 	* Cheks if the Clients Queue is empty
       
   389 	*/       
       
   390     TBool IsClientsQueEmpty();
       
   391      
       
   392     /**
       
   393     * Creates and adds to the list a data structure 
       
   394     * containing all the appropriate client data.
       
   395     * 
       
   396     * @param aPowerMeasurementsClientData pointer to the data to be added
       
   397     */        
       
   398     void AddMeasurementsClientL(TPowerMeasurementsClientData& aPowerMeasurementsClientData);
       
   399    
       
   400      
       
   401     /**
       
   402     * Deletes all the data relevant to the client that sent the message.
       
   403     * 
       
   404     * @param aPowerMeasurementsClientData pointer to the data that will be removed and deleted
       
   405     * 
       
   406     */       
       
   407     void RemoveMeasurementsClientData(TPowerMeasurementsClientData* aPowerMeasurementsClientData);
       
   408     
       
   409     /**
       
   410     * Deletes all the data relevant to the client that sent the message.
       
   411     * 
       
   412     * @param aPowerMeasurementsClientData pointer to the data that will be removed and deleted
       
   413     * 
       
   414     * @leave KErrNotFound Client not found in the list.
       
   415     */       
       
   416     void RemoveMeasurementsClientL(TPowerMeasurementsClientData* aPowerMeasurementsClientData);
       
   417 
       
   418     /**
       
   419 	* Adjusts the interval used by the plugin when a new client registers
       
   420 	* with a time interval that causes a change of the GCD.
       
   421 	* 
       
   422 	*  @param aIntervalMultiple Tthe new value of the GCD
       
   423 	*/       
       
   424     void RecalculatePluginInterval(TUint &aIntervalMultiple);
       
   425           	
       
   426     /**
       
   427 	* Checks if a adjustement is needed for the 
       
   428 	* interval used by the plugin
       
   429 	* 
       
   430 	* @param aIntervalMultiple The interval of the incoming client.
       
   431 	*/       
       
   432     TBool NeedPluginIntervalAdjustment(TUint aIntervalMultiple);
       
   433     
       
   434     /**
       
   435 	* Deletes all the measurements related data
       
   436 	* Used at destruction time.
       
   437 	*/	    
       
   438     void CleanUpMeasurementsData();
       
   439      
       
   440 	/**
       
   441 	* Calculation of the Greatest Common Divisor of two numbers.
       
   442 	*/
       
   443 	TUint CalculateGCD(TUint num1, TUint num2);
       
   444 
       
   445 	/**
       
   446 	* Called when the Max Reporting Period is reached. 
       
   447 	* 
       
   448 	*/	
       
   449 	void MaxReportingPeriodReached(TInt aReason=KErrTimedOut);
       
   450 
       
   451 private:
       
   452 	/*
       
   453 	* Deletes all the items of the queue and empties it.
       
   454 	*/  
       
   455 	void EmptyClientsQue();
       
   456 
       
   457 	/**
       
   458 	* The Measurements collected so far are written in the
       
   459 	* message area of the data
       
   460 	*/		
       
   461 	void WriteMeasurementsInMessageL(TClientData* aClientData, TUint aCount);
       
   462 	
       
   463 	/**
       
   464 	* Returns the ClientData that correspond to the aPowerMeasurementsClientData. 
       
   465 	* Each session has a TPowerMeasurementsClientData object. Hence each client is
       
   466 	* uniqely identified by this object.
       
   467 	* 
       
   468 	* @return Pointer to the TClientData of the client that holds the aPowerMeasurementsClientData. NULL if client is not found
       
   469 	*/		
       
   470 	TClientData* FindClient(TPowerMeasurementsClientData* aPowerMeasurementsClientData);
       
   471 	
       
   472 private:
       
   473     /**
       
   474     * C++ default constructor.
       
   475     */
       
   476 	CClientsData(CHWRMGenericTimer& aMeasurementsTimer);
       
   477 
       
   478     /**
       
   479     * By default Symbian 2nd phase constructor is private.
       
   480     *
       
   481     * @param aPluginHandler Pointer to plugin handler for Power
       
   482     */
       
   483     void ConstructL();        
       
   484 
       
   485 private:
       
   486 	TBool 								iMeasuring;						// Indicates if the plugin measurements are On or Off
       
   487     //Changing to TUint as Charge current report needs it. Also other measurements to be changed in future.    
       
   488     TUint                               iPluginIntervalMultiple;        // the Interval Multiple that is currently in use by the plugin
       
   489 	CHWRMGenericTimer&					iMeasurementsTimer;  			// Cutoff timer. Used to set and cancel the Max Period Timer
       
   490    
       
   491 	TSglQue<TClientData> 				iClientsQue;					// list of the registered clients
       
   492 	TSglQueIter<TClientData> 			iClientsQueIter;				// iterator of the list  
       
   493  };
       
   494 
       
   495 #endif  // HWRMPOWERCOMMONDATA_H
       
   496             
       
   497 // End of File