|
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: TickerProviderInterface |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef TICKERPROVIDERINTERFACE_H |
|
19 #define TICKERPROVIDERINTERFACE_H |
|
20 |
|
21 #include <time.h> |
|
22 #include <sys/time.h> |
|
23 |
|
24 namespace java |
|
25 { |
|
26 namespace captain |
|
27 { |
|
28 |
|
29 class TickerProviderEventsInterface |
|
30 { |
|
31 public: |
|
32 virtual void tick() = 0; |
|
33 }; |
|
34 |
|
35 class TickerProviderInterface |
|
36 { |
|
37 TickerProviderInterface(); // Cannot be used |
|
38 public: |
|
39 TickerProviderInterface(TickerProviderEventsInterface* aEvents) |
|
40 :mEvents(aEvents) |
|
41 {} |
|
42 virtual ~TickerProviderInterface() |
|
43 {} |
|
44 |
|
45 /** |
|
46 * Starts the ticker. |
|
47 * @param[in] aPeriod - delay in seconds |
|
48 * @return - |
|
49 */ |
|
50 virtual void nextTickAt(const long long& aJavaTime) = 0; |
|
51 /** |
|
52 * Returns current tick time if set. |
|
53 * @param[in] |
|
54 * @return - 0 if not set otherwise the set time |
|
55 */ |
|
56 virtual long long getNextTickAt() = 0; |
|
57 /** |
|
58 * Stops the ticker. |
|
59 * @param - |
|
60 * @return - |
|
61 */ |
|
62 virtual void cancel() = 0; |
|
63 |
|
64 // Helpers |
|
65 /** |
|
66 * Returns milliseconds from EPOCH. |
|
67 * @param[in] - |
|
68 * @return - milliseconds from EPOCH in success, -1 if fails |
|
69 */ |
|
70 virtual long long getCurrentJavaTime() |
|
71 { |
|
72 timeval tim; |
|
73 int err = gettimeofday(&tim, NULL); |
|
74 if (-1 == err) |
|
75 { |
|
76 return -1LL; |
|
77 } |
|
78 |
|
79 return (tim.tv_sec * 1000LL) + |
|
80 (tim.tv_usec / 1000LL); |
|
81 } |
|
82 |
|
83 protected: |
|
84 TickerProviderEventsInterface* mEvents; |
|
85 }; |
|
86 |
|
87 } // namespace captain |
|
88 } // namespace java |
|
89 |
|
90 #endif // TICKERPROVIDERINTERFACE_H |