usbengines/usbotgwatcher/src/cusbtimer.cpp
changeset 35 9d8b04ca6939
child 63 ef2686f7597e
equal deleted inserted replaced
34:7858bc6ead78 35:9d8b04ca6939
       
     1 /*
       
     2  * Copyright (c) 2008 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 #include "cusbtimer.h"
       
    19 
       
    20 #include "debug.h"
       
    21 
       
    22 // ---------------------------------------------------------------------------
       
    23 // 
       
    24 // ---------------------------------------------------------------------------
       
    25 //
       
    26 CUsbTimer::CUsbTimer(MUsbTimerObserver& aObserver, TUsbTimerId aTimerId) :
       
    27     CActive(CActive::EPriorityStandard), iObserver(aObserver), iTimerId(
       
    28             aTimerId)
       
    29     {
       
    30     CActiveScheduler::Add(this);
       
    31     }
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // 
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CUsbTimer::~CUsbTimer()
       
    38     {
       
    39     LOG_FUNC
       
    40     Cancel();
       
    41     iTimer.Close();
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // 
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 void CUsbTimer::ConstructL()
       
    49     {
       
    50     LOG_FUNC
       
    51     LEAVEIFERROR(iTimer.CreateLocal());
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // 
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CUsbTimer* CUsbTimer::NewL(MUsbTimerObserver& aObserver, TUsbTimerId aTimerId)
       
    59     {
       
    60     LOG_FUNC
       
    61 
       
    62     CUsbTimer* self = new (ELeave) CUsbTimer(aObserver, aTimerId);
       
    63     CleanupStack::PushL(self);
       
    64     self->ConstructL();
       
    65     CleanupStack::Pop(self); // pop self
       
    66     return self;
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // 
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 void CUsbTimer::After(TInt aMilliseconds)
       
    74     {
       
    75     if (IsActive())
       
    76         {
       
    77         Cancel();
       
    78         }
       
    79 
       
    80     // RunL will be called after KInactiveTimeForShutDown milliseconds
       
    81     iTimer.After(iStatus, TTimeIntervalMicroSeconds32(aMilliseconds));
       
    82     SetActive();
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // 
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CUsbTimer::RunL()
       
    90     {
       
    91 
       
    92     if (KErrNone != iStatus.Int())
       
    93         {
       
    94         LEAVE(iStatus.Int());
       
    95         }
       
    96 
       
    97     iObserver.TimerElapsedL(iTimerId);
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // 
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 TInt CUsbTimer::RunError(TInt aError)
       
   105     {
       
   106     LOG_FUNC
       
   107     LOG1( "aError = %d" , aError );
       
   108 
       
   109     return KErrNone;
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // 
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 void CUsbTimer::DoCancel()
       
   117     {
       
   118     iTimer.Cancel();
       
   119     }