sensord: restore attributes after sensor daemon is restarted
[platform/core/system/sensord.git] / src / client / sensor_client_info.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_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 <cmutex.h>
33 #include <sensor_handle_info.h>
34 #include <command_channel.h>
35
36 typedef std::vector<unsigned int> handle_vector;
37 typedef std::vector<sensor_id_t> sensor_id_vector;
38 typedef std::unordered_map<int, sensor_handle_info> sensor_handle_info_map;
39 typedef std::unordered_map<sensor_id_t, command_channel *> sensor_command_channel_map;
40
41 typedef struct sensor_rep {
42         bool active;
43         int pause_policy;
44         unsigned int interval;
45         unsigned int latency;
46         event_type_vector event_types;
47 } sensor_rep;
48
49 class sensor_client_info {
50 public:
51         static sensor_client_info& get_instance(void);
52         int create_handle(sensor_id_t sensor_id);
53         bool delete_handle(int handle);
54         bool register_event(int handle, unsigned int event_type,
55                         unsigned int interval, unsigned int latency, void *cb, void* user_data);
56         bool unregister_event(int handle, unsigned int event_type);
57
58         bool register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void* user_data);
59         bool unregister_accuracy_cb(int handle);
60
61         bool set_sensor_params(int handle, int sensor_state, int sensor_pause_policy);
62         bool get_sensor_params(int handle, int &sensor_state, int &sensor_pause_policy);
63         bool set_sensor_state(int handle, int sensor_state);
64
65         bool get_passive_mode(int handle);
66         bool set_passive_mode(int handle, bool passive);
67
68         bool set_attribute(int handle, int attribute, int value);
69         bool set_attribute(int handle, int attribute, std::string value);
70
71         bool set_sensor_pause_policy(int handle, int pause_policy);
72         bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency);
73         bool set_accuracy(int handle, int accuracy);
74         bool set_bad_accuracy(int handle, int bad_accuracy);
75         bool get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, void* &cb, void* &user_data);
76         void get_listening_sensors(sensor_id_vector &sensors);
77         void get_sensor_rep(sensor_id_t sensor, sensor_rep& rep);
78
79         bool get_active_batch(sensor_id_t sensor, unsigned int &interval, unsigned int &latency);
80         unsigned int get_active_pause_policy(sensor_id_t sensor_id);
81         void get_active_event_types(sensor_id_t sensor_id, event_type_vector &active_event_types);
82
83         bool get_sensor_id(int handle, sensor_id_t &sensor_id);
84         bool get_sensor_state(int handle, int &state);
85
86         bool has_client_id(void);
87         int get_client_id(void);
88         void set_client_id(int client_id);
89
90         bool is_active(void);
91         bool is_sensor_registered(sensor_id_t sensor_id);
92         bool is_sensor_active(sensor_id_t sensor_id);
93         bool is_event_active(int handle, unsigned int event_type, unsigned long long event_id);
94
95         bool add_command_channel(sensor_id_t sensor_id, command_channel *cmd_channel);
96         bool get_command_channel(sensor_id_t sensor_id, command_channel **cmd_channel);
97         bool close_command_channel(void);
98         bool close_command_channel(sensor_id_t sensor_id);
99
100         void get_all_handles(handle_vector &handles);
101         void get_sensor_handle_info(sensor_id_t sensor, sensor_handle_info_map &handles_info);
102         void get_all_handle_info(sensor_handle_info_map &handles_info);
103
104         void set_pause_policy(sensor_id_t sensor, int power_save_state);
105
106         void clear(void);
107
108         sensor_client_info();
109         ~sensor_client_info();
110
111 private:
112         sensor_handle_info_map m_sensor_handle_infos;
113         sensor_command_channel_map m_command_channels;
114
115         int m_client_id;
116
117         cmutex m_handle_info_lock;
118 };
119
120 #endif /* _SENSOR_CLIENT_INFO_H_ */