javamanager/javacaptain/src/tickerproviderinterface.h
branchRCL_3
changeset 14 04becd199f91
child 24 6c158198356e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/javamanager/javacaptain/src/tickerproviderinterface.h	Tue Apr 27 16:30:29 2010 +0300
@@ -0,0 +1,90 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  TickerProviderInterface
+*
+*/
+
+#ifndef TICKERPROVIDERINTERFACE_H
+#define TICKERPROVIDERINTERFACE_H
+
+#include <time.h>
+#include <sys/time.h>
+
+namespace java
+{
+namespace captain
+{
+
+class TickerProviderEventsInterface
+{
+public:
+    virtual void tick() = 0;
+};
+
+class TickerProviderInterface
+{
+    TickerProviderInterface(); // Cannot be used
+public:
+    TickerProviderInterface(TickerProviderEventsInterface* aEvents)
+            :mEvents(aEvents)
+    {}
+    virtual ~TickerProviderInterface()
+    {}
+
+    /**
+    * Starts the ticker.
+    * @param[in] aPeriod - delay in seconds
+    * @return -
+    */
+    virtual void nextTickAt(const long long& aJavaTime) = 0;
+    /**
+    * Returns current tick time if set.
+    * @param[in]
+    * @return - 0 if not set otherwise the set time
+    */
+    virtual long long getNextTickAt() = 0;
+    /**
+    * Stops the ticker.
+    * @param -
+    * @return -
+    */
+    virtual void cancel() = 0;
+
+    // Helpers
+    /**
+    * Returns milliseconds from EPOCH.
+    * @param[in]  -
+    * @return - milliseconds from EPOCH in success, -1 if fails
+    */
+    virtual long long getCurrentJavaTime()
+    {
+        timeval tim;
+        int err = gettimeofday(&tim, NULL);
+        if (-1 == err)
+        {
+            return -1LL;
+        }
+
+        return (tim.tv_sec * 1000LL) +
+               (tim.tv_usec / 1000LL);
+    }
+
+protected:
+    TickerProviderEventsInterface*  mEvents;
+};
+
+} // namespace captain
+} // namespace java
+
+#endif // TICKERPROVIDERINTERFACE_H