usbengines/usbotgwatcher/src/cusbtimer.cpp
changeset 0 1e05558e2206
child 5 7068aba64af5
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:  Implementation
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cusbtimer.h"
       
    20 
       
    21 #include "debug.h"
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // 
       
    25 // ---------------------------------------------------------------------------
       
    26 //
       
    27 CUsbTimer::CUsbTimer(MUsbTimerObserver* aObserver, TUsbTimerId aTimerId) :
       
    28     CActive(CActive::EPriorityStandard), iObserver(aObserver), iTimerId(
       
    29             aTimerId)
       
    30     {
       
    31     CActiveScheduler::Add(this);
       
    32     }
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // 
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CUsbTimer::~CUsbTimer()
       
    39     {
       
    40         FLOG( _L( "[USBOTGWATCHER]\tCUsbTimer::~CUsbTimer" ) );
       
    41     Cancel();
       
    42     iTimer.Close();
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // 
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 void CUsbTimer::ConstructL()
       
    50     {
       
    51         FLOG( _L( "[USBOTGWATCHER]\tCUsbTimer::ConstructL" ) );
       
    52     User::LeaveIfError(iTimer.CreateLocal());
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // 
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CUsbTimer* CUsbTimer::NewL(MUsbTimerObserver* anObserver,
       
    60         TUsbTimerId aTimerId)
       
    61     {
       
    62         FLOG( _L( "[USBOTGWATCHER]\tCUsbTimer::NewL" ) );
       
    63 
       
    64     CUsbTimer* self = new (ELeave) CUsbTimer(anObserver, aTimerId);
       
    65     CleanupStack::PushL(self);
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop(self); // pop self
       
    68     return self;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // 
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CUsbTimer::After(TInt aMilliseconds)
       
    76     {
       
    77 //        FTRACE(FPrint(_L( "[USBOTGWATCHER]\tCUsbTimer::After aMilliseconds %d, timerId=%d" ), aMilliseconds, iTimerId))
       
    78 
       
    79     if (IsActive()) // should we panic here? or just restart timer
       
    80         {
       
    81         Cancel();
       
    82         }
       
    83 
       
    84     // RunL will be called after KInactiveTimeForShutDown milliseconds
       
    85     iTimer.After(iStatus, TTimeIntervalMicroSeconds32(aMilliseconds));
       
    86     SetActive();
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // 
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CUsbTimer::RunL()
       
    94     {
       
    95 
       
    96     if(KErrNone != iStatus.Int())
       
    97         {
       
    98         FTRACE(FPrint(_L( "[USBOTGWATCHER]\tCUsbTimer::RunL iStatus %d" ), iStatus.Int()));
       
    99         User::Leave(iStatus.Int());
       
   100         }
       
   101 
       
   102     iObserver->TimerElapsedL(iTimerId);
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // 
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 TInt CUsbTimer::RunError(TInt aError)
       
   110     {
       
   111         FTRACE(FPrint(_L( "[USBOTGWATCHER]\tCUsbTimer::RunError aError %d" ), aError ));
       
   112 
       
   113     return KErrNone;
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // 
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 void CUsbTimer::DoCancel()
       
   121     {
       
   122         FLOG( _L( "[USBOTGWATCHER]\tCUsbTimer::DoCancel" ) )
       
   123     iTimer.Cancel();
       
   124     }