javamanager/javacaptain/inc/timerserverinterface.h
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     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:  TimerServerInterface
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef TIMERSERVERINTERFACE_H
       
    19 #define TIMERSERVERINTERFACE_H
       
    20 
       
    21 namespace java
       
    22 {
       
    23 namespace captain
       
    24 {
       
    25 
       
    26 class TimerServerEventsInterface
       
    27 {
       
    28 public:
       
    29     virtual ~TimerServerEventsInterface() {}
       
    30 
       
    31     virtual void timerTimeout(const int& aTimerId) = 0;
       
    32 };
       
    33 
       
    34 class JavaTime
       
    35 {
       
    36 public:
       
    37     JavaTime():mMillisFromEpoch(0LL) {}
       
    38     JavaTime(const long long& aTime):mMillisFromEpoch(aTime) {}
       
    39     JavaTime(const JavaTime& aJt):mMillisFromEpoch(aJt.getTime()) {}
       
    40     JavaTime& operator= (const JavaTime& aJt)
       
    41     {
       
    42         mMillisFromEpoch = aJt.getTime();
       
    43         return *this;
       
    44     }
       
    45     const long long& operator+ (const long long& a)
       
    46     {
       
    47         return (this->mMillisFromEpoch += a);
       
    48     }
       
    49     virtual ~JavaTime() {}
       
    50 
       
    51     virtual long long getTime() const
       
    52     {
       
    53         return mMillisFromEpoch;
       
    54     }
       
    55     virtual void setTime(const long long& aNewTime)
       
    56     {
       
    57         mMillisFromEpoch = aNewTime;
       
    58     }
       
    59 
       
    60 private:
       
    61     long long mMillisFromEpoch;
       
    62 };
       
    63 
       
    64 class TimerServerInterface
       
    65 {
       
    66 public:
       
    67     virtual ~TimerServerInterface() {}
       
    68 
       
    69     /**
       
    70     * Creates a new timer.
       
    71     * @param[in] aTimeoutInSeconds
       
    72     * @param[in] aTimerEvents - Callback interface when timer expires
       
    73     * @return >0 TimerId in success, 0 in failure
       
    74     */
       
    75     virtual int timerCreateSeconds(const unsigned int& aTimeoutInSeconds,
       
    76                                    TimerServerEventsInterface* aTimerEvents) = 0;
       
    77 
       
    78     /**
       
    79     * Creates a new timer.
       
    80     * @param[in] aJavaTime - time when timer should expire in java format
       
    81     * @param[in] aTimerEvents - Callback interface when timer expires
       
    82     * @return >0 TimerId in success, 0 in failure
       
    83     */
       
    84     virtual int timerCreateJavaTime(const JavaTime& aJavaTime,
       
    85                                     TimerServerEventsInterface* aTimerEvents) = 0;
       
    86 
       
    87     /**
       
    88     * Cancels a timer.
       
    89     * @param[in] aTimerId
       
    90     * @return -
       
    91     */
       
    92     virtual void timerCancel(const int& aTimerId) = 0;
       
    93 
       
    94     virtual JavaTime& getCurrentJavaTime(JavaTime&) const = 0;
       
    95 
       
    96     virtual bool hasExpired(const JavaTime&, const long long& aAccuracyInMs = 100) const = 0;
       
    97 
       
    98     virtual bool isLess(const JavaTime& a, const JavaTime& b) const = 0;
       
    99     virtual bool isEqual(const JavaTime& a, const JavaTime& b) const = 0;
       
   100     virtual bool isMore(const JavaTime& a, const JavaTime& b) const = 0;
       
   101 };
       
   102 
       
   103 } // namespace captain
       
   104 } // namespace java
       
   105 
       
   106 #endif // TIMERSERVERINTERFACE_H