devicediagnostics/diagplugins/diagvibrateplugin/src/diagvibratepluginengine.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Implements the vibration using CHWRMVibra
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "diagvibratepluginengine.h"
       
    21 #include "diagvibratepluginobserver.h"
       
    22 
       
    23 #include <DiagFrameworkDebug.h> 
       
    24 // EXTERNAL DATA STRUCTURES
       
    25 
       
    26 // EXTERNAL FUNCTION PROTOTYPES
       
    27 
       
    28 // CONSTANTS
       
    29 static const TInt KMilliseconds = 1000;
       
    30 
       
    31 // MACROS
       
    32 
       
    33 // LOCAL CONSTANTS AND MACROS
       
    34 
       
    35 // MODULE DATA STRUCTURES
       
    36 
       
    37 // LOCAL FUNCTION PROTOTYPES
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 
       
    41 // ============================= LOCAL FUNCTIONS ==============================
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // CDiagVibratePluginEngine::CDiagVibratePluginEngine()
       
    47 //
       
    48 // Constructor
       
    49 // ----------------------------------------------------------------------------
       
    50 //
       
    51 CDiagVibratePluginEngine::CDiagVibratePluginEngine( MDiagVibratePluginObserver& aObserver )
       
    52     : iObserver( aObserver )
       
    53     {
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CDiagVibratePluginEngine::NewL()
       
    58 //
       
    59 // Symbian OS default constructor
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CDiagVibratePluginEngine* CDiagVibratePluginEngine::NewL( MDiagVibratePluginObserver& aObserver )
       
    63     {
       
    64     CDiagVibratePluginEngine* self = CDiagVibratePluginEngine::NewLC( aObserver );
       
    65     CleanupStack::Pop( self );
       
    66     return self;
       
    67     }
       
    68     
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CDiagVibratePluginEngine::NewLC()
       
    72 //
       
    73 // Symbian OS default constructor
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CDiagVibratePluginEngine* CDiagVibratePluginEngine::NewLC( MDiagVibratePluginObserver& aObserver )
       
    77     {
       
    78     CDiagVibratePluginEngine* self = new ( ELeave ) CDiagVibratePluginEngine( aObserver );
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();
       
    81     
       
    82     return self;
       
    83     }
       
    84     
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CDiagVibratePluginEngine::ConstructL()
       
    88 //
       
    89 // Symbian OS two-phased constructor
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CDiagVibratePluginEngine::ConstructL()
       
    93     {
       
    94     iVibra = CHWRMVibra::NewL(this);
       
    95     }
       
    96     
       
    97 
       
    98 // ----------------------------------------------------------------------------
       
    99 // CDiagVibratePluginEngine::~CDiagVibratePluginEngine
       
   100 //
       
   101 // Destructor
       
   102 // ----------------------------------------------------------------------------
       
   103 //    
       
   104 CDiagVibratePluginEngine::~CDiagVibratePluginEngine()
       
   105     {
       
   106     if (iVibra)
       
   107         {    
       
   108         iVibra->ReleaseVibra();
       
   109         delete iVibra;
       
   110         }    
       
   111     }    
       
   112 
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // From MHWRMVibraObserver
       
   116 // CDiagVibratePluginEngine::VibraStatusChanged()
       
   117 // ---------------------------------------------------------------------------
       
   118 //    
       
   119 void CDiagVibratePluginEngine::VibraStatusChanged(CHWRMVibra::TVibraStatus aStatus)
       
   120     {
       
   121     TVibrateStatus vibrateStatus = EVibrateFailed;
       
   122     
       
   123     switch(aStatus)
       
   124         {
       
   125         case CHWRMVibra::EVibraStatusOn:
       
   126             vibrateStatus = EVibrateStarted;
       
   127             break;
       
   128 
       
   129         case CHWRMVibra::EVibraStatusStopped:
       
   130             vibrateStatus = EVibrateEnded;
       
   131             break;
       
   132 
       
   133         case CHWRMVibra::EVibraStatusNotAllowed:
       
   134             vibrateStatus = EVibrateBlocked;
       
   135             break;
       
   136         
       
   137         case CHWRMVibra::EVibraStatusUnknown:
       
   138         default:
       
   139             break;
       
   140         }
       
   141         
       
   142     iObserver.VibraStatusChanged( vibrateStatus );
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // From MHWRMVibraObserver
       
   147 // CDiagVibratePluginEngine::VibraModeChanged()
       
   148 // ---------------------------------------------------------------------------
       
   149 //    
       
   150 void CDiagVibratePluginEngine::VibraModeChanged( CHWRMVibra::TVibraModeState aStatus )
       
   151     {
       
   152     switch (aStatus)
       
   153         {
       
   154         case CHWRMVibra::EVibraModeON:
       
   155             break; //no need to do anything
       
   156             
       
   157         case CHWRMVibra::EVibraModeOFF:
       
   158         case CHWRMVibra::EVibraModeUnknown: 
       
   159         default: 
       
   160             iObserver.VibraStatusChanged(EVibrateFailed);    
       
   161             break;
       
   162         }
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // Method to start the vibra
       
   167 // CDiagVibratePluginEngine::StartVibraL()
       
   168 // ---------------------------------------------------------------------------
       
   169 //    
       
   170 void CDiagVibratePluginEngine::StartVibraL( TInt aVibrationTime )
       
   171     {
       
   172     iVibra->ReserveVibraL();
       
   173     iVibra->StartVibraL( aVibrationTime * KMilliseconds, KHWRMVibraMaxIntensity );
       
   174     }
       
   175 
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // Method to stop the vibra
       
   179 // CDiagVibratePluginEngine::StopVibra()
       
   180 // ---------------------------------------------------------------------------
       
   181 //    
       
   182 void CDiagVibratePluginEngine::StopVibra()
       
   183     {
       
   184     iVibra->ReleaseVibra();
       
   185     }    
       
   186 
       
   187 // End of File