resourcemgmt/vibractrl/src/vibractrlwrapperimpl.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2003 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:  Vibra control API implementation that uses HWRM vibra API
       
    15 *                instead of DOS.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "vibractrlwrapperimpl.h"
       
    22 
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ===============================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CVibraControlImpl::CVibraControlImpl
       
    28 // Constructor with notify handling.
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CVibraControlImpl::CVibraControlImpl(MVibraControlObserver* aCallback)
       
    32     :iCallback(aCallback),
       
    33     iVibra(NULL)
       
    34     {
       
    35     //...
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CVibraControlImpl::~CVibraControlImpl
       
    40 // Destructor
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CVibraControlImpl::~CVibraControlImpl()
       
    44     {
       
    45     delete iVibra;
       
    46     iVibra = NULL;
       
    47     
       
    48     // PCLint demands
       
    49     iCallback = NULL;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CVibraControlImpl::ConstructL
       
    54 // Symbian 2nd phase constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CVibraControlImpl::ConstructL()
       
    58     {
       
    59     // Ignore status change notifications caused by initialization
       
    60     // to make functionality similar to old vibra.
       
    61     iVibraRouteEvents = EFalse;
       
    62 
       
    63     // To get access vibra thru DOS
       
    64     iVibra = CHWRMVibra::NewL(this);
       
    65     
       
    66     iVibraRouteEvents = ETrue;
       
    67     }
       
    68 
       
    69     
       
    70 // -----------------------------------------------------------------------------
       
    71 // CVibraControlImpl::HandleErrorL
       
    72 // Handles error from HWRM Vibra API
       
    73 // -----------------------------------------------------------------------------
       
    74 void CVibraControlImpl::HandleErrorL(TInt aError)
       
    75     {
       
    76     if ( aError != KErrNone )
       
    77         {
       
    78         if ( aError == KErrAccessDenied )
       
    79             {
       
    80             NotifyRequestStatus(EVibraRequestNotAllowed);
       
    81             }
       
    82         else 
       
    83             {
       
    84             NotifyRequestStatus(EVibraRequestFail);
       
    85             if ( aError == KErrArgument || aError == KErrNotSupported )
       
    86                 {
       
    87                 User::Leave(aError);
       
    88                 }
       
    89             else
       
    90                 {
       
    91                 User::Leave(KErrGeneral);
       
    92                 }
       
    93             }        
       
    94         }
       
    95     else
       
    96         {
       
    97         NotifyRequestStatus(EVibraRequestOK);
       
    98         iExpectingStop = ETrue;  // Expecting vibra to be stopped by HWRM timer soon.
       
    99         }
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CVibraControlImpl::StartVibraL:
       
   104 // Route call to HWRM Vibra API
       
   105 // -----------------------------------------------------------------------------
       
   106 EXPORT_C void CVibraControlImpl::StartVibraL(TUint16 aDuration, TInt aIntensity)
       
   107     {
       
   108     if ( aIntensity != 0 )
       
   109         {        
       
   110         TRAPD(err, iVibra->StartVibraL(aDuration, aIntensity));
       
   111         HandleErrorL(err);
       
   112         }
       
   113     else
       
   114         {
       
   115         StopVibraL();
       
   116         }    
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CVibraControlImpl::StartVibraL:
       
   121 // Route call to HWRM Vibra API
       
   122 // -----------------------------------------------------------------------------
       
   123 EXPORT_C void CVibraControlImpl::StartVibraL(TUint16 aDuration)
       
   124     {
       
   125     TRAPD(err, iVibra->StartVibraL(aDuration));
       
   126     
       
   127     HandleErrorL(err);
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CVibraControlImpl::StopVibra
       
   132 // Vibra is stopped and timer supervising vibra is cancelled.
       
   133 // -----------------------------------------------------------------------------
       
   134 EXPORT_C void CVibraControlImpl::StopVibraL()
       
   135     {
       
   136     TRAPD(err, iVibra->StopVibraL());
       
   137 
       
   138     if ( err != KErrNone )
       
   139         {
       
   140         NotifyRequestStatus(EVibraRequestUnableToStop);
       
   141         User::Leave(err);
       
   142         }
       
   143     else
       
   144         {
       
   145         NotifyRequestStatus(EVibraRequestStopped);
       
   146         }   
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CVibraControlImpl::VibraSettings
       
   151 // Mode of the vibra is returned (from user profiles)
       
   152 // -----------------------------------------------------------------------------
       
   153 EXPORT_C CVibraControl::TVibraModeState CVibraControlImpl::VibraSettings() const
       
   154     {
       
   155     CHWRMVibra::TVibraModeState hwrmState = iVibra->VibraSettings();
       
   156     
       
   157     CVibraControl::TVibraModeState retval;
       
   158     
       
   159     switch (hwrmState)
       
   160         {
       
   161         case CHWRMVibra::EVibraModeON:
       
   162             {
       
   163             retval = CVibraControl::EVibraModeON;
       
   164             break;
       
   165             }
       
   166         case CHWRMVibra::EVibraModeOFF:
       
   167             {
       
   168             retval = CVibraControl::EVibraModeOFF;
       
   169             break;
       
   170             }
       
   171         default:
       
   172             {
       
   173             retval = CVibraControl::EVibraModeUnknown;
       
   174             break;
       
   175             }
       
   176         }
       
   177  
       
   178     return retval;
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CVibraControlImpl::NotifyRequestStatus
       
   183 // VibraRequestStatus callback method is called if there is observer who is
       
   184 // listening it.
       
   185 // -----------------------------------------------------------------------------
       
   186 void CVibraControlImpl::NotifyRequestStatus(TVibraRequestStatus aStatus)
       
   187     {
       
   188     if (iCallback && iVibraRouteEvents  )
       
   189         {
       
   190         iCallback->VibraRequestStatus(aStatus);
       
   191         }
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CVibraControlImpl::VibraModeChanged
       
   196 // Handler for events from HWRM Vibra API
       
   197 // -----------------------------------------------------------------------------
       
   198 void CVibraControlImpl::VibraModeChanged(CHWRMVibra::TVibraModeState aStatus)
       
   199     {
       
   200     if ( iCallback && iVibraRouteEvents )
       
   201         {        
       
   202         if ( aStatus == CHWRMVibra::EVibraModeON )
       
   203             {
       
   204             iCallback->VibraModeStatus(CVibraControl::EVibraModeON);
       
   205             }
       
   206         else if ( aStatus == CHWRMVibra::EVibraModeOFF )
       
   207             {
       
   208             iCallback->VibraModeStatus(CVibraControl::EVibraModeOFF);
       
   209             }
       
   210         else
       
   211             {
       
   212             iCallback->VibraModeStatus(CVibraControl::EVibraModeUnknown);
       
   213             }
       
   214         }
       
   215     }
       
   216     
       
   217 // -----------------------------------------------------------------------------
       
   218 // CVibraControlImpl::VibraStatusChanged
       
   219 // Handler for events from HWRM Vibra API
       
   220 // -----------------------------------------------------------------------------
       
   221 void CVibraControlImpl::VibraStatusChanged(CHWRMVibra::TVibraStatus aStatus)
       
   222     {
       
   223     // Only notify stop if expecting one. This is required to handle
       
   224     // stop generated automatically by HWRM vibra timer. All other
       
   225     // status notifications are either already handled in initial call or 
       
   226     // relate to some other vibra client.
       
   227     if ( iExpectingStop && aStatus == CHWRMVibra::EVibraStatusStopped )
       
   228         {
       
   229         iExpectingStop = EFalse;
       
   230         NotifyRequestStatus(EVibraRequestStopped);
       
   231         }
       
   232     }
       
   233 
       
   234 //  End of File