javamanager/javacaptain/src.s60/tickerprovider.cpp
branchRCL_3
changeset 19 04becd199f91
child 50 023eef975703
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     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:  TimerServer
       
    15 *
       
    16 */
       
    17 
       
    18 #include "logger.h"
       
    19 
       
    20 #include "tickerprovider.h"
       
    21 
       
    22 namespace java
       
    23 {
       
    24 namespace captain
       
    25 {
       
    26 
       
    27 TickerProvider::TickerProvider(TickerProviderEventsInterface* aEvents)
       
    28         :CActive(EPriorityStandard), TickerProviderInterface(aEvents), mNextTickAt(0LL)
       
    29 {
       
    30     JELOG2(EJavaCaptain);
       
    31     CActiveScheduler::Add(this);
       
    32     mRTimer.CreateLocal();
       
    33 }
       
    34 
       
    35 TickerProvider::~TickerProvider()
       
    36 {
       
    37     JELOG2(EJavaCaptain);
       
    38     Cancel();
       
    39     mRTimer.Close();
       
    40 }
       
    41 
       
    42 void TickerProvider::nextTickAt(const long long& aJavaTime)
       
    43 {
       
    44     JELOG2(EJavaCaptain);
       
    45 
       
    46     if (IsActive())
       
    47     {
       
    48         LOG(EJavaCaptain, EInfo, "Canceling previous RTimer");
       
    49         Cancel();
       
    50     }
       
    51 
       
    52     mNextTickAt = aJavaTime;
       
    53 
       
    54     //In this overflow situation we cannot throw an exception because midp tck expects
       
    55     //LLONG_MAX - 1 to be legal alarm value. We can set alarm to maximum value in this case.
       
    56     //2060 is maximum date year in S60 device.
       
    57     long long overFlowCheckValue = aJavaTime * 1000LL;
       
    58     if (overFlowCheckValue < aJavaTime)
       
    59     {
       
    60         TTime alarmTime(TTime(TDateTime(2060,EJanuary,0,0,0,0,0)).Int64());
       
    61         mRTimer.AtUTC(iStatus, alarmTime);
       
    62     }
       
    63     else
       
    64     {
       
    65         //TTime alarmTime(TTime(TDateTime(1970,EJanuary,0,0,0,0,0)).Int64() + (aJavaTime * 1000LL));
       
    66         TTime alarmTime(TTime(TDateTime(1970,EJanuary,0,0,0,0,0)).Int64() + (overFlowCheckValue));
       
    67         mRTimer.AtUTC(iStatus, alarmTime);
       
    68     }
       
    69 
       
    70     SetActive();
       
    71 }
       
    72 
       
    73 long long TickerProvider::getNextTickAt()
       
    74 {
       
    75     JELOG2(EJavaCaptain);
       
    76     if (IsActive())
       
    77     {
       
    78         return mNextTickAt;
       
    79     }
       
    80 
       
    81     return 0LL;
       
    82 }
       
    83 
       
    84 
       
    85 void TickerProvider::cancel()
       
    86 {
       
    87     JELOG2(EJavaCaptain);
       
    88     if (IsActive())
       
    89     {
       
    90         Cancel();
       
    91     }
       
    92     mNextTickAt = 0LL;
       
    93 }
       
    94 /*
       
    95 long long TickerProvider::getCurrentJavaTime()
       
    96 {
       
    97     JELOG2(EJavaCaptain);
       
    98     TTime currentTime;
       
    99     currentTime.UniversalTime();
       
   100 
       
   101     // Current time - javaEpoc && uSeconds -> mSeconds
       
   102     return (currentTime.Int64()- TTime(TDateTime(1970,EJanuary,0,0,0,0,0)).Int64()) / 1000LL;
       
   103 }
       
   104 */
       
   105 void TickerProvider::RunL()
       
   106 {
       
   107     JELOG2(EJavaCaptain);
       
   108 
       
   109     mNextTickAt = 0LL;
       
   110     if (mEvents)
       
   111     {
       
   112         mEvents->tick();
       
   113     }
       
   114 }
       
   115 
       
   116 void TickerProvider::DoCancel()
       
   117 {
       
   118     JELOG2(EJavaCaptain);
       
   119     mRTimer.Cancel();
       
   120 }
       
   121 
       
   122 } // namespace captain
       
   123 } // namespace java