resourcemgmt/hwresourcesmgr/vibra/src/HWRMVibraImpl.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2005-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 <e32svr.h>
       
    20 #include <centralrepository.h>
       
    21 #include "HWRMVibraImpl.h"
       
    22 #include "HWRMVibraClientServer.h"
       
    23 #include "HWRMtrace.h"
       
    24 #include "HWRMVibraSDKCRKeys.h"
       
    25 #include "HWRMVibraStatusObserver.h"
       
    26 #include "HWRMPrivateCRKeys.h"
       
    27 #include "hwrmuipluginhandler.h"
       
    28 
       
    29 
       
    30 // EXTERNAL DATA STRUCTURES
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES  
       
    33 
       
    34 // CONSTANTS
       
    35 
       
    36 // MACROS
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 
       
    40 // MODULE DATA STRUCTURES
       
    41 
       
    42 // LOCAL FUNCTION PROTOTYPES
       
    43 
       
    44 // FORWARD DECLARATIONS
       
    45 
       
    46 // ============================= LOCAL FUNCTIONS ===============================
       
    47 
       
    48 // ============================ MEMBER FUNCTIONS ===============================
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CHWRMVibraImpl::CHWRMVibraImpl
       
    52 // C++ constructor
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CHWRMVibraImpl::CHWRMVibraImpl()
       
    56     {
       
    57     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::CHWRMVibraImpl()"));
       
    58     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::CHWRMVibraImpl - return" ));
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CHWRMVibraImpl::ConstructL
       
    63 // Symbian 2nd phase constructor can leave.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CHWRMVibraImpl::ConstructL(MHWRMVibraObserver* aCallback)
       
    67     {
       
    68     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::ConstructL()" ));
       
    69     
       
    70     // NULL is acceptable value for aCallback, just means that 
       
    71     // client is not interested in callbacks.
       
    72     iCallback = aCallback;    
       
    73     iFeedbackCallback = NULL;
       
    74 
       
    75     // To get access to cenrep
       
    76     iProfileObserver = CHWRMVibraProfileObserver::NewL(this);
       
    77 
       
    78     // Get privileged SID and compare to this process SID
       
    79     CRepository* hwrmRep = CRepository::NewLC(KCRUidHWRMSettings);
       
    80     TInt sidInt(0);
       
    81     User::LeaveIfError(hwrmRep->Get(KHWRMAudioVibraSID, sidInt));
       
    82     TSecureId sid(sidInt);
       
    83     RProcess thisProcess;
       
    84     COMPONENT_TRACE3(_L( "HWRM VibraClient - CHWRMVibraImpl::ConstructL - Client SID: 0x%x, Privileged SID: 0x%x" ), thisProcess.SecureId().iId, sidInt );    
       
    85     if ( thisProcess.SecureId() == sid )
       
    86         {
       
    87         COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::ConstructL - Client is privileged" ) );    
       
    88         iPrivilegedClient = ETrue;
       
    89         }
       
    90     else
       
    91         {
       
    92         COMPONENT_TRACE1( _L( "HWRM VibraClient - CHWRMVibraImpl::ConstructL - Client is not privileged" ) );    
       
    93         iPrivilegedClient = EFalse;
       
    94         }
       
    95     CleanupStack::PopAndDestroy(hwrmRep);
       
    96     thisProcess.Close();
       
    97     
       
    98     // Connect the session and order notifications
       
    99     OpenL();
       
   100     
       
   101     TInt err(KErrNone);    
       
   102    	TRAP(err, iUiPluginHandler = CHwrmUiPluginHandler::NewL( ));
       
   103    	if ( err != KErrNone )
       
   104     	{    	
       
   105     	COMPONENT_TRACE2(_L( "HWRM ExtendedLightClient - CHWRMExtendedLightImpl::Open() - No Cone Plugin Handler" ), err );
       
   106     	iUiPluginHandler = NULL;
       
   107     	}
       
   108     if(iUiPluginHandler)
       
   109     	{
       
   110     	iUiPluginHandler->AddForegroundObserverL(this);    	
       
   111     	}
       
   112     
       
   113     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::ConstructL - return" ) );    
       
   114     }
       
   115 
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CHWRMVibra::SetFeedbackObserver
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void CHWRMVibraImpl::SetFeedbackObserver(MHWRMVibraFeedbackObserver* aCallback)
       
   122     {
       
   123     iFeedbackCallback = aCallback;
       
   124     iFeedbackCallback->VibraFeedbackModeChanged(iVibraFeedbackSetting);
       
   125     }
       
   126     
       
   127 
       
   128 // ---------------------------------------------------------
       
   129 // Destructor
       
   130 // ---------------------------------------------------------
       
   131 //
       
   132 CHWRMVibraImpl::~CHWRMVibraImpl()
       
   133     {
       
   134     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::~CHWRMVibraImpl()" ));
       
   135     
       
   136 
       
   137     // close HWRM client, also deletes status observer
       
   138     Close();
       
   139 
       
   140     delete iProfileObserver;    
       
   141         
       
   142     // iCallback is not owned so it is not cleaned
       
   143     iCallback = NULL;
       
   144     
       
   145     // iStatusObserver is deleted in close, NULL it here so pc-lint doesn't complain
       
   146     iStatusObserver = NULL;
       
   147     
       
   148     delete iUiPluginHandler;
       
   149 
       
   150     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::~CHWRMVibraImpl - return" ) );
       
   151     }
       
   152 
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CHWRMVibraImpl::OpenL
       
   156 // Opens session and orders notifications
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 void CHWRMVibraImpl::OpenL()
       
   160     {
       
   161     COMPONENT_TRACE1( _L( "HWRM VibraClient - CHWRMVibraImpl::Open()" ));
       
   162     
       
   163     User::LeaveIfError(iClient.Connect(HWRMResourceTypeVibra));
       
   164     
       
   165     // Order status notifications
       
   166     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::Open - Ordering notifications" ));
       
   167     iStatusObserver = CHWRMVibraStatusObserver::NewL(iCallback);            
       
   168     	
       
   169     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::Open - return" ));
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CHWRMVibraImpl::Close
       
   174 // Closes session.
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CHWRMVibraImpl::Close()
       
   178     {
       
   179     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::Close()" ));
       
   180         
       
   181     // Inform session that we are cleaning up now.
       
   182     // Ignore errors, just trace them
       
   183     if (iClient.Handle())
       
   184         {
       
   185         iClient.ExecuteOperation(EHWRMCleanupVibra, TIpcArgs());
       
   186         }
       
   187     
       
   188     // Abort status notifications
       
   189     if ( iStatusObserver )
       
   190         {
       
   191         COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::Close - canceling status notifications" ));
       
   192         iStatusObserver->Cancel();
       
   193         delete iStatusObserver;
       
   194         iStatusObserver = NULL;
       
   195         }
       
   196                 
       
   197     iClient.Close();
       
   198     
       
   199     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::Close - return" ) );
       
   200     }
       
   201     
       
   202 // -----------------------------------------------------------------------------
       
   203 // CHWRMVibraImpl::ReserveVibra
       
   204 // Reserve vibra resource
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 void CHWRMVibraImpl::ReserveVibraL()
       
   208     {
       
   209     ReserveVibraL(EFalse, EFalse);
       
   210     }    
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CHWRMVibraImpl::ReserveVibra
       
   214 // Reserve vibra resource
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CHWRMVibraImpl::ReserveVibraL(TBool aRestoreState, TBool aForceNoCCoeEnv)
       
   218     {
       
   219     COMPONENT_TRACE3(_L( "HWRM VibraClient - CHWRMVibraImpl::ReserveVibraL(0x%x, 0x%x)" ), aRestoreState, aForceNoCCoeEnv);
       
   220     
       
   221     if ( !aForceNoCCoeEnv )
       
   222         {                      
       
   223  		if(iUiPluginHandler)
       
   224     		{
       
   225     		// Check that we are on foreground (i.e. we have keyboard focus.)
       
   226             // Note: There can be windows on top of our application that have explicitly disabled keyboard focus,
       
   227             // but then again the foreground/background observer will not kick in in those cases either.
       
   228             // -> We can use focus to determine foreground status here.            
       
   229     		if(iUiPluginHandler->InForeground() == EFalse)
       
   230 				{
       
   231     			COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::ReserveVibra - Application does not have focus, Reserve denied." ) );
       
   232                 User::Leave(KErrNotReady);                
       
   233     			}
       
   234     		} 		        	
       
   235         else
       
   236         	{
       
   237             COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::::ReserveLightL - No iUiPluginHandler available" ) );
       
   238             User::Leave(KErrBadHandle);        	
       
   239         	}       
       
   240         }
       
   241     
       
   242     // Do the actual reservation
       
   243     DoReserveVibraL(aRestoreState, aForceNoCCoeEnv);
       
   244     
       
   245     if ( !aForceNoCCoeEnv )
       
   246         {
       
   247         // set autoreserve flag
       
   248         iAutoReserving = ETrue;
       
   249         }
       
   250     
       
   251     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::ReserveVibraL - return" ) );
       
   252     }
       
   253     
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CHWRMVibraImpl::ReleaseVibra
       
   257 // Release vibra resource
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 void CHWRMVibraImpl::ReleaseVibra()
       
   261     {
       
   262     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::ReleaseVibra()" ) );
       
   263     
       
   264     DoReleaseVibra();
       
   265 
       
   266     iAutoReserving = EFalse;
       
   267     
       
   268     COMPONENT_TRACE1( _L( "HWRM VibraClient - CHWRMVibraImpl::ReleaseVibra - return" ) );
       
   269     }
       
   270 
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CHWRMVibraImpl::DoReserveVibraL
       
   274 // Reserve vibra resource
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 void CHWRMVibraImpl::DoReserveVibraL(TBool aRestoreState, TBool aForceNoCCoeEnv)
       
   278     {
       
   279     COMPONENT_TRACE3( _L( "HWRM VibraClient - CHWRMVibraImpl::DoReserveVibra(0x%x, 0x%x)" ), aRestoreState, aForceNoCCoeEnv);
       
   280     
       
   281     // Check if vibra is already reserved by this session. 
       
   282     // In that case do nothing.
       
   283     if ( iReserved )
       
   284         {
       
   285         return;
       
   286         }
       
   287 
       
   288     // Execute reservation
       
   289     User::LeaveIfError(iClient.ExecuteOperation(EHWRMReserveVibra, TIpcArgs(aRestoreState, aForceNoCCoeEnv)));
       
   290 
       
   291     // Reserve successful, mark as reserved.
       
   292     iReserved = ETrue;
       
   293        
       
   294     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::DoReserveVibra - return" ) );
       
   295     }
       
   296     
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CHWRMVibraImpl::DoReleaseVibra
       
   300 // Release vibra resource
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 void CHWRMVibraImpl::DoReleaseVibra()
       
   304     {
       
   305     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::DoReleaseVibra()" ) );
       
   306     
       
   307     // Only release if reserved.
       
   308     if ( iReserved )
       
   309         {
       
   310         // Execute release
       
   311         TInt err = iClient.ExecuteOperation(EHWRMReleaseVibra, TIpcArgs());
       
   312         
       
   313         if ( err != KErrNone )
       
   314             {
       
   315             COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraImpl::DoReleaseVibra - Release execution failed: %d" ), err);
       
   316             }
       
   317         // If an error is raised on the server side before or after
       
   318         // vibra is released, attention must be paid to what the "iReserved"
       
   319         // flag should be set to
       
   320         iReserved = EFalse;
       
   321         }
       
   322         
       
   323     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::DoReleaseVibra - return" ) );
       
   324     }
       
   325 
       
   326 //------------------------------------------------------------------------------
       
   327 // CHWRMVibraImpl::HandleGainingForeground     
       
   328 // Inherited From MCoeForegroundObserver - called when app comes to foreground
       
   329 //------------------------------------------------------------------------------
       
   330 //
       
   331 void CHWRMVibraImpl::HandleGainingForeground()
       
   332     {
       
   333     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::HandleGainingForeground()" ));
       
   334 
       
   335     // Reserve if vibra is autoreserving
       
   336     if ( iAutoReserving )
       
   337         {
       
   338         TRAPD(err, DoReserveVibraL(ETrue, EFalse));
       
   339         
       
   340         if ( err != KErrNone )
       
   341             {
       
   342             COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraImpl::HandleGainingForeground - Error reserving: %d " ), err );
       
   343             }
       
   344         }
       
   345 
       
   346     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::HandleGainingForeground - return " ) );
       
   347     }
       
   348 
       
   349 
       
   350 //------------------------------------------------------------------------------
       
   351 // CHWRMVibraImpl::HandleLosingForeground     
       
   352 // Inherited From MCoeForegroundObserver - called when app goes to background 
       
   353 //------------------------------------------------------------------------------
       
   354 void CHWRMVibraImpl::HandleLosingForeground()
       
   355     {
       
   356     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::HandleLosingForeground()" ) );
       
   357 
       
   358     if ( iAutoReserving )
       
   359         {
       
   360         DoReleaseVibra();
       
   361         }
       
   362 
       
   363     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::HandleLosingForeground - return " ) );
       
   364     }
       
   365 
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // CHWRMVibraImpl::StartVibraL
       
   369 // Start vibra with duration.
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 void CHWRMVibraImpl::StartVibraL(TInt aDuration)
       
   373     {
       
   374     COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraImpl::StartVibraL(0x%x)" ), aDuration);
       
   375 
       
   376     if ( !iClient.Handle() )
       
   377         {
       
   378         COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::StartVibraL - Invalid HWRM client." ) );    
       
   379         User::Leave(KErrBadHandle);
       
   380         }
       
   381 
       
   382     if ( (aDuration < 0) || (aDuration > KHWRMVibraMaxDuration) )
       
   383         {
       
   384         User::Leave(KErrArgument);
       
   385         }
       
   386 	
       
   387     // make sure that vibra settings gets updated.
       
   388     VibraSettings();
       
   389 
       
   390     // nothing happens if vibra is not on from settings.        
       
   391     if ( iVibraSetting == EVibraModeON || iPrivilegedClient )
       
   392         {
       
   393         // Call start vibra from server with default intensity    
       
   394         User::LeaveIfError(iClient.ExecuteOperation(EHWRMStartVibraDefaultIntensity, TIpcArgs(aDuration)));
       
   395         }
       
   396     else
       
   397         {
       
   398         COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::StartVibraL - Vibra not available." ) );    
       
   399         User::Leave(KErrAccessDenied);
       
   400         }
       
   401     
       
   402     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::StartVibraL - return" ) );
       
   403     }
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // CHWRMVibraImpl::StartVibraL
       
   407 // Start vibra with duration and intensity.
       
   408 // -----------------------------------------------------------------------------
       
   409 //
       
   410 
       
   411 void CHWRMVibraImpl::StartVibraL(TInt aDuration, TInt aIntensity)
       
   412     {
       
   413     COMPONENT_TRACE3(_L( "HWRM VibraClient - CHWRMVibraImpl::StartVibraL(0x%x, 0x%x)" ), aDuration, aIntensity);
       
   414         
       
   415     if ( !iClient.Handle() )
       
   416         {
       
   417         COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::StartVibraL - Invalid HWRM client." ) );    
       
   418         User::Leave(KErrBadHandle);
       
   419         }
       
   420 
       
   421     if ( aDuration < 0 || aDuration > KHWRMVibraMaxDuration )
       
   422         {
       
   423         User::Leave(KErrArgument);
       
   424         }
       
   425 
       
   426     // check that intensity is in valid range
       
   427     if(aIntensity < KHWRMVibraMinIntensity || aIntensity > KHWRMVibraMaxIntensity)
       
   428         {
       
   429         COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraImpl::StartVibraL - Invalid intensity argument: %d" ), aIntensity );    
       
   430         User::Leave(KErrArgument);
       
   431         }
       
   432 
       
   433     // make sure that vibra settings gets updated.
       
   434     VibraSettings();
       
   435 	
       
   436     // nothing happens if vibra is not on from settings.        
       
   437     if ( iVibraSetting == EVibraModeON || iPrivilegedClient )
       
   438         {
       
   439         // Call start vibra from server with specified intensity    
       
   440         User::LeaveIfError(iClient.ExecuteOperation(EHWRMStartVibra, TIpcArgs(aDuration, aIntensity)));
       
   441         }
       
   442     else
       
   443         {
       
   444         COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::StartVibraL - Vibra not available." ) );    
       
   445         User::Leave(KErrAccessDenied);
       
   446         }
       
   447     
       
   448     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::StartVibraL - return" ) );
       
   449     }
       
   450 
       
   451 // -----------------------------------------------------------------------------
       
   452 // CHWRMVibraImpl::StopVibraL
       
   453 // Stop vibra.
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 void CHWRMVibraImpl::StopVibraL()
       
   457     {
       
   458     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::StopVibraL()" ));
       
   459         
       
   460     if ( !iClient.Handle() )
       
   461         {
       
   462         COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::StartVibraL - Invalid HWRM client." ) );    
       
   463         User::Leave(KErrBadHandle);
       
   464         }
       
   465 
       
   466     // always try to stop vibra just in case, even if it is not available 
       
   467     User::LeaveIfError(iClient.ExecuteOperation(EHWRMStopVibra, TIpcArgs()));
       
   468     
       
   469     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::StopVibraL - return" ) );
       
   470     }
       
   471 
       
   472 // -----------------------------------------------------------------------------
       
   473 // CHWRMVibraImpl::VibraSettings
       
   474 // Return vibra mode profile setting state
       
   475 // -----------------------------------------------------------------------------
       
   476 //
       
   477 CHWRMVibra::TVibraModeState CHWRMVibraImpl::VibraSettings() const
       
   478     {
       
   479     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::VibraSettings()" ));
       
   480 
       
   481     // get the current state
       
   482 	iVibraSetting = iProfileObserver->GetVibraModeState();
       
   483                
       
   484     COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraImpl::VibraSettings - return 0x%x" ), iVibraSetting );
       
   485     
       
   486     return iVibraSetting;
       
   487     }
       
   488 
       
   489 // -----------------------------------------------------------------------------
       
   490 // CHWRMVibraImpl::VibraStatus
       
   491 // Return vibra status
       
   492 // -----------------------------------------------------------------------------
       
   493 //
       
   494 CHWRMVibra::TVibraStatus CHWRMVibraImpl::VibraStatus() const
       
   495     {
       
   496     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraImpl::VibraStatus()" ));
       
   497     
       
   498     CHWRMVibra::TVibraStatus status = CHWRMVibra::EVibraStatusUnknown;
       
   499     
       
   500     if ( iStatusObserver )
       
   501         {    
       
   502         status = iStatusObserver->CurrentStatus();
       
   503         }
       
   504                
       
   505     COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraImpl::VibraStatus - return 0x%x" ), status );
       
   506     
       
   507     return status;
       
   508     }
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // CHWRMVibraImpl::VibraModeChange
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 void CHWRMVibraImpl::VibraModeChange(CHWRMVibra::TVibraModeState aNewState)
       
   515     {
       
   516     COMPONENT_TRACE2(_L("HWRM VibraClient - CHWRMVibra::VibraModeChange(0x%x)"), aNewState); 
       
   517 
       
   518     iVibraSetting = aNewState;
       
   519 
       
   520     if ( iCallback )
       
   521         {
       
   522         iCallback->VibraModeChanged(iVibraSetting);
       
   523         }
       
   524 
       
   525     COMPONENT_TRACE1(_L("HWRM VibraClient - CHWRMVibra::VibraModeChange - return") ); 
       
   526     }
       
   527 // -----------------------------------------------------------------------------
       
   528 // CHWRMVibraImpl::PulseVibraL
       
   529 // Start vibra with default intensity and duration.
       
   530 // -----------------------------------------------------------------------------
       
   531 //
       
   532 void CHWRMVibraImpl::PulseVibraL()
       
   533     {
       
   534     COMPONENT_TRACE1( ( _L( "HWRM VibraClient - CHWRMVibraImpl::PulseVibraL" )) );
       
   535 
       
   536     if ( !iClient.Handle() )
       
   537         {
       
   538         COMPONENT_TRACE1( ( _L( "HWRM VibraClient - CHWRMVibraImpl::PulseVibraL - Invalid HWRM client." ) ) );    
       
   539         User::Leave(KErrBadHandle);
       
   540         }
       
   541 
       
   542 	// make sure vibra feedback state gets updated
       
   543 	VibraFeedbackSettings();
       
   544 	
       
   545     // nothing happens if vibra is not on from settings.        
       
   546     if ( iVibraFeedbackSetting == EVibraFeedbackModeON )
       
   547         {
       
   548         // Call start vibra from server with default intensity    
       
   549         User::LeaveIfError(iClient.ExecuteOperation(EHWRMPulseVibraDefault, TIpcArgs()));
       
   550         }
       
   551     else
       
   552         {
       
   553         COMPONENT_TRACE1( ( _L( "HWRM VibraClient - CHWRMVibraImpl::PulseVibraL - Feedback vibration not available." ) ) );    
       
   554         User::Leave(KErrAccessDenied);
       
   555         }
       
   556     
       
   557     COMPONENT_TRACE1( ( _L( "HWRM VibraClient - CHWRMVibraImpl::PulseVibraL - return" ) ) );
       
   558     }
       
   559 
       
   560 // -----------------------------------------------------------------------------
       
   561 // CHWRMVibraImpl::PulseVibraL
       
   562 // Start vibra with specified duration and default intensity.
       
   563 // -----------------------------------------------------------------------------
       
   564 //
       
   565 void CHWRMVibraImpl::PulseVibraL(TInt aDuration)
       
   566     {
       
   567     COMPONENT_TRACE2(_L("HWRM VibraClient - CHWRMVibraImpl::PulseVibraL(0x%x)" ), aDuration);
       
   568     
       
   569     if ( !iClient.Handle() )
       
   570         {
       
   571         COMPONENT_TRACE1( ( _L( "HWRM VibraClient - CHWRMVibraImpl::PulseVibraL - Invalid HWRM client." ) ) );    
       
   572         User::Leave(KErrBadHandle);
       
   573         }
       
   574 
       
   575     if ( aDuration < 0 || aDuration > KHWRMVibraMaxDuration )
       
   576         {
       
   577         User::Leave(KErrArgument);
       
   578         }
       
   579 
       
   580 	// make sure vibra feedback state gets updated
       
   581 	VibraFeedbackSettings();
       
   582 	
       
   583     // nothing happens if feedback vibra is not on from settings.        
       
   584     if ( iVibraFeedbackSetting == EVibraFeedbackModeON )
       
   585         {
       
   586         // Call start vibra from server with specified intensity    
       
   587         User::LeaveIfError(iClient.ExecuteOperation(EHWRMPulseVibraDefaultIntensity, TIpcArgs(aDuration)));
       
   588         }
       
   589     else
       
   590         {
       
   591         COMPONENT_TRACE1( ( _L( "HWRM VibraClient - CHWRMVibraImpl::PulseVibraL - Feedback vibration not available." ) ) );    
       
   592         User::Leave(KErrAccessDenied);
       
   593         }
       
   594     
       
   595     COMPONENT_TRACE1( ( _L( "HWRM VibraClient - CHWRMVibraImpl::PulseVibraL - return" ) ) );
       
   596     }
       
   597 
       
   598 // -----------------------------------------------------------------------------
       
   599 // CHWRMVibraImpl::PulseVibraL
       
   600 // Start vibra with specified duration and intensity.
       
   601 // -----------------------------------------------------------------------------
       
   602 //
       
   603 void CHWRMVibraImpl::PulseVibraL(TInt aDuration, TInt aIntensity)
       
   604     {
       
   605     COMPONENT_TRACE3(_L( "HWRM VibraClient - CHWRMVibraImpl::PulseVibraL(0x%x, 0x%x)" ), aDuration, aIntensity);
       
   606         
       
   607     if ( !iClient.Handle() )
       
   608         {
       
   609         COMPONENT_TRACE1( ( _L( "HWRM VibraClient - CHWRMVibraImpl::PulseVibraL - Invalid HWRM client." ) ) );    
       
   610         User::Leave(KErrBadHandle);
       
   611         }
       
   612 
       
   613     if ( aDuration < 0 || aDuration > KHWRMVibraMaxDuration )
       
   614         {
       
   615         User::Leave(KErrArgument);
       
   616         }
       
   617 
       
   618     // check that intensity is in valid range
       
   619     if(aIntensity < KHWRMVibraMinPulseIntensity || aIntensity > KHWRMVibraMaxIntensity)
       
   620         {
       
   621         COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraImpl::PulseVibraL - Invalid intensity argument: %d" ), aIntensity );    
       
   622         User::Leave(KErrArgument);
       
   623         }
       
   624 
       
   625 	// make sure vibra feedback state gets updated
       
   626 	VibraFeedbackSettings();
       
   627 	
       
   628     // nothing happens if vibra is not on from settings.        
       
   629     if ( iVibraFeedbackSetting == EVibraFeedbackModeON )
       
   630         {
       
   631         // Call start vibra from server with specified intensity    
       
   632         User::LeaveIfError(iClient.ExecuteOperation(EHWRMPulseVibra, TIpcArgs(aDuration, aIntensity)));
       
   633         }
       
   634     else
       
   635         {
       
   636         COMPONENT_TRACE1( ( _L( "HWRM VibraClient - CHWRMVibraImpl::PulseVibraL - Feedback vibration not available." ) ) );    
       
   637         User::Leave(KErrAccessDenied);
       
   638         }
       
   639             
       
   640     
       
   641     COMPONENT_TRACE1( ( _L( "HWRM VibraClient - CHWRMVibraImpl::PulseVibraL - return" ) ) );
       
   642     }
       
   643 
       
   644 // -----------------------------------------------------------------------------
       
   645 // CHWRMVibraImpl::VibraFeedbackSettings
       
   646 // Return feedback vibration mode profile setting state
       
   647 // -----------------------------------------------------------------------------
       
   648 //
       
   649 CHWRMVibra::TVibraFeedbackModeState CHWRMVibraImpl::VibraFeedbackSettings() const
       
   650     {
       
   651     COMPONENT_TRACE1( ( _L( "HWRM VibraClient - CHWRMVibraImpl::VibraFeedbackSettings()" )) );
       
   652 
       
   653     // get the current vibra feedback state
       
   654 	iVibraFeedbackSetting = iProfileObserver->GetVibraFeedbackModeState();
       
   655                
       
   656     COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraImpl::VibraFeedbackSettings - return 0x%x" ), iVibraFeedbackSetting );
       
   657     
       
   658     return iVibraFeedbackSetting;
       
   659     }
       
   660 
       
   661 // -----------------------------------------------------------------------------
       
   662 // CHWRMVibraImpl::VibraFeedbackModeChange
       
   663 // -----------------------------------------------------------------------------
       
   664 //
       
   665 void CHWRMVibraImpl::VibraFeedbackModeChange(CHWRMVibra::TVibraFeedbackModeState  aNewState)
       
   666     {
       
   667     COMPONENT_TRACE2(_L("HWRM VibraClient - CHWRMVibra::VibraFeedbackModeChange(0x%x)"), aNewState); 
       
   668 
       
   669     iVibraFeedbackSetting = aNewState;
       
   670 
       
   671     if ( iFeedbackCallback )
       
   672         {
       
   673         iFeedbackCallback->VibraFeedbackModeChanged(iVibraFeedbackSetting);
       
   674         }
       
   675 
       
   676     COMPONENT_TRACE1(_L("HWRM VibraClient - CHWRMVibra::VibraFeedbackModeChange - return") ); 
       
   677     }
       
   678 
       
   679 
       
   680 
       
   681 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   682 
       
   683 //  End of File