Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
glib-loop.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Piotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 
25 #ifndef COMMON_UTILS_GLIB_LOOP_HPP
26 #define COMMON_UTILS_GLIB_LOOP_HPP
27 
28 #include "utils/callback-guard.hpp"
29 
30 #include <thread>
31 #include <memory>
32 #include <glib.h>
33 
34 
35 namespace utils {
36 
37 
42 public:
47 
52 
53 private:
54  std::unique_ptr<GMainLoop, void(*)(GMainLoop*)> mLoop;
55  std::thread mLoopThread;
56 };
57 
61 class Glib {
62 public:
69  typedef std::function<bool()> OnTimerEventCallback;
70 
74  static void addTimerEvent(const unsigned int intervalMs,
75  const OnTimerEventCallback& callback,
76  const CallbackGuard& guard);
77 
78 private:
79  static gboolean onTimerEvent(gpointer data);
80 };
81 
82 } // namespace utils
83 
84 
85 #endif // COMMON_UTILS_GLIB_LOOP_HPP
std::thread mLoopThread
Definition: glib-loop.hpp:55
Callback guard.
Callback guard.
Definition: callback-guard.hpp:38
Glib loop controller.
Definition: glib-loop.hpp:41
Miscellaneous helpers for the Glib library.
Definition: glib-loop.hpp:61
static gboolean onTimerEvent(gpointer data)
Definition: glib-loop.cpp:76
char data[368]
Definition: initctl.cpp:41
std::function< bool()> OnTimerEventCallback
A user provided function that will be called succesively after an interval has passed.
Definition: glib-loop.hpp:69
static void addTimerEvent(const unsigned int intervalMs, const OnTimerEventCallback &callback, const CallbackGuard &guard)
Adds a timer event to the glib main loop.
Definition: glib-loop.cpp:65
std::unique_ptr< GMainLoop, void(*)(GMainLoop *)> mLoop
Definition: glib-loop.hpp:54
~ScopedGlibLoop()
Stops loop and waits for a thread.
Definition: glib-loop.cpp:53
ScopedGlibLoop()
Starts a loop in separate thread.
Definition: glib-loop.cpp:40