mmserv/tms/tmsutility/src/tmstimer.cpp
changeset 21 2ed61feeead6
equal deleted inserted replaced
20:b67dd1fc57c5 21:2ed61feeead6
       
     1 /*
       
     2  * Copyright (c) 2010 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: Telephony Multimedia Service
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "tmstimer.h"
       
    20 
       
    21 using namespace TMS;
       
    22 
       
    23 // -----------------------------------------------------------------------------
       
    24 // Constructor
       
    25 // -----------------------------------------------------------------------------
       
    26 //
       
    27 TMSTimer::TMSTimer(gint aPriority) :
       
    28     CTimer(aPriority)
       
    29     {
       
    30     CActiveScheduler::Add(this);
       
    31     }
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // TMSTimer::ConstructL
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 void TMSTimer::ConstructL()
       
    38     {
       
    39     CTimer::ConstructL();
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // TMSTimer::NewL
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 EXPORT_C TMSTimer* TMSTimer::NewL(gint aPriority)
       
    47     {
       
    48     TMSTimer* self = new (ELeave) TMSTimer(aPriority);
       
    49     CleanupStack::PushL(self);
       
    50     self->ConstructL();
       
    51     CleanupStack::Pop(self);
       
    52     return self;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // TMSTimer::~TMSTimer
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 EXPORT_C TMSTimer::~TMSTimer()
       
    60     {
       
    61     Cancel();
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // TMSTimer::NotifyAfter
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 EXPORT_C void TMSTimer::NotifyAfter(gint timeout, TCallBack callback)
       
    69     {
       
    70     if (IsActive())
       
    71         {
       
    72         Cancel();
       
    73         }
       
    74     iObserver = NULL;
       
    75     iCallBack = callback;
       
    76     CTimer::After(TTimeIntervalMicroSeconds32(timeout));
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // TMSTimer::NotifyAfter
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C void TMSTimer::NotifyAfter(gint timeout, TMSTimerObserver& observer)
       
    84     {
       
    85     if (IsActive())
       
    86         {
       
    87         Cancel();
       
    88         }
       
    89     iObserver = &observer;
       
    90     CTimer::After(TTimeIntervalMicroSeconds32(timeout));
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 //  TMSTimer::CancelNotify
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 EXPORT_C void TMSTimer::CancelNotify()
       
    98     {
       
    99     Cancel();
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // TMSTimer::IsRunning
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 EXPORT_C gboolean TMSTimer::IsRunning()
       
   107     {
       
   108     return IsActive();
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // TMSTimer::RunL()
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void TMSTimer::RunL()
       
   116     {
       
   117     // Currently RunL doesn't leave.
       
   118     if (iObserver)
       
   119         {
       
   120         iObserver->TimerEvent();
       
   121         }
       
   122     else
       
   123         {
       
   124         iCallBack.CallBack();
       
   125         }
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // TMSTimer::RunError()
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 TInt TMSTimer::RunError(TInt aError)
       
   133     {
       
   134     return aError;
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 //  TMSTimer::DoCancel
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void TMSTimer::DoCancel()
       
   142     {
       
   143     iObserver = NULL;
       
   144     CTimer::DoCancel();
       
   145     }
       
   146 
       
   147 //  End of File