4 * Copyright (c) 2013 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 #include "sensor_internal.h"
22 #include <sensor_log.h>
28 * 1.2 listener : start, interval, batch latency, attributes
29 * 2. power save option / lcd vconf : move to server
31 * 4. thread-safe : ipc_client
34 * 7. stop : unset interval, batch
38 API int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *count)
41 * 1. get sensor list()
42 * 2. if sensor list is empty, return -ENODATA
43 * 3. if id is -EACCESS, return -EACCESS (except ALL_SENSOR)
44 * 4. list : memory allocation
45 * 5. return list, count
51 API int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor)
54 * 1. get sensor list()
55 * 2. if there is no sensor, return -ENODATA
56 * 3. if id is -EACCESS, return -EACCESS
57 * 4. if SENSOR_ALL, ???
64 API bool sensord_get_type(sensor_t sensor, sensor_type_t *type)
68 * 2. if there is no sensor, return false
74 API const char* sensord_get_name(sensor_t sensor)
77 * 1. if there is no sensor, return NULL
83 API const char* sensord_get_vendor(sensor_t sensor)
86 * 1. if there is no sensor, return NULL
92 API bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege)
96 * 2. if there is no sensor, return false
102 API bool sensord_get_min_range(sensor_t sensor, float *min_range)
106 * 2. if there is no sensor, return false
112 API bool sensord_get_max_range(sensor_t sensor, float *max_range)
116 * 2. if there is no sensor, return false
122 API bool sensord_get_resolution(sensor_t sensor, float *resolution)
126 * 2. if there is no sensor, return false
132 API bool sensord_get_min_interval(sensor_t sensor, int *min_interval)
136 * 2. if there is no sensor, return false
142 API bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count)
146 * 2. if there is no sensor, return false
152 API bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count)
156 * 2. if there is no sensor, return false
162 API bool sensord_is_wakeup_supported(sensor_t sensor)
166 * 2. if there is no sensor, return false
172 API int sensord_connect(sensor_t sensor)
176 * 2. if there is no sensor, return -EPERM
177 * 3. sensor is already registered(sensor), it doesn't need to connect server
178 * 4. create integer handle for only this client
179 * 5. if it is first connection(client), get client id from server
180 * 6. if it is first connection(client), start sensor event listener
181 * 7. sensor initialization : stop, pause_all
182 * 8. if it is first connection(client), send cmd hello
183 * 9. if cmd hello is failed and it is first connection(client) stop listener, remove id
189 API bool sensord_disconnect(int handle)
192 * 1. check parameter(check handle???)
193 * 2. check state of this handle
194 * 3. if it is on passive mode, unregister event and unset interval/latency
195 * 4. if it is not stop, stop it
196 * 5. if there is no active sensor(client), reset id & byebye and stop listener
202 API bool sensord_register_event(int handle, unsigned int event_type,
203 unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data)
207 * 2. if interval is 0, default interval
208 * ** if cb is null, how to handle it?
209 * ** event type is deprecated
215 API bool sensord_unregister_event(int handle, unsigned int event_type)
219 * 2. check previous interval, latency, cb, user_data
220 * 3. if passive mode is true, set false
221 * 4. if ret is false, register event
227 API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data)
236 API bool sensord_unregister_accuracy_cb(int handle)
245 API bool sensord_start(int handle, int option)
249 * 2. pause = CONVERT_OPTION_PAUSE_POLICY(option)
256 API bool sensord_stop(int handle)
260 * 2. check sensor state, id
261 * 2.1. if sensor is already stopped, return true
268 API bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval)
272 * 2. if interval is 0, default interval
273 * 3. if previous interval is lower than interval, return true
280 API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency)
284 * 2. if previous interval is lower than interval, return true
285 * 3. change batch latency
291 API bool sensord_set_option(int handle, int option)
294 * change option, always-on/power save option/lcd off/default
300 API int sensord_set_attribute_int(int handle, int attribute, int value)
303 * 1. if ATTRIBUTE_PAUSE_POLICY
304 * 2. if ATTRIBUTE_AXIS_ORIENTATION
311 API int sensord_set_attribute_str(int handle, int attribute, const char *value, int len)
315 * 2. if client id is invalid, return -EPERM
316 * 3. if there is other problems, return -EPERM
322 API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data)
326 * 2. check sensor state(is it really needed?)
333 API bool sensord_flush(int handle)
337 * 2. check sensor state(is it really needed?)
344 API bool sensord_set_passive_mode(int handle, bool passive)
346 /* set passive mode*/
351 API int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data)
355 * 2. create handle in this client
356 * 3. first connection(client)
357 * 4. cmd_connect for external sensor with key
359 retvm_if(!key, -EPERM, "Invalid key");
363 API bool sensord_external_disconnect(int handle)
367 * 2. create handle in this client
368 * 3. first connection(client)
369 * 4. cmd_connect for external sensor with key
370 * 5. disconnect this handle
371 * 6. if there is no active sensor, remove client id and stop listener
376 API bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt)
380 * 1.1 (data_cnt <= 0) || (data_cnt > POST_DATA_LEN_MAX)), return false
388 API sensor_t sensord_get_sensor(sensor_type_t type)
394 API bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count)
396 return (sensord_get_sensors(type, list, sensor_count) == OP_SUCCESS);
400 API bool sensord_register_hub_event(int handle, unsigned int event_type,
401 unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data)
407 API bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count)
411 * 2. if there is no sensor, return false
412 * 3. memory allocation
417 /* deprecated(BUT it is used in C-API....) */
418 API bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported)
422 * 2. if there is no sensor, return false
428 API bool sensord_send_sensorhub_data(int handle, const char *data, int data_len)
430 return (sensord_set_attribute_str(handle, 0, data, data_len) == OP_SUCCESS);
434 API bool sensord_send_command(int handle, const char *command, int command_len)
436 return (sensord_set_attribute_str(handle, 0, command, command_len) == OP_SUCCESS);