luna-sysmgr-common
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SingletonTimer.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
33 #ifndef SINGLETONTIMER_H
34 #define SINGLETONTIMER_H
35 
36 #include "Common.h"
37 
38 #include <glib.h>
39 #include <stdint.h>
40 
41 struct TimerHandle;
42 struct TimerSource;
43 
44 typedef void (*TimerCallback)(void* userArg);
45 
59 {
60 public:
75  SingletonTimer(GMainLoop* loop);
76 
84 
102  TimerHandle* create(TimerCallback callback, void* userArg);
103 
116  void fire(TimerHandle* timer, uint64_t timeInMs);
117 
135  void ref(TimerHandle* timer);
136 
151  void deref(TimerHandle* timer);
152 
169  static uint64_t currentTime();
170 
171  // Internal functions. don't use
182  static gboolean timerPrepare(GSource* source, gint* timeout);
183 
194  static gboolean timerCheck(GSource* source);
195 
206  static gboolean timerDispatch(GSource* source, GSourceFunc callback, gpointer userData);
207 
208 private:
218  void destroy(TimerHandle* handle);
219 
223  GMainLoop* m_loop;
224 
228  TimerSource* m_source;
229 
239  GList* m_activeList;
240 
241 private:
254 
267  SingletonTimer& operator=(const SingletonTimer&);
268 };
269 
270 #endif /* SINGLETONTIMER_H */