4 * Copyright (c) 2015 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>
28 #include <sf_common.h>
31 #include <unordered_map>
36 #include <condition_variable>
38 #include <sensor_handle_info.h>
39 #include <command_channel.h>
41 using std::unordered_map;
46 using std::lock_guard;
47 using std::unique_lock;
48 using std::condition_variable;
50 typedef vector<unsigned int> handle_vector;
51 typedef vector<sensor_id_t> sensor_id_vector;
52 typedef unordered_map<int,sensor_handle_info> sensor_handle_info_map;
53 typedef unordered_map<sensor_id_t, command_channel*> sensor_command_channel_map;
55 typedef struct sensor_rep
59 unsigned int interval;
61 event_type_vector event_types;
64 class sensor_client_info {
66 static sensor_client_info& get_instance(void);
67 int create_handle(sensor_id_t sensor_id);
68 bool delete_handle(int handle);
69 bool register_event(int handle, unsigned int event_type,
70 unsigned int interval, unsigned int latency, int cb_type, void *cb, void* user_data);
71 bool unregister_event(int handle, unsigned int event_type);
73 bool register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void* user_data);
74 bool unregister_accuracy_cb(int handle);
76 bool set_sensor_params(int handle, int sensor_state, int sensor_option);
77 bool get_sensor_params(int handle, int &sensor_state, int &sensor_option);
78 bool set_sensor_state(int handle, int sensor_state);
79 bool set_sensor_option(int handle, int sensor_option);
80 bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency);
81 bool set_event_maincontext(int handle, unsigned int event_type, GMainContext *maincontext);
82 bool set_accuracy(int handle, int accuracy);
83 bool set_bad_accuracy(int handle, int bad_accuracy);
84 bool get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, int &cb_type, void* &cb, void* &user_data);
85 void get_listening_sensors(sensor_id_vector &sensors);
86 void get_sensor_rep(sensor_id_t sensor, sensor_rep& rep);
88 bool get_active_batch(sensor_id_t sensor, unsigned int &interval, unsigned int &latency);
89 unsigned int get_active_option(sensor_id_t sensor_id);
90 void get_active_event_types(sensor_id_t sensor_id, event_type_vector &active_event_types);
92 bool get_sensor_id(int handle, sensor_id_t &sensor_id);
93 bool get_sensor_state(int handle, int &state);
94 bool get_sensor_wakeup(int handle, int &sensor_wakeup);
95 bool set_sensor_wakeup(int handle, int sensor_wakeup);
97 bool has_client_id(void);
98 int get_client_id(void);
99 void set_client_id(int client_id);
101 bool is_active(void);
102 bool is_sensor_registered(sensor_id_t sensor_id);
103 bool is_sensor_active(sensor_id_t sensor_id);
104 bool is_event_active(int handle, unsigned int event_type, unsigned long long event_id);
106 bool add_command_channel(sensor_id_t sensor_id, command_channel *cmd_channel);
107 bool get_command_channel(sensor_id_t sensor_id, command_channel **cmd_channel);
108 bool close_command_channel(void);
109 bool close_command_channel(sensor_id_t sensor_id);
111 void get_all_handles(handle_vector &handles);
112 void get_sensor_handle_info(sensor_id_t sensor, sensor_handle_info_map &handles_info);
113 void get_all_handle_info(sensor_handle_info_map &handles_info);
117 sensor_client_info();
118 ~sensor_client_info();
121 sensor_handle_info_map m_sensor_handle_infos;
122 sensor_command_channel_map m_command_channels;
126 cmutex m_handle_info_lock;
128 #endif /* _SENSOR_CLIENT_INFO_H_ */