resourcemgmt/vibractrl/src/vibratimer.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:  Timer class for superviving Vibrating time
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "vibratimer.h"
       
    21 #include "vibractrl.h" //TVibraCtrlPanic
       
    22 
       
    23 // ============================ MEMBER FUNCTIONS ===============================
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CVibraTimer::NewL
       
    27 // Two-phased constructor.
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CVibraTimer* CVibraTimer::NewL(MVibraTimerCallback* aCallback, TInt aMaxVibTime)
       
    31     {
       
    32     CVibraTimer* p = new (ELeave) CVibraTimer(aCallback, aMaxVibTime);
       
    33     CleanupStack::PushL(p);
       
    34     p->ConstructL();//base call
       
    35     CleanupStack::Pop(); // p
       
    36     return p;
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CVibraTimer::CVibraTimer(MVibraTimerCallback* aCallback)
       
    41 // Constructor with callback class as a parameter.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CVibraTimer::CVibraTimer(MVibraTimerCallback* aCallback, TInt aMaxVibTime)
       
    45 :CTimer(EPriorityHigh), 
       
    46 iCallback(aCallback),
       
    47 iMaximumVibraTimeMs(aMaxVibTime)
       
    48     {
       
    49     __ASSERT_ALWAYS(aCallback != NULL, User::Invariant());
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CVibraTimer::~CVibraTimer
       
    54 // Destructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CVibraTimer::~CVibraTimer()
       
    58     {
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CVibraTimer::Set(TInt aIntervalInMilliSecs)
       
    63 // Start the timer to complete after the specified number of microseconds.
       
    64 // If the duration is zero, then timer is set to predefined maximum value.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 TInt CVibraTimer::Set(TInt aIntervalInMilliSecs)
       
    68     {
       
    69     __ASSERT_ALWAYS(CActiveScheduler::Current()!= NULL, User::Invariant());
       
    70     
       
    71     if (!IsAdded())
       
    72         {
       
    73         CActiveScheduler::Add(this);
       
    74         }
       
    75     
       
    76     // If the timer is already running, cancel it... 
       
    77     if (IsActive())
       
    78         {
       
    79         Cancel();
       
    80         }
       
    81     // And set the new timer... 
       
    82     // Convert to uS first -- which is, after all, why this method really exists...
       
    83     if ((0 == aIntervalInMilliSecs) || (aIntervalInMilliSecs > iMaximumVibraTimeMs))
       
    84         {
       
    85         After(iMaximumVibraTimeMs * 1000);
       
    86         }
       
    87     else
       
    88         {    
       
    89         After(aIntervalInMilliSecs * 1000);
       
    90         }
       
    91     return KErrNone;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CVibraTimer::RunL
       
    96 // RunL() function will be run after the specified system time expires,
       
    97 // i.e. time is set by After() method,
       
    98 // -----------------------------------------------------------------------------
       
    99 void CVibraTimer::RunL()
       
   100     {
       
   101     __ASSERT_ALWAYS(iCallback != NULL, User::Invariant());
       
   102     
       
   103     iCallback->TimerFired();
       
   104     }
       
   105 
       
   106 //  End of File