usbengines/usbotgwatcher/src/cusbtimer.cpp
branchRCL_3
changeset 20 a15c582fbf97
parent 13 7068aba64af5
child 21 ff9df6630274
equal deleted inserted replaced
13:7068aba64af5 20:a15c582fbf97
     1 /*
     1 /*
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     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  *
     8  *
    16 */
     9  * Initial Contributors:
    17 
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  Implementation
       
    15  *
       
    16  */
    18 
    17 
    19 #include "cusbtimer.h"
    18 #include "cusbtimer.h"
    20 
    19 
    21 #include "debug.h"
    20 #include "debug.h"
    22 
    21 
    23 // ---------------------------------------------------------------------------
    22 // ---------------------------------------------------------------------------
    24 // 
    23 // 
    25 // ---------------------------------------------------------------------------
    24 // ---------------------------------------------------------------------------
    26 //
    25 //
    27 CUsbTimer::CUsbTimer(MUsbTimerObserver* aObserver, TUsbTimerId aTimerId) :
    26 CUsbTimer::CUsbTimer(MUsbTimerObserver& aObserver, TUsbTimerId aTimerId) :
    28     CActive(CActive::EPriorityStandard), iObserver(aObserver), iTimerId(
    27     CActive(CActive::EPriorityStandard), iObserver(aObserver), iTimerId(
    29             aTimerId)
    28             aTimerId)
    30     {
    29     {
    31     CActiveScheduler::Add(this);
    30     CActiveScheduler::Add(this);
    32     }
    31     }
    35 // 
    34 // 
    36 // ---------------------------------------------------------------------------
    35 // ---------------------------------------------------------------------------
    37 //
    36 //
    38 CUsbTimer::~CUsbTimer()
    37 CUsbTimer::~CUsbTimer()
    39     {
    38     {
    40         FLOG( _L( "[USBOTGWATCHER]\tCUsbTimer::~CUsbTimer" ) );
    39     LOG_FUNC
    41     Cancel();
    40     Cancel();
    42     iTimer.Close();
    41     iTimer.Close();
    43     }
    42     }
    44 
    43 
    45 // ---------------------------------------------------------------------------
    44 // ---------------------------------------------------------------------------
    46 // 
    45 // 
    47 // ---------------------------------------------------------------------------
    46 // ---------------------------------------------------------------------------
    48 //
    47 //
    49 void CUsbTimer::ConstructL()
    48 void CUsbTimer::ConstructL()
    50     {
    49     {
    51         FLOG( _L( "[USBOTGWATCHER]\tCUsbTimer::ConstructL" ) );
    50     LOG_FUNC
    52     User::LeaveIfError(iTimer.CreateLocal());
    51     User::LeaveIfError(iTimer.CreateLocal());
    53     }
    52     }
    54 
    53 
    55 // ---------------------------------------------------------------------------
    54 // ---------------------------------------------------------------------------
    56 // 
    55 // 
    57 // ---------------------------------------------------------------------------
    56 // ---------------------------------------------------------------------------
    58 //
    57 //
    59 CUsbTimer* CUsbTimer::NewL(MUsbTimerObserver* anObserver,
    58 CUsbTimer* CUsbTimer::NewL(MUsbTimerObserver& aObserver, TUsbTimerId aTimerId)
    60         TUsbTimerId aTimerId)
       
    61     {
    59     {
    62         FLOG( _L( "[USBOTGWATCHER]\tCUsbTimer::NewL" ) );
    60     LOG_FUNC
    63 
    61 
    64     CUsbTimer* self = new (ELeave) CUsbTimer(anObserver, aTimerId);
    62     CUsbTimer* self = new (ELeave) CUsbTimer(aObserver, aTimerId);
    65     CleanupStack::PushL(self);
    63     CleanupStack::PushL(self);
    66     self->ConstructL();
    64     self->ConstructL();
    67     CleanupStack::Pop(self); // pop self
    65     CleanupStack::Pop(self); // pop self
    68     return self;
    66     return self;
    69     }
    67     }
    72 // 
    70 // 
    73 // ---------------------------------------------------------------------------
    71 // ---------------------------------------------------------------------------
    74 //
    72 //
    75 void CUsbTimer::After(TInt aMilliseconds)
    73 void CUsbTimer::After(TInt aMilliseconds)
    76     {
    74     {
    77 //        FTRACE(FPrint(_L( "[USBOTGWATCHER]\tCUsbTimer::After aMilliseconds %d, timerId=%d" ), aMilliseconds, iTimerId))
    75     if (IsActive())
    78 
       
    79     if (IsActive()) 
       
    80         {
    76         {
    81         Cancel();
    77         Cancel();
    82         }
    78         }
    83 
    79 
    84     // RunL will be called after KInactiveTimeForShutDown milliseconds
    80     // RunL will be called after KInactiveTimeForShutDown milliseconds
    91 // ---------------------------------------------------------------------------
    87 // ---------------------------------------------------------------------------
    92 //
    88 //
    93 void CUsbTimer::RunL()
    89 void CUsbTimer::RunL()
    94     {
    90     {
    95 
    91 
    96     if(KErrNone != iStatus.Int())
    92     if (KErrNone != iStatus.Int())
    97         {
    93         {
    98         FTRACE(FPrint(_L( "[USBOTGWATCHER]\tCUsbTimer::RunL iStatus %d" ), iStatus.Int()));
       
    99         User::Leave(iStatus.Int());
    94         User::Leave(iStatus.Int());
   100         }
    95         }
   101 
    96 
   102     iObserver->TimerElapsedL(iTimerId);
    97     iObserver.TimerElapsedL(iTimerId);
   103     }
    98     }
   104 
    99 
   105 // ---------------------------------------------------------------------------
   100 // ---------------------------------------------------------------------------
   106 // 
   101 // 
   107 // ---------------------------------------------------------------------------
   102 // ---------------------------------------------------------------------------
   108 //
   103 //
   109 TInt CUsbTimer::RunError(TInt aError)
   104 TInt CUsbTimer::RunError(TInt aError)
   110     {
   105     {
   111         FTRACE(FPrint(_L( "[USBOTGWATCHER]\tCUsbTimer::RunError aError %d" ), aError ));
   106     LOG_FUNC
       
   107     LOG1( "aError = %d" , aError );
   112 
   108 
   113     return KErrNone;
   109     return KErrNone;
   114     }
   110     }
   115 
   111 
   116 // ---------------------------------------------------------------------------
   112 // ---------------------------------------------------------------------------
   117 // 
   113 // 
   118 // ---------------------------------------------------------------------------
   114 // ---------------------------------------------------------------------------
   119 //
   115 //
   120 void CUsbTimer::DoCancel()
   116 void CUsbTimer::DoCancel()
   121     {
   117     {
   122         FLOG( _L( "[USBOTGWATCHER]\tCUsbTimer::DoCancel" ) )
       
   123     iTimer.Cancel();
   118     iTimer.Cancel();
   124     }
   119     }