contextframework/cfwplugins/vibraactionplugin/src/vibraactionplugin.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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:  CVibraActionPlugIn class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "vibraactionplugin.h"
       
    20 
       
    21 #include <cfactionindication.h>
       
    22 
       
    23 #include "vibratrace.h"
       
    24 #include "vibraaction.h"
       
    25 
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 // Security policy for vibra action
       
    30 _LIT_SECURITY_POLICY_PASS( KSecurityPolicy );
       
    31 
       
    32 // Vibra actions
       
    33 _LIT( KVibraAction, "Vibra" );
       
    34 
       
    35 // Vibra parameters
       
    36 _LIT( KVibraMode, "Mode" );
       
    37 _LIT( KVibraDelay, "Delay" );
       
    38 _LIT( KVibraRepeats, "Repeats" );
       
    39 _LIT( KVibraRepeatInterval, "RepeatInterval" );
       
    40 _LIT( KVibraDuration, "Duration" );
       
    41 _LIT( KVibraIntensity, "Intensity" );
       
    42 
       
    43 // Vibra mode values
       
    44 _LIT( KVibraStart, "Start" );
       
    45 _LIT( KVibraStop, "Stop" );
       
    46 
       
    47 #ifdef _DEBUG
       
    48 // Panic category
       
    49 _LIT( KPanicCat, "VibraAction" );
       
    50 
       
    51 // Panic codes
       
    52 enum TPanicCode
       
    53     {
       
    54     EVibraActionNotInitialized
       
    55     };
       
    56 
       
    57 // Local panic function
       
    58 LOCAL_C void Panic( TPanicCode aCode )
       
    59     {
       
    60     User::Panic( KPanicCat, aCode );
       
    61     }
       
    62 
       
    63 #endif
       
    64 
       
    65 // MEMBER FUNCTIONS
       
    66 
       
    67 CVibraActionPlugIn* CVibraActionPlugIn::NewL()
       
    68     {
       
    69     FUNC_LOG;
       
    70 
       
    71     CVibraActionPlugIn* self = CVibraActionPlugIn::NewLC();
       
    72     CleanupStack::Pop( self );
       
    73 
       
    74     return self;
       
    75     }
       
    76 
       
    77 CVibraActionPlugIn* CVibraActionPlugIn::NewLC()
       
    78     {
       
    79     FUNC_LOG;
       
    80 
       
    81     CVibraActionPlugIn* self = new( ELeave ) CVibraActionPlugIn;
       
    82     CleanupStack::PushL( self );
       
    83 
       
    84     return self;
       
    85     }
       
    86 
       
    87 // Destructor
       
    88 CVibraActionPlugIn::~CVibraActionPlugIn()
       
    89     {
       
    90     FUNC_LOG;
       
    91 
       
    92     delete iVibraAction;
       
    93     }
       
    94 
       
    95 CVibraActionPlugIn::CVibraActionPlugIn()
       
    96     {
       
    97     FUNC_LOG;
       
    98 
       
    99     // Nothing to do
       
   100     }
       
   101 
       
   102 // METHODS
       
   103 
       
   104 //-----------------------------------------------------------------------------
       
   105 // CVibraActionPlugIn::InitializeL
       
   106 //-----------------------------------------------------------------------------
       
   107 //
       
   108 void CVibraActionPlugIn::InitializeL()
       
   109     {
       
   110     FUNC_LOG;
       
   111 
       
   112     iVibraAction = CVibraAction::NewL( *this );
       
   113     }
       
   114 
       
   115 //-----------------------------------------------------------------------------
       
   116 // CVibraActionPlugIn::ExecuteL
       
   117 //-----------------------------------------------------------------------------
       
   118 //
       
   119 CCFActionPlugIn::TExecutionTime CVibraActionPlugIn::ExecuteL(
       
   120     CCFActionIndication* aActionIndication )
       
   121     {
       
   122     FUNC_LOG;
       
   123 
       
   124     CCFActionPlugIn::TExecutionTime time = CCFActionPlugIn::ENone;
       
   125 
       
   126     __ASSERT_DEBUG( iVibraAction, Panic( EVibraActionNotInitialized ) );
       
   127 
       
   128     // Parse settings
       
   129     const RKeyValueArray& parameters = aActionIndication->Parameters();
       
   130     TInt count = parameters.Count();
       
   131     TPtrC key( KNullDesC );
       
   132     TPtrC value( KNullDesC );
       
   133 
       
   134     TVibraActionInfo info;
       
   135     TPtrC mode( KNullDesC );
       
   136     for( TInt i = 0; i < count; i++ )
       
   137         {
       
   138         key.Set( parameters[i]->Key() );
       
   139         value.Set( parameters[i]->Value() );
       
   140 
       
   141         // Mode
       
   142         if( key.CompareF( KVibraMode ) == KErrNone )
       
   143             {
       
   144             mode.Set( value );
       
   145             INFO_1( "Vibra mode: %S", &mode );
       
   146             }
       
   147         // Delay
       
   148         else if( key.CompareF( KVibraDelay ) == KErrNone )
       
   149             {
       
   150             info.iDelay = ConvertToInt( value );
       
   151             INFO_1( "Vibra delay: %d", info.iDelay );
       
   152             }
       
   153         // Repeats
       
   154         else if( key.CompareF( KVibraRepeats ) == KErrNone )
       
   155             {
       
   156             info.iRepeats = ConvertToInt( value );
       
   157             INFO_1( "Vibra repeats: %d", info.iRepeats );
       
   158             }
       
   159         // Repeat interval
       
   160         else if( key.CompareF( KVibraRepeatInterval ) == KErrNone )
       
   161             {
       
   162             info.iRepeatInterval = ConvertToInt( value );
       
   163             INFO_1( "Vibra repeat interval: %d", info.iRepeatInterval );
       
   164             }
       
   165         // Duration
       
   166         else if( key.CompareF( KVibraDuration ) == KErrNone )
       
   167             {
       
   168             info.iDuration = ConvertToInt( value );
       
   169             INFO_1( "Vibra duration: %d", info.iDuration );
       
   170             }
       
   171         // Intensity
       
   172         else if( key.CompareF( KVibraIntensity ) == KErrNone )
       
   173             {
       
   174             info.iIntensity = ConvertToInt( value );
       
   175             INFO_1( "Vibra intensity: %d", info.iIntensity );
       
   176             }
       
   177         }
       
   178 
       
   179     // Start vibra
       
   180     if( mode.CompareF( KVibraStart ) == KErrNone )
       
   181         {
       
   182         // Check if we have to repeat vibra pulses
       
   183         // In this case we must not return with ENone since
       
   184         // action execution thread will start waiting in semaphore
       
   185         // and none of the active objects will then be run
       
   186         time = iVibraAction->StartVibraL( info );
       
   187         }
       
   188     // Stop vibra
       
   189     else if( mode.CompareF( KVibraStop ) == KErrNone )
       
   190         {
       
   191         iVibraAction->StopVibraL();
       
   192         }
       
   193 
       
   194     return time;
       
   195     }
       
   196 
       
   197 //-----------------------------------------------------------------------------
       
   198 // CVibraActionPlugIn::GetActionsL
       
   199 //-----------------------------------------------------------------------------
       
   200 //
       
   201 void CVibraActionPlugIn::GetActionsL( CDesCArray& aActionList ) const
       
   202     {
       
   203     FUNC_LOG;
       
   204 
       
   205     aActionList.AppendL( KVibraAction );
       
   206     }
       
   207 
       
   208 //-----------------------------------------------------------------------------
       
   209 // CVibraActionPlugIn::SecurityPolicy
       
   210 //-----------------------------------------------------------------------------
       
   211 //
       
   212 const TSecurityPolicy& CVibraActionPlugIn::SecurityPolicy() const
       
   213     {
       
   214     FUNC_LOG;
       
   215 
       
   216     return KSecurityPolicy;
       
   217     }
       
   218 
       
   219 //-----------------------------------------------------------------------------
       
   220 // CVibraActionPlugIn::VibraActionCompletedL
       
   221 //-----------------------------------------------------------------------------
       
   222 //
       
   223 void CVibraActionPlugIn::VibraActionCompletedL()
       
   224     {
       
   225     FUNC_LOG;
       
   226 
       
   227     AsyncExecutionCompleted();
       
   228     }
       
   229 
       
   230 //-----------------------------------------------------------------------------
       
   231 // CVibraActionPlugIn::ConvertToInt
       
   232 //-----------------------------------------------------------------------------
       
   233 //
       
   234 TInt CVibraActionPlugIn::ConvertToInt( const TDesC& aDesc ) const
       
   235     {
       
   236     FUNC_LOG;
       
   237 
       
   238     TInt value = 0;
       
   239 
       
   240     TLex lex( aDesc );
       
   241     if( lex.Val( value ) != KErrNone )
       
   242         {
       
   243         value = KErrNotFound;
       
   244         }
       
   245 
       
   246     return value;
       
   247     }