4 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #ifndef _SENSOR_CLIENT_INFO_H_
21 #define _SENSOR_CLIENT_INFO_H_
24 #include <sys/types.h>
30 #include <unordered_map>
33 #include <sensor_handle_info.h>
34 #include <command_channel.h>
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;
41 typedef struct sensor_rep {
44 unsigned int interval;
46 event_type_vector event_types;
49 class sensor_client_info {
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);
58 bool register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void* user_data);
59 bool unregister_accuracy_cb(int handle);
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);
65 bool get_passive_mode(int handle);
66 bool set_passive_mode(int handle, bool passive);
68 bool set_attribute(int handle, int attribute, int value);
69 bool set_attribute(int handle, int attribute, std::string value);
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);
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);
83 bool get_sensor_id(int handle, sensor_id_t &sensor_id);
84 bool get_sensor_state(int handle, int &state);
86 bool has_client_id(void);
87 int get_client_id(void);
88 void set_client_id(int client_id);
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);
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);
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);
104 void set_pause_policy(sensor_id_t sensor, int power_save_state);
108 sensor_client_info();
109 ~sensor_client_info();
112 sensor_handle_info_map m_sensor_handle_infos;
113 sensor_command_channel_map m_command_channels;
117 cmutex m_handle_info_lock;
120 #endif /* _SENSOR_CLIENT_INFO_H_ */