Merge branch 'tizen_3.0' into devel/tizen
[platform/core/system/sensord.git] / src / client / sensor_callback_deliverer.h
1 /*
2  * sensord
3  *
4  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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  */
19
20 #ifndef _SENSOR_CALLBACK_DELIVERER_H_
21 #define _SENSOR_CALLBACK_DELIVERER_H_
22
23 #include <glib.h>
24 #include <client_common.h>
25
26 #include <thread>
27 #include <atomic>
28
29 class sensor_callback_deliverer {
30 public:
31         sensor_callback_deliverer();
32         ~sensor_callback_deliverer();
33
34         bool start(void);
35         bool stop(void);
36         bool is_running(void);
37
38         bool push(client_callback_info *ci);
39
40 private:
41         static gboolean callback_dispatcher(gpointer data);
42
43         std::atomic_bool m_running;
44
45         GAsyncQueue *m_callbacks;
46         std::thread *m_deliverer;
47
48         void run(void);
49         bool terminate(void);
50
51         void deliver_to_main_loop(client_callback_info *ci);
52 };
53
54 #endif /* _SENSOR_CALLBACK_DELIVERER_H_ */