resourcemgmt/hwresourcesmgr/server/inc/HWRMLightService.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 HWRMLIGHTSERVICE_H
       
    27 #define HWRMLIGHTSERVICE_H
       
    28 
       
    29 //  INCLUDES
       
    30 #include <e32base.h>
       
    31 #include "HWRMGenericTimer.h"
       
    32 #include "HWRMLightCommands.h"
       
    33 #include "HWRMLight.h"
       
    34 #include "HWRMService.h"
       
    35 #include "HWRMLightCommonData.h"
       
    36 #include "HWRMLightClientServer.h" // for KHWRMLightMaxTargets
       
    37 
       
    38 // CONSTANTS
       
    39 // None
       
    40 
       
    41 // MACROS
       
    42 // None
       
    43 
       
    44 // DATA TYPES
       
    45 
       
    46 /**
       
    47 * Set of datas that store single target state 
       
    48 */
       
    49 struct THWRHLightTargetStateData
       
    50     {
       
    51     CHWRMLight::TLightStatus iState;  // Light state
       
    52     TInt iIntensity;                  // Light intensity 
       
    53     TInt iOnCycleDuration;            // On cycle duration (if base state is blink), ms
       
    54     TInt iOffCycleDuration;           // Off cycle duration (if base state is blink), ms.
       
    55     TBool iFade;                      // Fade in or out. (not used for blink state).
       
    56     TUint iColor;                     // R G B values.
       
    57     };
       
    58 
       
    59 /**
       
    60 * Data struct for light target specific data
       
    61 */
       
    62 struct THWRMLightTargetData 
       
    63     {
       
    64     TInt               iTarget;    // The identifier of target this data refers to.
       
    65     CHWRMGenericTimer* iTimer;     // Timer pointer for duration based calls. Not owned.
       
    66     TBool              iSuspended; // Flag to indicate if this target is suspended.
       
    67     TBool              iReserved;  // Flag to indicate if this target is reserved.
       
    68     TInt               iFrozenTime; // Remaining light timer duration at last release.    T
       
    69 
       
    70     THWRHLightTargetStateData iBaseState;   // Stores light base state
       
    71     THWRHLightTargetStateData iLastState;   // Stores last desired light state
       
    72     THWRHLightTargetStateData iFrozenState; // Stores freeze state for light
       
    73     };
       
    74 
       
    75 
       
    76 // FUNCTION PROTOTYPES
       
    77 // None
       
    78 
       
    79 // FORWARD DECLARATIONS
       
    80 class CHWRMLightCommonData;
       
    81 class CHWRMPluginHandler;
       
    82 class CHWRMReservationHandler;
       
    83 
       
    84 // CLASS DECLARATION
       
    85 
       
    86 /**
       
    87 * Data storage class for light plugin requests.
       
    88 */
       
    89 class THWRMLightPluginRequestData : public THWRMPluginRequestData
       
    90     {
       
    91     public:
       
    92         TInt iTarget; // Target of the request
       
    93 
       
    94         /**
       
    95 	    * Convenience constructor
       
    96 	    */
       
    97 	    THWRMLightPluginRequestData(TInt aTarget,
       
    98 	                                const RMessage2& aRequestMessage,
       
    99 	                                TUint8 aTransId, 
       
   100 	                                TInt   aCommandId,
       
   101 	                                TBool  aSplitCommand,
       
   102 	                                TInt   aSplitCommandId,
       
   103 	                                TAny*  aSplitCommandData)
       
   104 	        : THWRMPluginRequestData(aRequestMessage, aTransId, aCommandId, aSplitCommand, aSplitCommandId, aSplitCommandData),
       
   105 	          iTarget(aTarget)
       
   106 	            {
       
   107 	            };
       
   108 	    /**
       
   109 	    * Virtual destructor.
       
   110 	    */
       
   111 	    virtual ~THWRMLightPluginRequestData()
       
   112 	        {
       
   113 	        };
       
   114     };
       
   115 
       
   116 /**
       
   117 *  Hardware Resource Manager server side service object for Light sessions.
       
   118 *
       
   119 */
       
   120 class CHWRMLightService : public CHWRMService,
       
   121                           public MHWRMGenericTimerCallback
       
   122     {
       
   123     private:  // Enumerations
       
   124     
       
   125         /**
       
   126         * Private enumeration to identify state change type
       
   127         */
       
   128         enum TStateChangeType
       
   129             {
       
   130             EStateChangeFrozenState = 0,
       
   131             EStateChangeBaseState,
       
   132             EStateChangeLastState,
       
   133             EStateChangeDefaultState
       
   134             };
       
   135 
       
   136     public: // Constructors and Destructor
       
   137     
       
   138         /**
       
   139         * Two-phased constructor.
       
   140         *
       
   141         * @param aPluginHandler The plugin handler to use with this service.
       
   142         */
       
   143         static CHWRMLightService* NewL(CHWRMPluginHandler* aPluginHandler,
       
   144                                        CHWRMReservationHandler* aReservationHandler,
       
   145                                        CHWRMLightCommonData& aLightCommonData);
       
   146         
       
   147         /**
       
   148         * Destructor.
       
   149         */
       
   150         virtual ~CHWRMLightService();
       
   151         
       
   152     public: // Base class methods
       
   153     	
       
   154     	virtual TBool ExecuteMessageL( const RMessage2& aMessage );
       
   155     	virtual void ProcessResponseL( TInt aCommandId, TUint8 aTransId, TDesC8& aData, TBool aTimeout );
       
   156     	virtual void SuspendSubResource(TInt aSubResource);
       
   157     	virtual void ResumeSubResource(TInt aSubResource);
       
   158         virtual void ActivateSubResource(TInt aSubResource, TBool aActivate);    	    	    
       
   159         
       
   160     	// From MHWRMGenericTimerCallback    	
       
   161     	virtual void GenericTimerFired(TInt aTimerId, TBool aCutOff);
       
   162     	
       
   163     public: // Other methods
       
   164     
       
   165         /**
       
   166         * Updates default sensor sensitivity to plugin
       
   167         *
       
   168         * @param aSensitivity New default sensitivity value.
       
   169         */
       
   170         void UpdateDefaultSensitivityL(TInt aSensitivity);
       
   171 
       
   172         /**
       
   173         * Updates default intensity to plugin
       
   174         *
       
   175     	* @param aTarget The light target mask
       
   176         * @param aIntensity New default intensity value for specified targets.
       
   177         */
       
   178         void UpdateDefaultIntensityL(TInt aTarget, TInt aIntensity);
       
   179         
       
   180         /**
       
   181         * Turns all unreserved system lights on.
       
   182         */
       
   183         void SystemLightsOn();
       
   184 
       
   185     private: 
       
   186     
       
   187         /**
       
   188         * C++ default constructor.
       
   189         */
       
   190         CHWRMLightService(CHWRMLightCommonData& aLightCommonData);
       
   191 
       
   192         /**
       
   193         * By default Symbian 2nd phase constructor is private.
       
   194         */
       
   195         void ConstructL(CHWRMPluginHandler* aPluginHandler,
       
   196                         CHWRMReservationHandler* aReservationHandler);
       
   197         
       
   198     	/**
       
   199     	* Turns lights on.
       
   200     	*
       
   201     	* @param aTarget The light target
       
   202     	* @param aDuration  Duration of timer, ms
       
   203     	* @param aIntensity Intensity
       
   204     	* @param aFadeIn fade-in
       
   205     	* @param aMessage Related message
       
   206     	* @param aTimerInitiated If ETrue, call is initiated by a timer.
       
   207     	* @param aActivationInitiated If ETrue, call is initiated by activation of target.
       
   208     	*/
       
   209 	    void LightsOnL(TInt aTarget,
       
   210 	                   TInt aDuration, 
       
   211 	                   TInt aIntensity,
       
   212 	                   TBool aFadeIn,
       
   213 	                   const RMessage2& aMessage,
       
   214 	                   TBool aTimerInitiated = EFalse,
       
   215 	                   TBool aActivationInitiated = EFalse);
       
   216   	
       
   217     	/**
       
   218     	* Turns lights off.
       
   219     	*
       
   220     	* @param aTarget The light target
       
   221     	* @param aDuration  Duration of timer, ms
       
   222     	* @param aFadeOut fade-out
       
   223     	* @param aMessage Related message
       
   224     	* @param aTimerInitiated If ETrue, call is initiated by a timer.
       
   225     	* @param aActivationInitiated If ETrue, call is initiated by activation of target.
       
   226     	*/
       
   227 	    void LightsOffL(TInt aTarget,
       
   228 	                    TInt aDuration, 
       
   229 	                    TBool aFadeOut,
       
   230 	                    const RMessage2& aMessage,
       
   231 	                    TBool aTimerInitiated = EFalse,
       
   232 	                    TBool aActivationInitiated = EFalse);
       
   233   	
       
   234     	/**
       
   235     	* Starts lights blinking
       
   236     	*
       
   237     	* @param aTarget The light target
       
   238     	* @param aDuration  Duration of timer, ms
       
   239     	* @param aIntensity Intensity
       
   240     	* @param aOnCycleTime On cycle time, ms
       
   241     	* @param aOffCycleTime Off cycle time, ms 
       
   242     	* @param aMessage Related message
       
   243     	* @param aTimerInitiated If ETrue, call is initiated by a timer.
       
   244     	* @param aActivationInitiated If ETrue, call is initiated by activation of target.
       
   245     	*/
       
   246 	    void LightsBlinkL(TInt aTarget,
       
   247 	                      TInt aDuration, 
       
   248 	                      TInt aIntensity,
       
   249 	                      TInt aOnCycleTime,
       
   250 	                      TInt aOffCycleTime,
       
   251 	                      const RMessage2& aMessage,
       
   252 	                      TBool aTimerInitiated = EFalse,
       
   253 	                      TBool aActivationInitiated = EFalse);
       
   254     	
       
   255     	/**
       
   256     	* Restores base state of the target light.
       
   257     	*
       
   258     	* @param aTargetData Reference to target data. 
       
   259     	*         If restoring default state, this is ignored,
       
   260     	*         but still cannot be NULL reference.
       
   261     	* @param aStateType Determines which type of state is restored
       
   262     	* @param aTimerInitiated If ETrue, call is initiated by a timer.
       
   263     	* @param aDefaultTargetMask Target mask used in restoring 
       
   264     	*         default state. Ignored in other restores.
       
   265     	* @param aMessage A pointer to message to use in transaction. If NULL,
       
   266     	*         a dummy message is used.
       
   267     	* @param aActivationInitiated If ETrue, call is initiated by activation of target.
       
   268     	*/
       
   269     	void RestoreState(const THWRMLightTargetData& aTargetData, 
       
   270     	                  TStateChangeType aStateType,
       
   271     	                  TBool aTimerInitiated = EFalse,
       
   272     	                  TInt aDefaultTargetMask = 0,
       
   273     	                  const RMessage2* aMessage = NULL,
       
   274 	                      TBool aActivationInitiated = EFalse );
       
   275     	
       
   276 
       
   277     	/**
       
   278     	* Stores base states of target data objects as necessary.
       
   279     	* Also sets or cancels relevant timers.
       
   280     	*
       
   281     	* @param aTimerInitiated If ETrue, original call was timer initiated.
       
   282     	* @param aDuration Duration of the call.
       
   283     	* @param aTarget A light target. If target is mask, multiple 
       
   284     	*        timers can be started.
       
   285     	* @param aState The light state to be set
       
   286     	* @param aIntensity Intensity of initiating call
       
   287     	* @param aFade fade-in or fade-out of initiating call
       
   288     	* @param aOnCycleTime On cycle time of the initiating call
       
   289     	* @param aOffCycleTime Off cycle time of the initiating call
       
   290     	*/
       
   291     	void UpdateTimersAndStoreStates(TBool aTimerInitiated,
       
   292     	                TInt aDuration,
       
   293     	                TInt aTarget,
       
   294                         CHWRMLight::TLightStatus aState,
       
   295 	                    TInt aIntensity,
       
   296 	                    TBool aFade,
       
   297                         TInt aOnCycleTime,
       
   298                         TInt aOffCycleTime);
       
   299 
       
   300     	/**
       
   301     	* Checks the validity of common API call parameters.
       
   302     	* Also checks the session handle.
       
   303     	*
       
   304     	* @param aTarget    aTarget parameter of API call
       
   305     	* @param aDuration  aDuration parameter of API call
       
   306     	* @param aIntensity aIntensity parameter of API call
       
   307     	* @leave KErrArgument   If parameters not valid
       
   308     	* @leave KErrBadHandle  If plugin handler reference is invalid. 
       
   309     	*/
       
   310     	void CheckCommonParametersL(TInt aTarget, 
       
   311     	                            TInt aDuration, 
       
   312     	                            TInt aIntensity) const;
       
   313         
       
   314     	/**
       
   315     	* Checks the validity of duration type API call parameters
       
   316     	*
       
   317     	* @param aDuration  aDuration parameter of API call
       
   318     	* @leave KErrArgument   If parameters not valid
       
   319     	*/
       
   320     	void CheckDurationParameterL(TInt aDuration) const;
       
   321     	
       
   322     	/**
       
   323     	* Checks the validity of target type API call parameters.
       
   324     	*
       
   325     	* @param aTarget  aTarget parameter of API call
       
   326     	*/
       
   327     	void CheckTargetParameterL(TInt aTarget) const;
       
   328     	
       
   329     	/**
       
   330     	* Gets mask of unsuspended targets and checks their
       
   331     	* reservation status.
       
   332     	*
       
   333     	* @param aTarget Targets to be checked.
       
   334     	* @return Mask of unsuspended targets.
       
   335     	* @leave KErrInUse if any of unsuspended targets is 
       
   336     	*             reserved to some other service
       
   337     	*/
       
   338     	TInt GetAndCheckUnsuspendedTargetsL(TInt aTarget) const;
       
   339     	
       
   340     	/**
       
   341     	* Executes a plugin command
       
   342         *
       
   343         * @param aTarget Targets of the plugin command
       
   344         * @param aMessage Message related to this command.
       
   345         * @param aCommandId Command ID of the command.	
       
   346         * @param aPckg Command package
       
   347         * @param aSplitCommand Indicates if this execution is part of split command.
       
   348     	*/
       
   349         void ExecutePluginCommandL(TInt aTarget,
       
   350                                   const RMessage2& aMessage,
       
   351                                   TInt aCommandId,
       
   352                                   TDesC8& aPckg,
       
   353                                   TBool aSplitCommand,
       
   354                                   TInt aSplitCommandId = 0, 
       
   355                                   TAny* aSplitCommandData = NULL  );
       
   356         
       
   357         /**
       
   358         * Returns suitable modified target mask for general case
       
   359         *
       
   360         * @param aTarget Original target
       
   361         * @param aLightsOff ETrue if mask is needed for lights off command
       
   362         * @return Modified target mask
       
   363         * @leave KErrNotSupported if target is not supported at this time.
       
   364         */
       
   365         TInt ModifyTargetMaskL(TInt aTarget, TBool aLightsOff);
       
   366         
       
   367         /**
       
   368         * Cleans up light service.
       
   369         * Attempts to restore lights to proper states.
       
   370         */
       
   371         void CleanupLights();
       
   372 
       
   373         /**
       
   374         * Releases lights.
       
   375         * Called by ExecuteMessageL.
       
   376         */
       
   377         void ReleaseLights(TInt aTargetMask);
       
   378         
       
   379         /**
       
   380         * Reserves lights.
       
   381         * Called by ExecuteMessageL.
       
   382         *
       
   383         * @param aTargetMask
       
   384         * @param aMessage Message pointer for identifying the reserving client
       
   385         * @param aForceNoCCoeEnv Indicates if reservation is done in force CCoeEnv mode.
       
   386         */
       
   387         void ReserveLightsL(const RMessage2& aMessage);
       
   388 
       
   389         /**
       
   390         * Turns lights on.
       
   391         *
       
   392         * @param aTarget The light target
       
   393         * @param aColor  color data
       
   394         *
       
   395         */
       
   396         TBool SetColorL(TInt aTarget, TUint aColor, const RMessage2& aMessage, TBool aActivationInitiated = EFalse,
       
   397                        TBool aSplitCommand = EFalse, TInt aSplitCommandId = 0, TAny* aSplitCommandData = NULL);
       
   398 
       
   399 
       
   400     private:  // data
       
   401 
       
   402         CHWRMLightCommonData&     iLightCommonData; // Pointer to light data object common to all sessions. Not owned.                 
       
   403         THWRMLightTargetData      iTargets[KHWRMLightMaxTargets]; // Target specific datas. Owned. Each data refers to target
       
   404                                                              // value (KHWRMLightFirstTarget << <index>) in CHWRMLight::TLightTarget. 
       
   405         THWRHLightTargetStateData iDefaultState;             // Default state of lights when no reservations are active                                                            
       
   406         TInt                      iSupportedTargets;         // Supported targets mask
       
   407         TInt                      iFullSystemTarget;         // Full system target
       
   408         TBool                     iCleaningUp;               // Indicates that cleanup has started. No new commands are handled.
       
   409         
       
   410     public: // friends
       
   411     
       
   412         friend class CHWRMLightTargetHandler;
       
   413     };
       
   414 
       
   415 #endif  // HWRMLIGHTSERVICE_H
       
   416             
       
   417 // End of File