sensord: clean up sf_common.h/sensor_common.h/sensor_logs.h
[platform/core/system/sensord.git] / src / client / sensor_client_info.h
1 /*
2  * libsensord
3  *
4  * Copyright (c) 2015 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_CLIENT_INFO_H_
21 #define _SENSOR_CLIENT_INFO_H_
22
23 #include <glib.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #include <csocket.h>
27 #include <string.h>
28 #include <algorithm>
29 #include <sstream>
30 #include <unordered_map>
31 #include <vector>
32 #include <string>
33 #include <queue>
34 #include <mutex>
35 #include <condition_variable>
36 #include <cmutex.h>
37 #include <sensor_handle_info.h>
38 #include <command_channel.h>
39
40 using std::unordered_map;
41 using std::vector;
42 using std::string;
43 using std::queue;
44 using std::mutex;
45 using std::lock_guard;
46 using std::unique_lock;
47 using std::condition_variable;
48
49 typedef vector<unsigned int> handle_vector;
50 typedef vector<sensor_id_t> sensor_id_vector;
51 typedef unordered_map<int,sensor_handle_info> sensor_handle_info_map;
52 typedef unordered_map<sensor_id_t, command_channel*> sensor_command_channel_map;
53
54 typedef struct sensor_rep {
55         bool active;
56         int option;
57         unsigned int interval;
58         unsigned int latency;
59         event_type_vector event_types;
60 } sensor_rep;
61
62 class sensor_client_info {
63 public:
64         static sensor_client_info& get_instance(void);
65         int create_handle(sensor_id_t sensor_id);
66         bool delete_handle(int handle);
67         bool register_event(int handle, unsigned int event_type,
68                         unsigned int interval, unsigned int latency, int cb_type, void *cb, void* user_data);
69         bool unregister_event(int handle, unsigned int event_type);
70
71         bool register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void* user_data);
72         bool unregister_accuracy_cb(int handle);
73
74         bool set_sensor_params(int handle, int sensor_state, int sensor_option);
75         bool get_sensor_params(int handle, int &sensor_state, int &sensor_option);
76         bool set_sensor_state(int handle, int sensor_state);
77         bool set_sensor_option(int handle, int sensor_option);
78         bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency);
79         bool set_event_maincontext(int handle, unsigned int event_type, GMainContext *maincontext);
80         bool set_accuracy(int handle, int accuracy);
81         bool set_bad_accuracy(int handle, int bad_accuracy);
82         bool get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, int &cb_type, void* &cb, void* &user_data);
83         void get_listening_sensors(sensor_id_vector &sensors);
84         void get_sensor_rep(sensor_id_t sensor, sensor_rep& rep);
85
86         bool get_active_batch(sensor_id_t sensor, unsigned int &interval, unsigned int &latency);
87         unsigned int get_active_option(sensor_id_t sensor_id);
88         void get_active_event_types(sensor_id_t sensor_id, event_type_vector &active_event_types);
89
90         bool get_sensor_id(int handle, sensor_id_t &sensor_id);
91         bool get_sensor_state(int handle, int &state);
92         bool get_sensor_wakeup(int handle, int &sensor_wakeup);
93         bool set_sensor_wakeup(int handle, int sensor_wakeup);
94
95         bool has_client_id(void);
96         int get_client_id(void);
97         void set_client_id(int client_id);
98
99         bool is_active(void);
100         bool is_sensor_registered(sensor_id_t sensor_id);
101         bool is_sensor_active(sensor_id_t sensor_id);
102         bool is_event_active(int handle, unsigned int event_type, unsigned long long event_id);
103
104         bool add_command_channel(sensor_id_t sensor_id, command_channel *cmd_channel);
105         bool get_command_channel(sensor_id_t sensor_id, command_channel **cmd_channel);
106         bool close_command_channel(void);
107         bool close_command_channel(sensor_id_t sensor_id);
108
109         void get_all_handles(handle_vector &handles);
110         void get_sensor_handle_info(sensor_id_t sensor, sensor_handle_info_map &handles_info);
111         void get_all_handle_info(sensor_handle_info_map &handles_info);
112
113         void clear(void);
114
115         sensor_client_info();
116         ~sensor_client_info();
117
118 private:
119         sensor_handle_info_map m_sensor_handle_infos;
120         sensor_command_channel_map m_command_channels;
121
122         int m_client_id;
123
124         cmutex m_handle_info_lock;
125 };
126 #endif /* _SENSOR_CLIENT_INFO_H_ */