Adding AK8975 geo-sensor info in sensors.xml.in required by geo-plugin
[platform/core/system/sensord.git] / src / shared / csensor_event_dispatcher.h
1 /*
2  * libsensord-share
3  *
4  * Copyright (c) 2014 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_EVENT_DISPATCHER_H_
21 #define _SENSOR_EVENT_DISPATCHER_H_
22
23 #include <sf_common.h>
24 #include <csensor_event_queue.h>
25 #include <cclient_info_manager.h>
26 #include <sensor_fusion.h>
27 #include <csocket.h>
28 #include <virtual_sensor.h>
29 #include <vconf.h>
30
31 typedef map<unsigned int, sensor_event_t> event_type_last_event_map;
32 typedef list<virtual_sensor *> virtual_sensors;
33
34 class csensor_event_dispatcher
35 {
36 private:
37         bool m_lcd_on;
38         csocket m_accept_socket;
39         cmutex m_mutex;
40         cmutex m_last_events_mutex;
41         event_type_last_event_map m_last_events;
42         virtual_sensors m_active_virtual_sensors;
43         cmutex m_active_virtual_sensors_mutex;
44         sensor_fusion *m_sensor_fusion;
45
46         csensor_event_dispatcher();
47         ~csensor_event_dispatcher();
48         csensor_event_dispatcher(csensor_event_dispatcher const &) {};
49         csensor_event_dispatcher &operator=(csensor_event_dispatcher const &);
50
51         void accept_connections(void);
52         void accept_event_channel(csocket client_socket);
53
54         void dispatch_event(void);
55         void send_sensor_events(void *events, int event_cnt, bool is_hub_event, event_situation situation);
56         static void situation_watcher(keynode_t *node, void *user_data);
57         bool is_lcd_on(void);
58         static cclient_info_manager &get_client_info_manager(void);
59         static csensor_event_queue &get_event_queue(void);
60
61         bool is_record_event(unsigned int event_type);
62         void put_last_event(unsigned int event_type, const sensor_event_t &event);
63         bool get_last_event(unsigned int event_type, sensor_event_t &event);
64
65         bool has_active_virtual_sensor(virtual_sensor *sensor);
66         virtual_sensors get_active_virtual_sensors(void);
67
68         static bool compare_by_timestamp(const sensor_event_t &a, const sensor_event_t &b);
69         void sort_sensor_events(sensor_event_t *events, unsigned int cnt);
70 public:
71         static csensor_event_dispatcher &get_instance() {
72                 static csensor_event_dispatcher inst;
73                 return inst;
74         }
75
76         bool run(void);
77         void request_last_event(int client_id, const sensor_type_t sensor);
78
79         bool add_active_virtual_sensor(virtual_sensor *sensor);
80         bool delete_active_virtual_sensor(virtual_sensor *sensor);
81 };
82
83 #endif /*_CSENSOR_EVENT_DISPATCHER_H_*/