summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaeminYeom <taemin.yeom@samsung.com>2022-07-07 15:09:25 +0900
committerTaeminYeom <taemin.yeom@samsung.com>2022-07-07 16:19:45 +0900
commit5057351d922eeeed99ed35d972d8dfd604e3426f (patch)
tree5e36fbc06c3921d3055283555d242ef51e6c1f16
parent6e0837fbecf9d4201f6d4a79973f3059a1bcd996 (diff)
downloadsensor-5057351d922eeeed99ed35d972d8dfd604e3426f.tar.gz
sensor-5057351d922eeeed99ed35d972d8dfd604e3426f.tar.bz2
sensor-5057351d922eeeed99ed35d972d8dfd604e3426f.zip
Change the name of header files
Fix the style of name sensor-xxx.h Merge sensor_internal.h into sensor-internal.h Change-Id: I7beddf55788172884670b978ee431c8ea4892eb5 Signed-off-by: TaeminYeom <taemin.yeom@samsung.com>
-rw-r--r--include/sensor-internal.h508
-rw-r--r--include/sensor-log.h (renamed from include/sensor_log.h)0
-rw-r--r--include/sensor-private.h (renamed from include/sensor_private.h)0
-rw-r--r--include/sensor-types.h (renamed from include/sensor_types.h)0
-rw-r--r--include/sensor_internal.h545
-rw-r--r--src/api/sensor-internal.cpp1180
-rw-r--r--src/api/sensor.cpp10
-rw-r--r--src/api/sensor_internal.cpp1197
-rw-r--r--src/api/sensor_listener.cpp4
-rw-r--r--src/api/sensor_listener.h2
-rw-r--r--src/api/sensor_manager.cpp2
-rw-r--r--src/api/sensor_manager.h2
-rw-r--r--src/api/sensor_manager_channel_handler.cpp2
-rw-r--r--src/api/sensor_manager_channel_handler.h2
-rw-r--r--src/api/sensor_provider.cpp8
-rw-r--r--src/api/sensor_provider_channel_handler.cpp2
-rw-r--r--src/api/sensor_provider_channel_handler.h2
-rw-r--r--src/api/sensor_provider_internal.cpp4
-rw-r--r--src/api/sensor_provider_internal.h4
-rw-r--r--src/api/sensor_reader.cpp4
-rw-r--r--src/api/sensor_recorder/sensor_recorder.cpp2
-rw-r--r--src/api/sensor_recorder/sensor_recorder_dummy.cpp2
-rw-r--r--src/shared/accept_event_handler.cpp2
-rw-r--r--src/shared/cbase_lock.cpp2
-rw-r--r--src/shared/channel.cpp2
-rw-r--r--src/shared/channel_event_handler.cpp2
-rw-r--r--src/shared/cmutex.cpp2
-rw-r--r--src/shared/command_types.h2
-rw-r--r--src/shared/event_loop.cpp2
-rw-r--r--src/shared/ipc_client.cpp2
-rw-r--r--src/shared/ipc_server.cpp2
-rw-r--r--src/shared/message.cpp2
-rw-r--r--src/shared/sensor_info.cpp4
-rw-r--r--src/shared/sensor_info.h2
-rw-r--r--src/shared/sensor_utils.cpp4
-rw-r--r--src/shared/sensor_utils.h2
-rw-r--r--src/shared/seqpacket_socket.cpp2
-rw-r--r--src/shared/socket.cpp2
-rw-r--r--src/shared/stream_socket.cpp2
39 files changed, 1730 insertions, 1790 deletions
diff --git a/include/sensor-internal.h b/include/sensor-internal.h
index 04ef69a..bb32f54 100644
--- a/include/sensor-internal.h
+++ b/include/sensor-internal.h
@@ -17,9 +17,21 @@
#ifndef __SENSOR_INTERNAL_H__
#define __SENSOR_INTERNAL_H__
+#ifndef API
+#define API __attribute__((visibility("default")))
+#endif
+
+#include <stdbool.h>
+#include <sys/types.h>
+#include <limits.h>
+
+/*header for common sensor type*/
+#include <sensor-types.h>
#include <sensor.h>
#include <hal-sensor-types.h>
+#define SENSOR_BATCH_LATENCY_DEFAULT UINT_MAX
+
#ifdef __cplusplus
extern "C"
{
@@ -29,6 +41,496 @@ typedef enum {
SENSOR_LIDAR = 1000,
} sensor_type_internel_e;
+typedef void (*sensor_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data);
+typedef void (*sensor_events_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t events[], int events_count, void *user_data);
+typedef void (*sensorhub_cb_t)(sensor_t sensor, unsigned int event_type, sensorhub_data_t *data, void *user_data);
+typedef void (*sensor_accuracy_changed_cb_t) (sensor_t sensor, unsigned long long timestamp, int accuracy, void *user_data);
+typedef void (*sensor_attribute_int_changed_cb_t)(sensor_t sensor, int attribute, int value, void *user_data);
+typedef void (*sensor_attribute_str_changed_cb_t)(sensor_t sensor, int attribute, const char *value, int len, void *user_data);
+
+/**
+ * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors.
+ *
+ * @param[in] type the type of sensors requested.
+ * @param[out] list the list of sensors matching the asked type, the caller should explicitly free this list.
+ * @param[out] sensor count the count of sensors contained in the list.
+ * @return true on success, otherwise false.
+ */
+bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count);
+
+/**
+ * @brief Get the default sensor for a given type.
+ *
+ * @param[in] type the type of a sensor requested.
+ * @return the default sensor matching the asked type on success, otherwise NULL.
+ */
+sensor_t sensord_get_sensor(sensor_type_t type);
+
+/**
+ * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors.
+ *
+ * @param[in] type the type of sensors requested.
+ * @param[out] list the list of sensors matching the asked type, the caller should explicitly free this list.
+ * @param[out] sensor count the count of sensors contained in the list.
+ * @return 0 on success, otherwise a negative error value
+ * @retval 0 Successful
+ * @retval -EPERM Operation not permitted
+ * @retval -EACCES Permission denied
+ * @retval -ENODATA NO sensor available
+ */
+int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count);
+
+/**
+ * @brief Get the default sensor for a given type.
+ *
+ * @param[in] type the type of a sensor requested.
+ * @param[out] a sensor matching the asked type.
+ * @return 0 on success, otherwise a negative error value
+ * @retval 0 Successful
+ * @retval -EPERM Operation not permitted
+ * @retval -EACCES Permission denied
+ */
+int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor);
+
+/**
+ * @brief Get the type of this sensor.
+ *
+ * @param[in] sensor a sensor to get type.
+ * @param[out] type the type of this sensor.
+ * @return return true on success, otherwise false.
+ */
+bool sensord_get_type(sensor_t sensor, sensor_type_t *type);
+
+/**
+ * @brief Get the URI string of this sensor.
+ *
+ * @param[in] sensor a sensor to get uri.
+ * @return the name string of this sensor on success, otherwise NULL.
+ */
+const char* sensord_get_uri(sensor_t sensor);
+
+/**
+ * @brief Get the name string of this sensor.
+ *
+ * @param[in] sensor a sensor to get name.
+ * @return the name string of this sensor on success, otherwise NULL.
+ */
+const char* sensord_get_name(sensor_t sensor);
+
+/**
+ * @brief Get the vendor string of this sensor.
+ *
+ * @param[in] sensor a sensor to get vendor.
+ * @return the vendor string of this sensor on success, otherwise NULL.
+ */
+const char* sensord_get_vendor(sensor_t sensor);
+
+/**
+ * @brief Get the privilege of this sensor.
+ *
+ * @param[in] sensor a sensor to get privilege.
+ * @param[out] privilege the privilege of this sensor.
+ * @return true on success, otherwise false.
+ */
+bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege);
+
+/**
+ * @brief Get the minimum range of this sensor in the sensor's unit.
+ *
+ * @param[in] sensor a sensor to get minimum range.
+ * @param[out] min_range the minimum range of this sensor in the sensor's unit.
+ * @return true on success, otherwise false.
+ */
+bool sensord_get_min_range(sensor_t sensor, float *min_range);
+
+/**
+ * @brief Get the maximum range of this sensor in the sensor's unit.
+ *
+ * @param[in] sensor a sensor to get maximum range.
+ * @param[out] max_range the maximum range of this sensor in the sensor's unit.
+ * @return true on success, otherwise false.
+ */
+bool sensord_get_max_range(sensor_t sensor, float *max_range);
+
+/**
+ * @brief Get the resolution of this sensor in the sensor's unit.
+ *
+ * @param[in] sensor a sensor to get resolution.
+ * @param[out] resolution the resolution of this sensor in the sensor's unit.
+ * @return true on success, otherwise false.
+ */
+bool sensord_get_resolution(sensor_t sensor, float *resolution);
+
+/**
+ * @brief Get the minimum interval allowed between two events in microsecond or zero if this sensor only returns a value when the data it's measuring changes.
+ *
+ * @param[in] sensor a sensor to get minimum interval.
+ * @param[out] min_interval the minimum interval of this sensor.
+ * @return true on success, otherwise false.
+ */
+bool sensord_get_min_interval(sensor_t sensor, int *min_interval);
+
+/**
+ * @brief Get the number of events reserved for this sensor in the batch mode FIFO.
+ *
+ * @param[in] sensor a sensor to get the number of fifo count
+ * @param[out] fifo_count the number of events reserved for this sensor in the batch mode FIFO
+ * @return true on success, otherwise false
+ */
+bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count);
+
+/**
+ * @brief Get the maximum number of events of this sensor that could be batched. If this value is zero it indicates that batch mode is not supported for this sensor.
+ *
+ * @param[in] sensor a sensor to the maximum number of events that could be batched.
+ * @param[out] max_batch_count the maximum number of events of this sensor that could be batched.
+ * @return true on success, otherwise false.
+ */
+bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count);
+
+/**
+ * @brief Get the supported event types of this sensor.
+ *
+ * @param[in] sensor a sensor to get the supported event types.
+ * @param[out] event_types the array containing supported event types of this sensor, the caller should explicitly free this array.
+ * @param[out] count the count of the supported event types of this sensor.
+ * @return true on success, otherwise false.
+ */
+bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count);
+
+/**
+ * @brief Check a given event type is supporeted by this sensor.
+ *
+ * @param[in] sensor a sensor to check a given event type is supporeted.
+ * @param[out] event_type an event type to be checked whether supported or not.
+ * @param[out] supported whether a given event is supported or not in this sensor.
+ * @return true on success, otherwise false.
+ */
+bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported);
+
+/**
+ * @brief Check a wakeup supported or not by this sensor.
+ *
+ * @param[in] sensor a sensor to check a given event type is supporeted.
+ * @return true on success, otherwise false.
+ */
+bool sensord_is_wakeup_supported(sensor_t sensor);
+
+/**
+ * @brief Connect a given sensor and get a handle of a given sensor.
+ *
+ * @param[in] sensor a sensor to connect
+ * @return a handle of a given sensor on success, otherwise negative value
+ */
+int sensord_connect(sensor_t sensor);
+
+/**
+ * @brief Disconnect a given sensor.
+ *
+ * @param[in] handle a handle to disconnect.
+ * @return true on success, otherwise false.
+ */
+bool sensord_disconnect(int handle);
+
+/**
+ * @brief Register a callback with a connected sensor for a given event_type. This callback will be called when a given event occurs in a connected sensor.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] event_type an event type to register
+ * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval.
+ * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds.
+ * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
+ * @param[in] cb a callback which is called when a given event occurs
+ * @param[in] user_data the callback is called with user_data
+ * @return true on success, otherwise false.
+ */
+bool sensord_register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data);
+
+/**
+ * @brief Register a callback with a connected sensor for a given event_type. This callback will be called when a given event occurs in a connected sensor.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] event_type an event type to register
+ * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
+ * @param[in] cb a callback which is called when a given event occurs
+ * @param[in] user_data the callback is called with user_data
+ * @return true on success, otherwise false.
+ */
+bool sensord_register_events(int handle, unsigned int event_type, unsigned int max_batch_latency, sensor_events_cb_t cb, void *user_data);
+
+/**
+ * @brief Register a callback with a connected context sensor for a given event_type. This callback will be called when a given event occurs in a connected context sensor.
+ *
+ * @param[in] handle a handle represensting a connected context sensor.
+ * @param[in] event_type an event type to register
+ * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval.
+ * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds.
+ * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
+ * @param[in] cb a callback which is called when a given event occurs
+ * @param[in] user_data the callback is called with user_data
+ * @return true on success, otherwise false.
+ */
+bool sensord_register_hub_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data);
+
+/**
+ * @brief Unregister a event with a connected sensor. After unregistering, that event will not be sent.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] event_type an event type to unregister.
+ * @return true on success, otherwise false.
+ */
+bool sensord_unregister_event(int handle, unsigned int event_type);
+
+/**
+ * @brief Unregister a event with a connected sensor. After unregistering, that event will not be sent.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] event_type an event type to unregister.
+ * @return true on success, otherwise false.
+ */
+bool sensord_unregister_events(int handle, unsigned int event_type);
+
+/**
+ * @brief Register a callback with a connected sensor. This callback will be called when the accuracy of a sensor has changed.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] cb a callback which is called when he accuracy of a sensor has changed.
+ * @param[in] user_data the callback is called with user_data
+ * @return true on success, otherwise false.
+ */
+bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data);
+
+/**
+ * @brief Unregister a callback with a connected sensor. After unregistering, sensor_accuray_change_cb will not be called.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @return true on success, otherwise false.
+ */
+bool sensord_unregister_accuracy_cb(int handle);
+
+/**
+ * @brief Register a callback with a connected sensor. This callback will be called when attributes of a sensor has changed.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] cb a callback which is called when he attributes of a sensor has changed.
+ * @param[in] user_data the callback is called with user_data
+ * @return true on success, otherwise false.
+ */
+bool sensord_register_attribute_int_changed_cb(int handle, sensor_attribute_int_changed_cb_t cb, void *user_data);
+
+/**
+ * @brief Unregister a callback with a connected sensor. After unregistering, sensor_attribute_int_changed_cb will not be called.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @return true on success, otherwise false.
+ */
+bool sensord_unregister_attribute_int_changed_cb(int handle);
+
+/**
+ * @brief Register a callback with a connected sensor. This callback will be called when attributes of a sensor has changed.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] cb a callback which is called when he attributes of a sensor has changed.
+ * @param[in] user_data the callback is called with user_data
+ * @return true on success, otherwise false.
+ */
+bool sensord_register_attribute_str_changed_cb(int handle, sensor_attribute_str_changed_cb_t cb, void *user_data);
+
+/**
+ * @brief Unregister a callback with a connected sensor. After unregistering, sensor_attribute_str_changed_cb will not be called.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @return true on success, otherwise false.
+ */
+bool sensord_unregister_attribute_str_changed_cb(int handle);
+
+/**
+ * @brief Start listening events with a connected sensor.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] option either one of SENSOR_OPTION_DEFAULT and SENSOR_OPTION_ALWAYS_ON.
+ * with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
+ * with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
+ * @return true on success, otherwise false.
+ */
+bool sensord_start(int handle, int option);
+
+/**
+ * @brief Stop listening events with a connected sensor.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @return true on success, otherwise false.
+ */
+bool sensord_stop(int handle);
+
+/**
+ * @brief Change the interval of a specifed event type in a connected sensor.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] event_type an event type to change interval.
+ * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval.
+ * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds.
+ * @return true on success, otherwise false.
+ */
+bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval);
+
+/**
+ * @brief Change the max batch latency of a specifed event type in a connected sensor.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] event_type an event type to change max batch latency
+ * @param[in] max_batch_latency an event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
+ * @return true on success, otherwise false.
+ */
+bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency);
+
+/**
+ * @brief Change the option of a connected sensor.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] option either one of SENSOR_OPTION_DEFAULT and SENSOR_OPTION_ALWAYS_ON.
+ * with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
+ * with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
+ * @return true on success, otherwise false.
+ */
+bool sensord_set_option(int handle, int option);
+
+/*
+ * @brief Set the attribute to a connected sensor
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] attribute an attribute to change
+ * @param[in] value an attribute value
+ * @return 0 on success, otherwise a negative error value
+ * @retval 0 Successful
+ * @retval -EINVAL Invalid parameter
+ * @retval -EPERM Operation not permitted
+ */
+int sensord_set_attribute_int(int handle, int attribute, int value);
+
+/*
+ * @brief Get the attribute to a connected sensor
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] attribute an attribute to get value
+ * @param[out] value an attribute value
+ * @return 0 on success, otherwise a negative error value
+ * @retval 0 Successful
+ * @retval -EINVAL Invalid parameter
+ * @retval -EPERM Operation not permitted
+ */
+int sensord_get_attribute_int(int handle, int attribute, int* value);
+
+/**
+ * @brief Set the attribute to a connected sensor
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] attribute an attribute to change
+ * @param[in] value an attribute value
+ * @param[in] value_len the length of value
+ * @return 0 on success, otherwise a negative error value
+ * @retval 0 Successful
+ * @retval -EINVAL Invalid parameter
+ * @retval -EPERM Operation not permitted
+ */
+int sensord_set_attribute_str(int handle, int attribute, const char *value, int len);
+
+/**
+ * @brief Get the attribute to a connected sensor
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] attribute an attribute to get value
+ * @param[out] value an attribute value, the caller should explicitly free this value
+ * @param[out] len the length of value
+ * @return 0 on success, otherwise a negative error value
+ * @retval 0 Successful
+ * @retval -EINVAL Invalid parameter
+ * @retval -EPERM Operation not permitted
+ */
+int sensord_get_attribute_str(int handle, int attribute, char **value, int *len);
+
+/**
+ * @brief Send data to sensorhub
+ *
+ * @param[in] handle a handle represensting a connected context sensor.
+ * @param[in] data it holds data to send to sensorhub
+ * @param[in] data_len the length of data
+ * @return true on success, otherwise false.
+ */
+bool sensord_send_sensorhub_data(int handle, const char *data, int data_len);
+bool sensord_send_command(int handle, const char *command, int command_len);
+
+/**
+ * @brief get sensor data from a connected sensor
+ *
+ * @param[in] handle a handle represensting a connected context sensor.
+ * @param[in] data_id it specifies data to get
+ * @param[out] sensor_data data from connected sensor
+ * @return true on success, otherwise false.
+ */
+bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data);
+
+/**
+ * @brief get sensor data from a connected sensor
+ *
+ * @param[in] handle a handle represensting a connected context sensor.
+ * @param[in] data_id it specifies data to get
+ * @param[out] sensor_data the data list from connected sensor, the caller should explicitly free this list.
+ * @param[out] count the count of data contained in the list.
+ * @return true on success, otherwise false.
+ */
+bool sensord_get_data_list(int handle, unsigned int data_id, sensor_data_t** sensor_data, int* count);
+
+/**
+ * @brief flush sensor data from a connected sensor
+ *
+ * @param[in] handle a handle represensting a connected context sensor.
+ * @return true on success, otherwise false.
+ */
+bool sensord_flush(int handle);
+
+bool sensord_set_passive_mode(int handle, bool passive);
+
+
+/* Sensor Internal API using URI */
+int sensord_get_default_sensor_by_uri(const char *uri, sensor_t *sensor);
+int sensord_get_sensors_by_uri(const char *uri, sensor_t **list, int *sensor_count);
+
+typedef void (*sensord_added_cb)(const char *uri, void *user_data);
+int sensord_add_sensor_added_cb(sensord_added_cb callback, void *user_data);
+int sensord_remove_sensor_added_cb(sensord_added_cb callback);
+
+typedef void (*sensord_removed_cb)(const char *uri, void *user_data);
+int sensord_add_sensor_removed_cb(sensord_removed_cb callback, void *user_data);
+int sensord_remove_sensor_removed_cb(sensord_removed_cb callback);
+
+/* Sensor provider */
+typedef void *sensord_provider_h;
+int sensord_create_provider(const char *uri, sensord_provider_h *provider);
+int sensord_destroy_provider(sensord_provider_h provider);
+int sensord_add_provider(sensord_provider_h provider);
+int sensord_remove_provider(sensord_provider_h provider);
+
+int sensord_provider_set_name(sensord_provider_h provider, const char *name);
+int sensord_provider_set_vendor(sensord_provider_h provider, const char *vendor);
+int sensord_provider_set_range(sensord_provider_h provider, float min_range, float max_range);
+int sensord_provider_set_resolution(sensord_provider_h provider, float resolution);
+
+typedef void (*sensord_provider_start_cb)(sensord_provider_h provider, void *user_data);
+int sensord_provider_set_start_cb(sensord_provider_h provider, sensord_provider_start_cb callback, void *user_data);
+
+typedef void (*sensord_provider_stop_cb)(sensord_provider_h provider, void *user_data);
+int sensord_provider_set_stop_cb(sensord_provider_h provider, sensord_provider_stop_cb callback, void *user_data);
+
+typedef void (*sensord_provider_interval_changed_cb)(sensord_provider_h provider, unsigned int interval_ms, void *user_data);
+int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, sensord_provider_interval_changed_cb callback, void *user_data);
+
+typedef void (*sensord_provider_attribute_str_cb)(sensord_provider_h provider, int attribute, const char *value, int count, void *user_data);
+int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data);
+
+int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data);
+int sensord_provider_publish_events(sensord_provider_h provider, sensor_data_t events[], int count);
+
/**
* @brief Set the attribute to a connected sensor
*
@@ -55,6 +557,12 @@ int sensor_util_set_attribute_int(sensor_type_e type, sensor_attribute_e attr, i
*/
int sensor_util_get_attribute_int(sensor_type_e type, sensor_attribute_e attr, int *value);
+/* Deprecated */
+typedef void (*sensor_external_command_cb_t)(int handle, const char* data, int data_cnt, void *user_data);
+int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data);
+bool sensord_external_disconnect(int handle);
+bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/sensor_log.h b/include/sensor-log.h
index 3904e13..3904e13 100644
--- a/include/sensor_log.h
+++ b/include/sensor-log.h
diff --git a/include/sensor_private.h b/include/sensor-private.h
index 7d99272..7d99272 100644
--- a/include/sensor_private.h
+++ b/include/sensor-private.h
diff --git a/include/sensor_types.h b/include/sensor-types.h
index a2028d3..a2028d3 100644
--- a/include/sensor_types.h
+++ b/include/sensor-types.h
diff --git a/include/sensor_internal.h b/include/sensor_internal.h
deleted file mode 100644
index 477c8d7..0000000
--- a/include/sensor_internal.h
+++ /dev/null
@@ -1,545 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __SENSORD_INTERNAL_H__
-#define __SENSORD_INTERNAL_H__
-
-#ifndef API
-#define API __attribute__((visibility("default")))
-#endif
-
-#include <stdbool.h>
-#include <sys/types.h>
-#include <limits.h>
-
-/*header for common sensor type*/
-#include <sensor_types.h>
-
-#define SENSOR_BATCH_LATENCY_DEFAULT UINT_MAX
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-typedef void (*sensor_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data);
-typedef void (*sensor_events_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t events[], int events_count, void *user_data);
-typedef void (*sensorhub_cb_t)(sensor_t sensor, unsigned int event_type, sensorhub_data_t *data, void *user_data);
-typedef void (*sensor_accuracy_changed_cb_t) (sensor_t sensor, unsigned long long timestamp, int accuracy, void *user_data);
-typedef void (*sensor_attribute_int_changed_cb_t)(sensor_t sensor, int attribute, int value, void *user_data);
-typedef void (*sensor_attribute_str_changed_cb_t)(sensor_t sensor, int attribute, const char *value, int len, void *user_data);
-
-/**
- * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors.
- *
- * @param[in] type the type of sensors requested.
- * @param[out] list the list of sensors matching the asked type, the caller should explicitly free this list.
- * @param[out] sensor count the count of sensors contained in the list.
- * @return true on success, otherwise false.
- */
-bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count);
-
-/**
- * @brief Get the default sensor for a given type.
- *
- * @param[in] type the type of a sensor requested.
- * @return the default sensor matching the asked type on success, otherwise NULL.
- */
-sensor_t sensord_get_sensor(sensor_type_t type);
-
-/**
- * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors.
- *
- * @param[in] type the type of sensors requested.
- * @param[out] list the list of sensors matching the asked type, the caller should explicitly free this list.
- * @param[out] sensor count the count of sensors contained in the list.
- * @return 0 on success, otherwise a negative error value
- * @retval 0 Successful
- * @retval -EPERM Operation not permitted
- * @retval -EACCES Permission denied
- * @retval -ENODATA NO sensor available
- */
-int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count);
-
-/**
- * @brief Get the default sensor for a given type.
- *
- * @param[in] type the type of a sensor requested.
- * @param[out] a sensor matching the asked type.
- * @return 0 on success, otherwise a negative error value
- * @retval 0 Successful
- * @retval -EPERM Operation not permitted
- * @retval -EACCES Permission denied
- */
-int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor);
-
-/**
- * @brief Get the type of this sensor.
- *
- * @param[in] sensor a sensor to get type.
- * @param[out] type the type of this sensor.
- * @return return true on success, otherwise false.
- */
-bool sensord_get_type(sensor_t sensor, sensor_type_t *type);
-
-/**
- * @brief Get the URI string of this sensor.
- *
- * @param[in] sensor a sensor to get uri.
- * @return the name string of this sensor on success, otherwise NULL.
- */
-const char* sensord_get_uri(sensor_t sensor);
-
-/**
- * @brief Get the name string of this sensor.
- *
- * @param[in] sensor a sensor to get name.
- * @return the name string of this sensor on success, otherwise NULL.
- */
-const char* sensord_get_name(sensor_t sensor);
-
-/**
- * @brief Get the vendor string of this sensor.
- *
- * @param[in] sensor a sensor to get vendor.
- * @return the vendor string of this sensor on success, otherwise NULL.
- */
-const char* sensord_get_vendor(sensor_t sensor);
-
-/**
- * @brief Get the privilege of this sensor.
- *
- * @param[in] sensor a sensor to get privilege.
- * @param[out] privilege the privilege of this sensor.
- * @return true on success, otherwise false.
- */
-bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege);
-
-/**
- * @brief Get the minimum range of this sensor in the sensor's unit.
- *
- * @param[in] sensor a sensor to get minimum range.
- * @param[out] min_range the minimum range of this sensor in the sensor's unit.
- * @return true on success, otherwise false.
- */
-bool sensord_get_min_range(sensor_t sensor, float *min_range);
-
-/**
- * @brief Get the maximum range of this sensor in the sensor's unit.
- *
- * @param[in] sensor a sensor to get maximum range.
- * @param[out] max_range the maximum range of this sensor in the sensor's unit.
- * @return true on success, otherwise false.
- */
-bool sensord_get_max_range(sensor_t sensor, float *max_range);
-
-/**
- * @brief Get the resolution of this sensor in the sensor's unit.
- *
- * @param[in] sensor a sensor to get resolution.
- * @param[out] resolution the resolution of this sensor in the sensor's unit.
- * @return true on success, otherwise false.
- */
-bool sensord_get_resolution(sensor_t sensor, float *resolution);
-
-/**
- * @brief Get the minimum interval allowed between two events in microsecond or zero if this sensor only returns a value when the data it's measuring changes.
- *
- * @param[in] sensor a sensor to get minimum interval.
- * @param[out] min_interval the minimum interval of this sensor.
- * @return true on success, otherwise false.
- */
-bool sensord_get_min_interval(sensor_t sensor, int *min_interval);
-
-/**
- * @brief Get the number of events reserved for this sensor in the batch mode FIFO.
- *
- * @param[in] sensor a sensor to get the number of fifo count
- * @param[out] fifo_count the number of events reserved for this sensor in the batch mode FIFO
- * @return true on success, otherwise false
- */
-bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count);
-
-/**
- * @brief Get the maximum number of events of this sensor that could be batched. If this value is zero it indicates that batch mode is not supported for this sensor.
- *
- * @param[in] sensor a sensor to the maximum number of events that could be batched.
- * @param[out] max_batch_count the maximum number of events of this sensor that could be batched.
- * @return true on success, otherwise false.
- */
-bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count);
-
-/**
- * @brief Get the supported event types of this sensor.
- *
- * @param[in] sensor a sensor to get the supported event types.
- * @param[out] event_types the array containing supported event types of this sensor, the caller should explicitly free this array.
- * @param[out] count the count of the supported event types of this sensor.
- * @return true on success, otherwise false.
- */
-bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count);
-
-/**
- * @brief Check a given event type is supporeted by this sensor.
- *
- * @param[in] sensor a sensor to check a given event type is supporeted.
- * @param[out] event_type an event type to be checked whether supported or not.
- * @param[out] supported whether a given event is supported or not in this sensor.
- * @return true on success, otherwise false.
- */
-bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported);
-
-/**
- * @brief Check a wakeup supported or not by this sensor.
- *
- * @param[in] sensor a sensor to check a given event type is supporeted.
- * @return true on success, otherwise false.
- */
-bool sensord_is_wakeup_supported(sensor_t sensor);
-
-/**
- * @brief Connect a given sensor and get a handle of a given sensor.
- *
- * @param[in] sensor a sensor to connect
- * @return a handle of a given sensor on success, otherwise negative value
- */
-int sensord_connect(sensor_t sensor);
-
-/**
- * @brief Disconnect a given sensor.
- *
- * @param[in] handle a handle to disconnect.
- * @return true on success, otherwise false.
- */
-bool sensord_disconnect(int handle);
-
-/**
- * @brief Register a callback with a connected sensor for a given event_type. This callback will be called when a given event occurs in a connected sensor.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] event_type an event type to register
- * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval.
- * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds.
- * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
- * @param[in] cb a callback which is called when a given event occurs
- * @param[in] user_data the callback is called with user_data
- * @return true on success, otherwise false.
- */
-bool sensord_register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data);
-
-/**
- * @brief Register a callback with a connected sensor for a given event_type. This callback will be called when a given event occurs in a connected sensor.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] event_type an event type to register
- * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
- * @param[in] cb a callback which is called when a given event occurs
- * @param[in] user_data the callback is called with user_data
- * @return true on success, otherwise false.
- */
-bool sensord_register_events(int handle, unsigned int event_type, unsigned int max_batch_latency, sensor_events_cb_t cb, void *user_data);
-
-/**
- * @brief Register a callback with a connected context sensor for a given event_type. This callback will be called when a given event occurs in a connected context sensor.
- *
- * @param[in] handle a handle represensting a connected context sensor.
- * @param[in] event_type an event type to register
- * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval.
- * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds.
- * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
- * @param[in] cb a callback which is called when a given event occurs
- * @param[in] user_data the callback is called with user_data
- * @return true on success, otherwise false.
- */
-bool sensord_register_hub_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data);
-
-/**
- * @brief Unregister a event with a connected sensor. After unregistering, that event will not be sent.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] event_type an event type to unregister.
- * @return true on success, otherwise false.
- */
-bool sensord_unregister_event(int handle, unsigned int event_type);
-
-/**
- * @brief Unregister a event with a connected sensor. After unregistering, that event will not be sent.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] event_type an event type to unregister.
- * @return true on success, otherwise false.
- */
-bool sensord_unregister_events(int handle, unsigned int event_type);
-
-/**
- * @brief Register a callback with a connected sensor. This callback will be called when the accuracy of a sensor has changed.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] cb a callback which is called when he accuracy of a sensor has changed.
- * @param[in] user_data the callback is called with user_data
- * @return true on success, otherwise false.
- */
-bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data);
-
-/**
- * @brief Unregister a callback with a connected sensor. After unregistering, sensor_accuray_change_cb will not be called.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @return true on success, otherwise false.
- */
-bool sensord_unregister_accuracy_cb(int handle);
-
-/**
- * @brief Register a callback with a connected sensor. This callback will be called when attributes of a sensor has changed.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] cb a callback which is called when he attributes of a sensor has changed.
- * @param[in] user_data the callback is called with user_data
- * @return true on success, otherwise false.
- */
-bool sensord_register_attribute_int_changed_cb(int handle, sensor_attribute_int_changed_cb_t cb, void *user_data);
-
-/**
- * @brief Unregister a callback with a connected sensor. After unregistering, sensor_attribute_int_changed_cb will not be called.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @return true on success, otherwise false.
- */
-bool sensord_unregister_attribute_int_changed_cb(int handle);
-
-/**
- * @brief Register a callback with a connected sensor. This callback will be called when attributes of a sensor has changed.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] cb a callback which is called when he attributes of a sensor has changed.
- * @param[in] user_data the callback is called with user_data
- * @return true on success, otherwise false.
- */
-bool sensord_register_attribute_str_changed_cb(int handle, sensor_attribute_str_changed_cb_t cb, void *user_data);
-
-/**
- * @brief Unregister a callback with a connected sensor. After unregistering, sensor_attribute_str_changed_cb will not be called.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @return true on success, otherwise false.
- */
-bool sensord_unregister_attribute_str_changed_cb(int handle);
-
-/**
- * @brief Start listening events with a connected sensor.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] option either one of SENSOR_OPTION_DEFAULT and SENSOR_OPTION_ALWAYS_ON.
- * with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
- * with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
- * @return true on success, otherwise false.
- */
-bool sensord_start(int handle, int option);
-
-/**
- * @brief Stop listening events with a connected sensor.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @return true on success, otherwise false.
- */
-bool sensord_stop(int handle);
-
-/**
- * @brief Change the interval of a specifed event type in a connected sensor.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] event_type an event type to change interval.
- * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval.
- * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds.
- * @return true on success, otherwise false.
- */
-bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval);
-
-/**
- * @brief Change the max batch latency of a specifed event type in a connected sensor.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] event_type an event type to change max batch latency
- * @param[in] max_batch_latency an event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
- * @return true on success, otherwise false.
- */
-bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency);
-
-/**
- * @brief Change the option of a connected sensor.
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] option either one of SENSOR_OPTION_DEFAULT and SENSOR_OPTION_ALWAYS_ON.
- * with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
- * with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
- * @return true on success, otherwise false.
- */
-bool sensord_set_option(int handle, int option);
-
-/*
- * @brief Set the attribute to a connected sensor
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] attribute an attribute to change
- * @param[in] value an attribute value
- * @return 0 on success, otherwise a negative error value
- * @retval 0 Successful
- * @retval -EINVAL Invalid parameter
- * @retval -EPERM Operation not permitted
- */
-int sensord_set_attribute_int(int handle, int attribute, int value);
-
-/*
- * @brief Get the attribute to a connected sensor
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] attribute an attribute to get value
- * @param[out] value an attribute value
- * @return 0 on success, otherwise a negative error value
- * @retval 0 Successful
- * @retval -EINVAL Invalid parameter
- * @retval -EPERM Operation not permitted
- */
-int sensord_get_attribute_int(int handle, int attribute, int* value);
-
-/**
- * @brief Set the attribute to a connected sensor
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] attribute an attribute to change
- * @param[in] value an attribute value
- * @param[in] value_len the length of value
- * @return 0 on success, otherwise a negative error value
- * @retval 0 Successful
- * @retval -EINVAL Invalid parameter
- * @retval -EPERM Operation not permitted
- */
-int sensord_set_attribute_str(int handle, int attribute, const char *value, int len);
-
-/**
- * @brief Get the attribute to a connected sensor
- *
- * @param[in] handle a handle represensting a connected sensor.
- * @param[in] attribute an attribute to get value
- * @param[out] value an attribute value, the caller should explicitly free this value
- * @param[out] len the length of value
- * @return 0 on success, otherwise a negative error value
- * @retval 0 Successful
- * @retval -EINVAL Invalid parameter
- * @retval -EPERM Operation not permitted
- */
-int sensord_get_attribute_str(int handle, int attribute, char **value, int *len);
-
-/**
- * @brief Send data to sensorhub
- *
- * @param[in] handle a handle represensting a connected context sensor.
- * @param[in] data it holds data to send to sensorhub
- * @param[in] data_len the length of data
- * @return true on success, otherwise false.
- */
-bool sensord_send_sensorhub_data(int handle, const char *data, int data_len);
-bool sensord_send_command(int handle, const char *command, int command_len);
-
-/**
- * @brief get sensor data from a connected sensor
- *
- * @param[in] handle a handle represensting a connected context sensor.
- * @param[in] data_id it specifies data to get
- * @param[out] sensor_data data from connected sensor
- * @return true on success, otherwise false.
- */
-bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data);
-
-/**
- * @brief get sensor data from a connected sensor
- *
- * @param[in] handle a handle represensting a connected context sensor.
- * @param[in] data_id it specifies data to get
- * @param[out] sensor_data the data list from connected sensor, the caller should explicitly free this list.
- * @param[out] count the count of data contained in the list.
- * @return true on success, otherwise false.
- */
-bool sensord_get_data_list(int handle, unsigned int data_id, sensor_data_t** sensor_data, int* count);
-
-/**
- * @brief flush sensor data from a connected sensor
- *
- * @param[in] handle a handle represensting a connected context sensor.
- * @return true on success, otherwise false.
- */
-bool sensord_flush(int handle);
-
-bool sensord_set_passive_mode(int handle, bool passive);
-
-
-/* Sensor Internal API using URI */
-int sensord_get_default_sensor_by_uri(const char *uri, sensor_t *sensor);
-int sensord_get_sensors_by_uri(const char *uri, sensor_t **list, int *sensor_count);
-
-typedef void (*sensord_added_cb)(const char *uri, void *user_data);
-int sensord_add_sensor_added_cb(sensord_added_cb callback, void *user_data);
-int sensord_remove_sensor_added_cb(sensord_added_cb callback);
-
-typedef void (*sensord_removed_cb)(const char *uri, void *user_data);
-int sensord_add_sensor_removed_cb(sensord_removed_cb callback, void *user_data);
-int sensord_remove_sensor_removed_cb(sensord_removed_cb callback);
-
-/* Sensor provider */
-typedef void *sensord_provider_h;
-int sensord_create_provider(const char *uri, sensord_provider_h *provider);
-int sensord_destroy_provider(sensord_provider_h provider);
-int sensord_add_provider(sensord_provider_h provider);
-int sensord_remove_provider(sensord_provider_h provider);
-
-int sensord_provider_set_name(sensord_provider_h provider, const char *name);
-int sensord_provider_set_vendor(sensord_provider_h provider, const char *vendor);
-int sensord_provider_set_range(sensord_provider_h provider, float min_range, float max_range);
-int sensord_provider_set_resolution(sensord_provider_h provider, float resolution);
-
-typedef void (*sensord_provider_start_cb)(sensord_provider_h provider, void *user_data);
-int sensord_provider_set_start_cb(sensord_provider_h provider, sensord_provider_start_cb callback, void *user_data);
-
-typedef void (*sensord_provider_stop_cb)(sensord_provider_h provider, void *user_data);
-int sensord_provider_set_stop_cb(sensord_provider_h provider, sensord_provider_stop_cb callback, void *user_data);
-
-typedef void (*sensord_provider_interval_changed_cb)(sensord_provider_h provider, unsigned int interval_ms, void *user_data);
-int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, sensord_provider_interval_changed_cb callback, void *user_data);
-
-typedef void (*sensord_provider_attribute_str_cb)(sensord_provider_h provider, int attribute, const char *value, int count, void *user_data);
-int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data);
-
-int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data);
-int sensord_provider_publish_events(sensord_provider_h provider, sensor_data_t events[], int count);
-
-/* Deprecated */
-typedef void (*sensor_external_command_cb_t)(int handle, const char* data, int data_cnt, void *user_data);
-int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data);
-bool sensord_external_disconnect(int handle);
-bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt);
-
-/**
- * @}
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __SENSORD_INTERNAL_H__ */
diff --git a/src/api/sensor-internal.cpp b/src/api/sensor-internal.cpp
index 514b95f..8e764f1 100644
--- a/src/api/sensor-internal.cpp
+++ b/src/api/sensor-internal.cpp
@@ -14,11 +14,1185 @@
* limitations under the License.
*/
-#include <sensor-internal.h>
-
#include <errno.h>
+
+#include <sensor-internal.h>
#include <sensor.h>
-#include <sensor_internal.h>
+#include <sensor-types.h>
+#include <sensor_types_private.h>
+#include <sensor_utils.h>
+#include <channel_handler.h>
+#include <sensor_manager.h>
+#include <sensor_listener.h>
+#include <sensor_provider_internal.h>
+#include <sensor-log.h>
+#include <cmutex.h>
+#include <command_types.h>
+#include "sensor_reader.h"
+
+#include <unordered_map>
+#include <regex>
+#include <thread>
+
+#define CONVERT_OPTION_TO_PAUSE_POLICY(option) ((option) ^ 0b11)
+#define MAX_LISTENER 100
+#define MAX_PROVIDER 20
+
+using namespace sensor;
+
+typedef struct {
+ int listener_id;
+ sensor_info *sensor;
+ void* cb;
+ char* data;
+ size_t data_size;
+ void *user_data;
+} callback_info_s;
+
+typedef GSourceFunc callback_dispatcher_t;
+
+static sensor::sensor_manager manager;
+static std::unordered_map<int, sensor::sensor_listener *> listeners;
+static cmutex lock;
+static uint providerCnt = 0;
+
+static gboolean sensor_events_callback_dispatcher(gpointer data)
+{
+ int event_type = 0;
+ callback_info_s *info = (callback_info_s *)data;
+
+ AUTOLOCK(lock);
+
+ if (info->sensor)
+ event_type = CONVERT_TYPE_EVENT(info->sensor->get_type());
+
+ if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) {
+ size_t element_size = sizeof(sensor_data_t);
+ size_t count = info->data_size / element_size;
+ ((sensor_events_cb_t)info->cb)(info->sensor, event_type, (sensor_data_t*)info->data, count, info->user_data);
+ }
+
+ delete [] info->data;
+ delete info;
+ return FALSE;
+}
+
+static gboolean sensor_event_callback_dispatcher(gpointer data)
+{
+ int event_type = 0;
+ callback_info_s *info = (callback_info_s *)data;
+
+ AUTOLOCK(lock);
+
+ if (info->sensor)
+ event_type = CONVERT_TYPE_EVENT(info->sensor->get_type());
+
+ if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) {
+ ((sensor_cb_t)info->cb)(info->sensor, event_type, (sensor_data_t*)info->data, info->user_data);
+ }
+
+ delete [] info->data;
+ delete info;
+ return FALSE;
+}
+
+static gboolean sensor_accuracy_changed_callback_dispatcher(gpointer data)
+{
+ callback_info_s *info = (callback_info_s *)data;
+
+ AUTOLOCK(lock);
+
+ if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) {
+ sensor_data_t * sensor_data = (sensor_data_t *)info->data;
+ ((sensor_accuracy_changed_cb_t)info->cb)(info->sensor, sensor_data->timestamp, sensor_data->accuracy, info->user_data);
+ }
+
+ delete [] info->data;
+ delete info;
+ return FALSE;
+}
+
+static gboolean sensor_attribute_int_changed_callback_dispatcher(gpointer data)
+{
+ callback_info_s *info = (callback_info_s *)data;
+
+ AUTOLOCK(lock);
+
+ if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) {
+ cmd_listener_attr_int_t *d = (cmd_listener_attr_int_t *)info->data;
+ ((sensor_attribute_int_changed_cb_t)info->cb)(info->sensor, d->attribute, d->value, info->user_data);
+ }
+
+ delete [] info->data;
+ delete info;
+ return FALSE;
+}
+
+static gboolean sensor_attribute_str_changed_callback_dispatcher(gpointer data)
+{
+ callback_info_s *info = (callback_info_s *)data;
+
+ AUTOLOCK(lock);
+
+ if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) {
+ cmd_listener_attr_str_t *d = (cmd_listener_attr_str_t *)info->data;
+ ((sensor_attribute_str_changed_cb_t)info->cb)(info->sensor, d->attribute, d->value, d->len, info->user_data);
+ }
+
+ delete [] info->data;
+ delete info;
+ return FALSE;
+}
+
+class sensor_listener_channel_handler : public ipc::channel_handler
+{
+public:
+ sensor_listener_channel_handler(int id, sensor_t sensor, void* cb, void *user_data, callback_dispatcher_t dispatcher)
+ : m_listener_id(id)
+ , m_sensor(reinterpret_cast<sensor_info *>(sensor))
+ , m_cb(cb)
+ , m_user_data(user_data)
+ , m_dispatcher(dispatcher)
+ {}
+
+ void connected(ipc::channel *ch) {}
+ void disconnected(ipc::channel *ch) {}
+ void read(ipc::channel *ch, ipc::message &msg)
+ {
+ callback_info_s *info;
+ auto size = msg.size();
+ char *data = new(std::nothrow) char[size];
+ if (data == NULL)
+ return;
+ memcpy(data, msg.body(), size);
+
+ info = new(std::nothrow) callback_info_s();
+ info->listener_id = m_listener_id;
+ info->cb = m_cb;
+ info->sensor = m_sensor;
+ info->data = data;
+ info->data_size = size;
+ info->user_data = m_user_data;
+
+ g_idle_add(m_dispatcher, info);
+ }
+
+ void read_complete(ipc::channel *ch) {}
+ void error_caught(ipc::channel *ch, int error) {}
+ void set_handler(int num, ipc::channel_handler* handler) {}
+ void disconnect(void) {}
+
+private:
+ int m_listener_id;
+ sensor_info *m_sensor;
+ void* m_cb;
+ void *m_user_data;
+ callback_dispatcher_t m_dispatcher;
+};
+
+/*
+ * TO-DO-LIST:
+ * 1. power save option / lcd vconf : move to server
+ * 2. thread-safe : ipc_client
+ */
+
+API int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *count)
+{
+ return sensord_get_sensors_by_uri(utils::get_uri(type), list, count);
+}
+
+API int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor)
+{
+ return sensord_get_default_sensor_by_uri(utils::get_uri(type), sensor);
+}
+
+API bool sensord_get_type(sensor_t sensor, sensor_type_t *type)
+{
+ retvm_if(!type, false, "Invalid type");
+ retvm_if(!manager.connect(), false, "Failed to connect");
+ retvm_if(!manager.is_supported(sensor), false,
+ "Invalid sensor[%p]", sensor);
+
+ *type = static_cast<sensor_info *>(sensor)->get_type();
+
+ return true;
+}
+
+API const char* sensord_get_uri(sensor_t sensor)
+{
+ retvm_if(!manager.connect(), NULL, "Failed to connect");
+ retvm_if(!manager.is_supported(sensor), NULL,
+ "Invalid sensor[%p]", sensor);
+
+ return static_cast<sensor_info *>(sensor)->get_uri().c_str();
+}
+
+API const char* sensord_get_name(sensor_t sensor)
+{
+ retvm_if(!manager.connect(), NULL, "Failed to connect");
+ retvm_if(!manager.is_supported(sensor), NULL,
+ "Invalid sensor[%p]", sensor);
+
+ return static_cast<sensor_info *>(sensor)->get_model().c_str();
+}
+
+API const char* sensord_get_vendor(sensor_t sensor)
+{
+ retvm_if(!manager.connect(), NULL, "Failed to connect");
+ retvm_if(!manager.is_supported(sensor), NULL,
+ "Invalid sensor[%p]", sensor);
+
+ return static_cast<sensor_info *>(sensor)->get_vendor().c_str();
+}
+
+API bool sensord_get_min_range(sensor_t sensor, float *min_range)
+{
+ retvm_if(!min_range, false, "Invalid paramter");
+ retvm_if(!manager.connect(), false, "Failed to connect");
+ retvm_if(!manager.is_supported(sensor), false,
+ "Invalid sensor[%p]", sensor);
+
+ *min_range = static_cast<sensor_info *>(sensor)->get_min_range();
+
+ return true;
+}
+
+API bool sensord_get_max_range(sensor_t sensor, float *max_range)
+{
+ retvm_if(!max_range, false, "Invalid parameter");
+ retvm_if(!manager.connect(), false, "Failed to connect");
+ retvm_if(!manager.is_supported(sensor), false,
+ "Invalid sensor[%p]", sensor);
+
+ *max_range = static_cast<sensor_info *>(sensor)->get_max_range();
+
+ return true;
+}
+
+API bool sensord_get_resolution(sensor_t sensor, float *resolution)
+{
+ retvm_if(!resolution, false, "Invalid parameter");
+ retvm_if(!manager.connect(), false, "Failed to connect");
+ retvm_if(!manager.is_supported(sensor), false,
+ "Invalid sensor[%p]", sensor);
+
+ *resolution = static_cast<sensor_info *>(sensor)->get_resolution();
+
+ return true;
+}
+
+API bool sensord_get_min_interval(sensor_t sensor, int *min_interval)
+{
+ retvm_if(!min_interval, false, "Invalid parameter");
+ retvm_if(!manager.connect(), false, "Failed to connect");
+ retvm_if(!manager.is_supported(sensor), false,
+ "Invalid sensor[%p]", sensor);
+
+ *min_interval = static_cast<sensor_info *>(sensor)->get_min_interval();
+
+ return true;
+}
+
+API bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count)
+{
+ retvm_if(!fifo_count, false, "Invalid parameter");
+ retvm_if(!manager.connect(), false, "Failed to connect");
+ retvm_if(!manager.is_supported(sensor), false,
+ "Invalid sensor[%p]", sensor);
+
+ *fifo_count = 0;
+
+ return true;
+}
+
+API bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count)
+{
+ retvm_if(!max_batch_count, false, "Invalid parameter");
+ retvm_if(!manager.connect(), false, "Failed to connect");
+ retvm_if(!manager.is_supported(sensor), false,
+ "Invalid sensor[%p]", sensor);
+
+ *max_batch_count = static_cast<sensor_info *>(sensor)->get_max_batch_count();
+
+ return true;
+}
+
+API bool sensord_is_wakeup_supported(sensor_t sensor)
+{
+ retvm_if(!manager.connect(), false, "Failed to connect");
+ retvm_if(!manager.is_supported(sensor), false,
+ "Invalid sensor[%p]", sensor);
+
+ return static_cast<sensor_info *>(sensor)->is_wakeup_supported();
+}
+
+API int sensord_connect(sensor_t sensor)
+{
+ AUTOLOCK(lock);
+
+ retvm_if(!manager.connect(), -EIO, "Failed to connect");
+ retvm_if(!manager.is_supported(sensor), -EINVAL,
+ "Invalid sensor[%p]", sensor);
+ retvm_if(listeners.size() > MAX_LISTENER, -EPERM, "Exceeded the maximum listener");
+
+ sensor::sensor_listener *listener;
+ static sensor_reader reader;
+
+ listener = new(std::nothrow) sensor::sensor_listener(sensor, reader.get_event_loop());
+ retvm_if(!listener, -ENOMEM, "Failed to allocate memory");
+
+ listeners[listener->get_id()] = listener;
+
+ _D("Connect[%d]", listener->get_id());
+
+ return listener->get_id();
+}
+
+API bool sensord_disconnect(int handle)
+{
+ sensor::sensor_listener *listener;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+ retvm_if(!listener, false, "Invalid handle[%d]", handle);
+
+ _D("Disconnect[%d]", listener->get_id());
+
+ delete listener;
+ listeners.erase(handle);
+
+ if (listeners.empty())
+ manager.disconnect();
+
+ return true;
+}
+
+static inline bool sensord_register_event_impl(int handle, unsigned int event_type,
+ unsigned int interval, unsigned int max_batch_latency, void* cb, bool is_events_callback, void *user_data)
+{
+ sensor::sensor_listener *listener;
+ int prev_interval;
+ int prev_max_batch_latency;
+ sensor_listener_channel_handler *handler;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ prev_interval = listener->get_interval();
+ prev_max_batch_latency = listener->get_max_batch_latency();
+
+ if (listener->set_interval(interval) < 0) {
+ _E("Failed to set interval");
+ return false;
+ }
+
+ if (listener->set_max_batch_latency(max_batch_latency) < 0) {
+ listener->set_interval(prev_interval);
+ _E("Failed to set max_batch_latency");
+ return false;
+ }
+
+ if (is_events_callback) {
+ handler = new(std::nothrow)sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_events_callback_dispatcher);
+ } else {
+ handler = new(std::nothrow)sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_event_callback_dispatcher);
+ }
+
+ if (!handler) {
+ listener->set_max_batch_latency(prev_max_batch_latency);
+ listener->set_interval(prev_interval);
+ _E("Failed to allocate memory");
+ return false;
+ }
+
+ listener->set_event_handler(handler);
+
+ _D("Register event[%d]", listener->get_id());
+
+ return true;
+}
+
+API bool sensord_register_event(int handle, unsigned int event_type,
+ unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data)
+{
+ return sensord_register_event_impl(handle, event_type, interval, max_batch_latency, (void*)cb, false, user_data);
+}
+
+static inline bool sensord_unregister_event_imple(int handle)
+{
+ sensor::sensor_listener *listener;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ listener->unset_event_handler();
+
+ _D("Unregister event[%d]", listener->get_id());
+
+ return true;
+}
+
+API bool sensord_unregister_event(int handle, unsigned int event_type)
+{
+ return sensord_unregister_event_imple(handle);
+}
+
+API bool sensord_register_events(int handle, unsigned int event_type, unsigned int max_batch_latency, sensor_events_cb_t cb, void *user_data)
+{
+ return sensord_register_event_impl(handle, event_type, 0, max_batch_latency, (void*)cb, true, user_data);
+}
+
+API bool sensord_unregister_events(int handle, unsigned int event_type)
+{
+ return sensord_unregister_event_imple(handle);
+}
+
+API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data)
+{
+ sensor::sensor_listener *listener;
+ sensor_listener_channel_handler *handler;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ handler = new(std::nothrow) sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_accuracy_changed_callback_dispatcher);
+ retvm_if(!handler, false, "Failed to allocate memory");
+
+ listener->set_accuracy_handler(handler);
+
+ return true;
+}
+
+API bool sensord_unregister_accuracy_cb(int handle)
+{
+ sensor::sensor_listener *listener;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ listener->unset_accuracy_handler();
+
+ return true;
+}
+
+API bool sensord_register_attribute_int_changed_cb(int handle, sensor_attribute_int_changed_cb_t cb, void *user_data)
+{
+ sensor::sensor_listener *listener;
+ sensor_listener_channel_handler *handler;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ handler = new(std::nothrow) sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_attribute_int_changed_callback_dispatcher);
+ retvm_if(!handler, false, "Failed to allocate memory");
+
+ listener->set_attribute_int_changed_handler(handler);
+
+ return true;
+}
+
+API bool sensord_unregister_attribute_int_changed_cb(int handle)
+{
+ sensor::sensor_listener *listener;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ listener->unset_attribute_int_changed_handler();
+
+ return true;
+}
+
+API bool sensord_register_attribute_str_changed_cb(int handle, sensor_attribute_str_changed_cb_t cb, void *user_data)
+{
+ sensor::sensor_listener *listener;
+ sensor_listener_channel_handler *handler;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ handler = new(std::nothrow) sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_attribute_str_changed_callback_dispatcher);
+ retvm_if(!handler, false, "Failed to allocate memory");
+
+ listener->set_attribute_str_changed_handler(handler);
+
+ return true;
+}
+
+API bool sensord_unregister_attribute_str_changed_cb(int handle)
+{
+ sensor::sensor_listener *listener;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ listener->unset_attribute_str_changed_handler();
+
+ return true;
+}
+
+API bool sensord_start(int handle, int option)
+{
+ sensor::sensor_listener *listener;
+ int prev_pause;
+ int pause;
+ int interval, batch_latency;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ pause = CONVERT_OPTION_TO_PAUSE_POLICY(option);
+ prev_pause = listener->get_pause_policy();
+
+ if (listener->set_attribute(SENSORD_ATTRIBUTE_PAUSE_POLICY, pause) < 0) {
+ _E("Failed to set pause policy[%d]", pause);
+ return false;
+ }
+
+ if (listener->start() < 0) {
+ listener->set_attribute(SENSORD_ATTRIBUTE_PAUSE_POLICY, prev_pause);
+ _E("Failed to start listener");
+ return false;
+ }
+
+ interval = listener->get_interval();
+ if (interval > 0)
+ listener->set_interval(interval);
+
+ batch_latency = listener->get_max_batch_latency();
+ if (batch_latency != SENSOR_BATCH_LATENCY_DEFAULT)
+ listener->set_max_batch_latency(batch_latency);
+
+ _D("Start[%d] with the interval[%d] batch_latency[%d]",
+ listener->get_id(), interval, batch_latency);
+
+ return true;
+}
+
+API bool sensord_stop(int handle)
+{
+ int ret;
+ sensor::sensor_listener *listener;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ ret = listener->stop();
+
+ if (ret == -EAGAIN || ret == OP_SUCCESS)
+ return true;
+
+ _D("Stop[%d]", listener->get_id());
+
+ return false;
+}
+
+API bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval)
+{
+ sensor::sensor_listener *listener;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ if (listener->set_interval(interval) < 0) {
+ _E("Failed to set interval to listener");
+ return false;
+ }
+
+ _D("Set interval[%d, %d]", listener->get_id(), interval);
+
+ return true;
+}
+
+API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency)
+{
+ sensor::sensor_listener *listener;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ if (listener->set_max_batch_latency(max_batch_latency) < 0) {
+ _E("Failed to set max_batch_latency to listener");
+ return false;
+ }
+
+ _D("Set max batch latency[%d, %u]", listener->get_id(), max_batch_latency);
+
+ return true;
+}
+
+API bool sensord_set_option(int handle, int option)
+{
+ sensor::sensor_listener *listener;
+ int pause;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ pause = CONVERT_OPTION_TO_PAUSE_POLICY(option);
+
+ if (listener->set_attribute(SENSORD_ATTRIBUTE_PAUSE_POLICY, pause) < 0) {
+ _E("Failed to set option[%d(%d)] to listener", option, pause);
+ return false;
+ }
+
+ _D("Set pause option[%d, %d]", listener->get_id(), pause);
+
+ return true;
+}
+
+API int sensord_set_attribute_int(int handle, int attribute, int value)
+{
+ sensor::sensor_listener *listener;
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), -EINVAL, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ if (listener->set_attribute(attribute, value) < 0) {
+ _E("Failed to set attribute[%d, %d]", attribute, value);
+ return -EIO;
+ }
+
+ _D("Set attribute[%d, %d, %d]", listener->get_id(), attribute, value);
+
+ return OP_SUCCESS;
+}
+
+API int sensord_get_attribute_int(int handle, int attribute, int* value)
+{
+ sensor::sensor_listener *listener;
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), -EINVAL, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ if (listener->get_attribute(attribute, value) < 0) {
+ _E("Failed to get attribute[%d]", attribute);
+ return -EIO;
+ }
+
+ _D("Get attribute[%d, %d, %d]", listener->get_id(), attribute, *value);
+
+ return OP_SUCCESS;
+}
+
+API int sensord_set_attribute_str(int handle, int attribute, const char *value, int len)
+{
+ sensor::sensor_listener *listener;
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), -EINVAL, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ if (listener->set_attribute(attribute, value, len) < 0) {
+ _E("Failed to set attribute[%d, %s]", attribute, value);
+ return -EIO;
+ }
+ _D("Set attribute ID[%d], attr[%d], len[%d]", listener->get_id(), attribute, len);
+
+ return OP_SUCCESS;
+}
+
+API int sensord_get_attribute_str(int handle, int attribute, char **value, int* len)
+{
+ sensor::sensor_listener *listener;
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), -EINVAL, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ if (listener->get_attribute(attribute, value, len) < 0) {
+ _E("Failed to get attribute[%d]", attribute);
+ return -EIO;
+ }
+ _D("Get attribute ID[%d], attr[%d], len[%d]", listener->get_id(), attribute, *len);
+
+ return OP_SUCCESS;
+}
+
+API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data)
+{
+ sensor::sensor_listener *listener;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ if (listener->get_sensor_data(sensor_data) < 0) {
+ _E("Failed to get sensor data from listener");
+ return false;
+ }
+
+ return true;
+}
+
+API bool sensord_get_data_list(int handle, unsigned int data_id, sensor_data_t** sensor_data, int* count)
+{
+ sensor::sensor_listener *listener;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ if (listener->get_sensor_data_list(sensor_data, count) < 0) {
+ _E("Failed to get sensor data from listener");
+ return false;
+ }
+
+ return true;
+}
+
+API bool sensord_flush(int handle)
+{
+ sensor::sensor_listener *listener;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ if (listener->flush() < 0) {
+ _E("Failed to flush sensor");
+ return false;
+ }
+
+ return true;
+}
+
+API bool sensord_set_passive_mode(int handle, bool passive)
+{
+ sensor::sensor_listener *listener;
+
+ AUTOLOCK(lock);
+
+ auto it = listeners.find(handle);
+ retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
+
+ listener = it->second;
+
+ if (listener->set_passive_mode(passive) < 0) {
+ _E("Failed to set passive mode");
+ return false;
+ }
+
+ return true;
+}
+
+/* Sensor Internal API using URI */
+API int sensord_get_default_sensor_by_uri(const char *uri, sensor_t *sensor)
+{
+ retvm_if(!sensor, -EINVAL, "Invalid parameter");
+ retvm_if(!manager.connect(), -EIO, "Failed to connect");
+
+ return manager.get_sensor(uri, sensor);
+}
+
+API int sensord_get_sensors_by_uri(const char *uri, sensor_t **list, int *count)
+{
+ retvm_if((!list || !count), -EINVAL, "Invalid parameter");
+ retvm_if(!manager.connect(), -EIO, "Failed to connect");
+
+ return manager.get_sensors(uri, list, count);
+}
+
+API int sensord_add_sensor_added_cb(sensord_added_cb callback, void *user_data)
+{
+ retvm_if(!callback, -EINVAL, "Invalid paramter");
+ retvm_if(!manager.connect(), -EIO, "Failed to connect");
+
+ manager.add_sensor_added_cb(callback, user_data);
+ return OP_SUCCESS;
+}
+
+API int sensord_remove_sensor_added_cb(sensord_added_cb callback)
+{
+ retvm_if(!callback, -EINVAL, "Invalid paramter");
+ retvm_if(!manager.connect(), -EIO, "Failed to connect");
+
+ manager.remove_sensor_added_cb(callback);
+ return OP_SUCCESS;
+}
+
+API int sensord_add_sensor_removed_cb(sensord_removed_cb callback, void *user_data)
+{
+ retvm_if(!callback, -EINVAL, "Invalid paramter");
+ retvm_if(!manager.connect(), -EIO, "Failed to connect");
+
+ manager.add_sensor_removed_cb(callback, user_data);
+ return OP_SUCCESS;
+}
+
+API int sensord_remove_sensor_removed_cb(sensord_removed_cb callback)
+{
+ retvm_if(!callback, -EINVAL, "Invalid paramter");
+ retvm_if(!manager.connect(), -EIO, "Failed to connect");
+
+ manager.remove_sensor_removed_cb(callback);
+ return OP_SUCCESS;
+}
+
+/* Sensor provider */
+API int sensord_create_provider(const char *uri, sensord_provider_h *provider)
+{
+ retvm_if(providerCnt >= MAX_PROVIDER, -EPERM, "Exceeded the maximum provider");
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+
+ std::string str_uri(uri);
+ retvm_if(str_uri.find(PREDEFINED_TYPE_URI) != std::string::npos,
+ -EINVAL, "Invalid URI format[%s]", uri);
+
+ static std::regex uri_regex(SENSOR_URI_REGEX, std::regex::optimize);
+ retvm_if(!std::regex_match(uri, uri_regex),
+ -EINVAL, "Invalid URI format[%s]", uri);
+
+ sensor_provider *p;
+
+ p = new(std::nothrow) sensor_provider(uri);
+ retvm_if(!p, -ENOMEM, "Failed to allocate memory");
+
+ *provider = static_cast<sensord_provider_h>(p);
+ providerCnt++;
+ return OP_SUCCESS;
+}
+
+API int sensord_destroy_provider(sensord_provider_h provider)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+
+ delete static_cast<sensor::sensor_provider *>(provider);
+ providerCnt--;
+ return OP_SUCCESS;
+}
+
+API int sensord_add_provider(sensord_provider_h provider)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+ retvm_if(!manager.connect(), -EIO, "Failed to connect");
+
+ int ret;
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ ret = p->connect();
+ retv_if(ret < 0, ret);
+
+ ret = manager.add_sensor(p);
+ if (ret < 0) {
+ p->disconnect();
+ return ret;
+ }
+
+ return OP_SUCCESS;
+}
+
+API int sensord_remove_provider(sensord_provider_h provider)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+ retvm_if(!manager.connect(), -EIO, "Failed to connect");
+
+ int ret;
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ if (!p->disconnect())
+ return OP_ERROR;
+
+ ret = manager.remove_sensor(p);
+ if (ret < 0) {
+ p->connect();
+ return OP_ERROR;
+ }
+
+ return OP_SUCCESS;
+}
+
+API int sensord_provider_set_name(sensord_provider_h provider, const char *name)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ sensor_info *info = p->get_sensor_info();
+ info->set_model(name);
+
+ return OP_SUCCESS;
+}
+
+API int sensord_provider_set_vendor(sensord_provider_h provider, const char *vendor)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ sensor_info *info = p->get_sensor_info();
+ info->set_vendor(vendor);
+
+ return OP_SUCCESS;
+}
+
+API int sensord_provider_set_range(sensord_provider_h provider, float min_range, float max_range)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ sensor_info *info = p->get_sensor_info();
+ info->set_min_range(min_range);
+ info->set_max_range(max_range);
+
+ return OP_SUCCESS;
+}
+
+API int sensord_provider_set_resolution(sensord_provider_h provider, float resolution)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ sensor_info *info = p->get_sensor_info();
+ info->set_resolution(resolution);
+
+ return OP_SUCCESS;
+}
+
+API int sensord_provider_set_start_cb(sensord_provider_h provider, sensord_provider_start_cb callback, void *user_data)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+ retvm_if(!callback, -EINVAL, "Invalid paramter");
+
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ p->set_start_cb(callback, user_data);
+
+ return OP_SUCCESS;
+}
+
+API int sensord_provider_set_stop_cb(sensord_provider_h provider, sensord_provider_stop_cb callback, void *user_data)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+ retvm_if(!callback, -EINVAL, "Invalid paramter");
+
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ p->set_stop_cb(callback, user_data);
+
+ return OP_SUCCESS;
+}
+
+API int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, sensord_provider_interval_changed_cb callback, void *user_data)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+ retvm_if(!callback, -EINVAL, "Invalid paramter");
+
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ p->set_interval_cb(callback, user_data);
+
+ return OP_SUCCESS;
+}
+
+API int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+ retvm_if(!callback, -EINVAL, "Invalid paramter");
+
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ p->set_attribute_str_cb(callback, user_data);
+
+ return OP_SUCCESS;
+}
+
+API int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ /* TODO: synchronous call is enough? */
+ return p->publish(data);
+}
+
+API int sensord_provider_publish_events(sensord_provider_h provider, sensor_data_t events[], int count)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ return p->publish(events, count);
+};
+
+/* deperecated */
+API sensor_t sensord_get_sensor(sensor_type_t type)
+{
+ sensor_t sensor;
+
+ if (sensord_get_default_sensor(type, &sensor) < 0)
+ return NULL;
+
+ return sensor;
+}
+
+/* deprecated */
+API bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count)
+{
+ return (sensord_get_sensors(type, list, sensor_count) == OP_SUCCESS);
+}
+
+/* deprecated */
+API bool sensord_register_hub_event(int handle, unsigned int event_type,
+ unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data)
+{
+ return false;
+}
+
+/* deprecated */
+API bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count)
+{
+ /*
+ * 1. check parameter
+ * 2. if there is no sensor, return false
+ * 3. memory allocation
+ */
+ return true;
+}
+
+/* deprecated(BUT it is used in C-API....) */
+API bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported)
+{
+ if (!manager.is_supported(sensor))
+ *supported = false;
+ else
+ *supported = true;
+
+ return true;
+}
+
+/* deprecated */
+API bool sensord_send_sensorhub_data(int handle, const char *data, int data_len)
+{
+ return (sensord_set_attribute_str(handle, 0, data, data_len) == OP_SUCCESS);
+}
+
+/* deprecated */
+API bool sensord_send_command(int handle, const char *command, int command_len)
+{
+ return (sensord_set_attribute_str(handle, 0, command, command_len) == OP_SUCCESS);
+}
+
+/* deprecated */
+API bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege)
+{
+ *privilege = SENSOR_PRIVILEGE_PUBLIC;
+
+ return true;
+}
+
+/* deprecated */
+API int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data)
+{
+ /*
+ * 1. check parameter
+ * 2. create handle in this client
+ * 3. first connection(client)
+ * 4. cmd_connect for external sensor with key
+ */
+ retvm_if(!key, -EINVAL, "Invalid key");
+ return 0;
+}
+
+/* deprecated */
+API bool sensord_external_disconnect(int handle)
+{
+ /*
+ * 1. check parameter
+ * 2. create handle in this client
+ * 3. first connection(client)
+ * 4. cmd_connect for external sensor with key
+ * 5. disconnect this handle
+ * 6. if there is no active sensor, remove client id and stop listener
+ */
+ return true;
+}
+
+/* deprecated */
+API bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt)
+{
+ /*
+ * 1. check parameter
+ * 1.1 (data_cnt <= 0) || (data_cnt > POST_DATA_LEN_MAX)), return false
+ * 2. cmd_post
+ */
+
+ return true;
+}
int sensor_util_set_attribute_int(sensor_type_e type, sensor_attribute_e attr, int value)
{
diff --git a/src/api/sensor.cpp b/src/api/sensor.cpp
index 287af04..db1d8ec 100644
--- a/src/api/sensor.cpp
+++ b/src/api/sensor.cpp
@@ -19,13 +19,13 @@
#include <string.h>
#include <sys/time.h>
#include <limits.h>
-
-#include <sensor_internal.h>
-#include <sensor.h>
-#include <sensor_private.h>
#include <libgen.h>
#include <memory>
-#include "include/sensor_log.h"
+
+#include <sensor.h>
+#include <sensor-internal.h>
+#include <sensor-private.h>
+#include <sensor-log.h>
#define RETURN_VAL_IF(expr, err) \
do { \
diff --git a/src/api/sensor_internal.cpp b/src/api/sensor_internal.cpp
deleted file mode 100644
index 2c9b833..0000000
--- a/src/api/sensor_internal.cpp
+++ /dev/null
@@ -1,1197 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_internal.h>
-#include <sensor_types.h>
-#include <sensor_types_private.h>
-#include <sensor_utils.h>
-
-#include <channel_handler.h>
-#include <sensor_manager.h>
-#include <sensor_listener.h>
-#include <sensor_provider_internal.h>
-#include <sensor_log.h>
-#include <unordered_map>
-#include <regex>
-#include <thread>
-#include <cmutex.h>
-#include <command_types.h>
-
-#include "sensor_reader.h"
-
-#define CONVERT_OPTION_TO_PAUSE_POLICY(option) ((option) ^ 0b11)
-#define MAX_LISTENER 100
-#define MAX_PROVIDER 20
-
-using namespace sensor;
-
-typedef struct {
- int listener_id;
- sensor_info *sensor;
- void* cb;
- char* data;
- size_t data_size;
- void *user_data;
-} callback_info_s;
-
-typedef GSourceFunc callback_dispatcher_t;
-
-static sensor::sensor_manager manager;
-static std::unordered_map<int, sensor::sensor_listener *> listeners;
-static cmutex lock;
-static uint providerCnt = 0;
-
-static gboolean sensor_events_callback_dispatcher(gpointer data)
-{
- int event_type = 0;
- callback_info_s *info = (callback_info_s *)data;
-
- AUTOLOCK(lock);
-
- if (info->sensor)
- event_type = CONVERT_TYPE_EVENT(info->sensor->get_type());
-
- if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) {
- size_t element_size = sizeof(sensor_data_t);
- size_t count = info->data_size / element_size;
- ((sensor_events_cb_t)info->cb)(info->sensor, event_type, (sensor_data_t*)info->data, count, info->user_data);
- }
-
- delete [] info->data;
- delete info;
- return FALSE;
-}
-
-static gboolean sensor_event_callback_dispatcher(gpointer data)
-{
- int event_type = 0;
- callback_info_s *info = (callback_info_s *)data;
-
- AUTOLOCK(lock);
-
- if (info->sensor)
- event_type = CONVERT_TYPE_EVENT(info->sensor->get_type());
-
- if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) {
- ((sensor_cb_t)info->cb)(info->sensor, event_type, (sensor_data_t*)info->data, info->user_data);
- }
-
- delete [] info->data;
- delete info;
- return FALSE;
-}
-
-static gboolean sensor_accuracy_changed_callback_dispatcher(gpointer data)
-{
- callback_info_s *info = (callback_info_s *)data;
-
- AUTOLOCK(lock);
-
- if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) {
- sensor_data_t * sensor_data = (sensor_data_t *)info->data;
- ((sensor_accuracy_changed_cb_t)info->cb)(info->sensor, sensor_data->timestamp, sensor_data->accuracy, info->user_data);
- }
-
- delete [] info->data;
- delete info;
- return FALSE;
-}
-
-static gboolean sensor_attribute_int_changed_callback_dispatcher(gpointer data)
-{
- callback_info_s *info = (callback_info_s *)data;
-
- AUTOLOCK(lock);
-
- if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) {
- cmd_listener_attr_int_t *d = (cmd_listener_attr_int_t *)info->data;
- ((sensor_attribute_int_changed_cb_t)info->cb)(info->sensor, d->attribute, d->value, info->user_data);
- }
-
- delete [] info->data;
- delete info;
- return FALSE;
-}
-
-static gboolean sensor_attribute_str_changed_callback_dispatcher(gpointer data)
-{
- callback_info_s *info = (callback_info_s *)data;
-
- AUTOLOCK(lock);
-
- if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) {
- cmd_listener_attr_str_t *d = (cmd_listener_attr_str_t *)info->data;
- ((sensor_attribute_str_changed_cb_t)info->cb)(info->sensor, d->attribute, d->value, d->len, info->user_data);
- }
-
- delete [] info->data;
- delete info;
- return FALSE;
-}
-
-class sensor_listener_channel_handler : public ipc::channel_handler
-{
-public:
- sensor_listener_channel_handler(int id, sensor_t sensor, void* cb, void *user_data, callback_dispatcher_t dispatcher)
- : m_listener_id(id)
- , m_sensor(reinterpret_cast<sensor_info *>(sensor))
- , m_cb(cb)
- , m_user_data(user_data)
- , m_dispatcher(dispatcher)
- {}
-
- void connected(ipc::channel *ch) {}
- void disconnected(ipc::channel *ch) {}
- void read(ipc::channel *ch, ipc::message &msg)
- {
- callback_info_s *info;
- auto size = msg.size();
- char *data = new(std::nothrow) char[size];
- if (data == NULL)
- return;
- memcpy(data, msg.body(), size);
-
- info = new(std::nothrow) callback_info_s();
- info->listener_id = m_listener_id;
- info->cb = m_cb;
- info->sensor = m_sensor;
- info->data = data;
- info->data_size = size;
- info->user_data = m_user_data;
-
- g_idle_add(m_dispatcher, info);
- }
-
- void read_complete(ipc::channel *ch) {}
- void error_caught(ipc::channel *ch, int error) {}
- void set_handler(int num, ipc::channel_handler* handler) {}
- void disconnect(void) {}
-
-private:
- int m_listener_id;
- sensor_info *m_sensor;
- void* m_cb;
- void *m_user_data;
- callback_dispatcher_t m_dispatcher;
-};
-
-/*
- * TO-DO-LIST:
- * 1. power save option / lcd vconf : move to server
- * 2. thread-safe : ipc_client
- */
-
-API int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *count)
-{
- return sensord_get_sensors_by_uri(utils::get_uri(type), list, count);
-}
-
-API int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor)
-{
- return sensord_get_default_sensor_by_uri(utils::get_uri(type), sensor);
-}
-
-API bool sensord_get_type(sensor_t sensor, sensor_type_t *type)
-{
- retvm_if(!type, false, "Invalid type");
- retvm_if(!manager.connect(), false, "Failed to connect");
- retvm_if(!manager.is_supported(sensor), false,
- "Invalid sensor[%p]", sensor);
-
- *type = static_cast<sensor_info *>(sensor)->get_type();
-
- return true;
-}
-
-API const char* sensord_get_uri(sensor_t sensor)
-{
- retvm_if(!manager.connect(), NULL, "Failed to connect");
- retvm_if(!manager.is_supported(sensor), NULL,
- "Invalid sensor[%p]", sensor);
-
- return static_cast<sensor_info *>(sensor)->get_uri().c_str();
-}
-
-API const char* sensord_get_name(sensor_t sensor)
-{
- retvm_if(!manager.connect(), NULL, "Failed to connect");
- retvm_if(!manager.is_supported(sensor), NULL,
- "Invalid sensor[%p]", sensor);
-
- return static_cast<sensor_info *>(sensor)->get_model().c_str();
-}
-
-API const char* sensord_get_vendor(sensor_t sensor)
-{
- retvm_if(!manager.connect(), NULL, "Failed to connect");
- retvm_if(!manager.is_supported(sensor), NULL,
- "Invalid sensor[%p]", sensor);
-
- return static_cast<sensor_info *>(sensor)->get_vendor().c_str();
-}
-
-API bool sensord_get_min_range(sensor_t sensor, float *min_range)
-{
- retvm_if(!min_range, false, "Invalid paramter");
- retvm_if(!manager.connect(), false, "Failed to connect");
- retvm_if(!manager.is_supported(sensor), false,
- "Invalid sensor[%p]", sensor);
-
- *min_range = static_cast<sensor_info *>(sensor)->get_min_range();
-
- return true;
-}
-
-API bool sensord_get_max_range(sensor_t sensor, float *max_range)
-{
- retvm_if(!max_range, false, "Invalid parameter");
- retvm_if(!manager.connect(), false, "Failed to connect");
- retvm_if(!manager.is_supported(sensor), false,
- "Invalid sensor[%p]", sensor);
-
- *max_range = static_cast<sensor_info *>(sensor)->get_max_range();
-
- return true;
-}
-
-API bool sensord_get_resolution(sensor_t sensor, float *resolution)
-{
- retvm_if(!resolution, false, "Invalid parameter");
- retvm_if(!manager.connect(), false, "Failed to connect");
- retvm_if(!manager.is_supported(sensor), false,
- "Invalid sensor[%p]", sensor);
-
- *resolution = static_cast<sensor_info *>(sensor)->get_resolution();
-
- return true;
-}
-
-API bool sensord_get_min_interval(sensor_t sensor, int *min_interval)
-{
- retvm_if(!min_interval, false, "Invalid parameter");
- retvm_if(!manager.connect(), false, "Failed to connect");
- retvm_if(!manager.is_supported(sensor), false,
- "Invalid sensor[%p]", sensor);
-
- *min_interval = static_cast<sensor_info *>(sensor)->get_min_interval();
-
- return true;
-}
-
-API bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count)
-{
- retvm_if(!fifo_count, false, "Invalid parameter");
- retvm_if(!manager.connect(), false, "Failed to connect");
- retvm_if(!manager.is_supported(sensor), false,
- "Invalid sensor[%p]", sensor);
-
- *fifo_count = 0;
-
- return true;
-}
-
-API bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count)
-{
- retvm_if(!max_batch_count, false, "Invalid parameter");
- retvm_if(!manager.connect(), false, "Failed to connect");
- retvm_if(!manager.is_supported(sensor), false,
- "Invalid sensor[%p]", sensor);
-
- *max_batch_count = static_cast<sensor_info *>(sensor)->get_max_batch_count();
-
- return true;
-}
-
-API bool sensord_is_wakeup_supported(sensor_t sensor)
-{
- retvm_if(!manager.connect(), false, "Failed to connect");
- retvm_if(!manager.is_supported(sensor), false,
- "Invalid sensor[%p]", sensor);
-
- return static_cast<sensor_info *>(sensor)->is_wakeup_supported();
-}
-
-API int sensord_connect(sensor_t sensor)
-{
- AUTOLOCK(lock);
-
- retvm_if(!manager.connect(), -EIO, "Failed to connect");
- retvm_if(!manager.is_supported(sensor), -EINVAL,
- "Invalid sensor[%p]", sensor);
- retvm_if(listeners.size() > MAX_LISTENER, -EPERM, "Exceeded the maximum listener");
-
- sensor::sensor_listener *listener;
- static sensor_reader reader;
-
- listener = new(std::nothrow) sensor::sensor_listener(sensor, reader.get_event_loop());
- retvm_if(!listener, -ENOMEM, "Failed to allocate memory");
-
- listeners[listener->get_id()] = listener;
-
- _D("Connect[%d]", listener->get_id());
-
- return listener->get_id();
-}
-
-API bool sensord_disconnect(int handle)
-{
- sensor::sensor_listener *listener;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
- retvm_if(!listener, false, "Invalid handle[%d]", handle);
-
- _D("Disconnect[%d]", listener->get_id());
-
- delete listener;
- listeners.erase(handle);
-
- if (listeners.empty())
- manager.disconnect();
-
- return true;
-}
-
-static inline bool sensord_register_event_impl(int handle, unsigned int event_type,
- unsigned int interval, unsigned int max_batch_latency, void* cb, bool is_events_callback, void *user_data)
-{
- sensor::sensor_listener *listener;
- int prev_interval;
- int prev_max_batch_latency;
- sensor_listener_channel_handler *handler;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- prev_interval = listener->get_interval();
- prev_max_batch_latency = listener->get_max_batch_latency();
-
- if (listener->set_interval(interval) < 0) {
- _E("Failed to set interval");
- return false;
- }
-
- if (listener->set_max_batch_latency(max_batch_latency) < 0) {
- listener->set_interval(prev_interval);
- _E("Failed to set max_batch_latency");
- return false;
- }
-
- if (is_events_callback) {
- handler = new(std::nothrow)sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_events_callback_dispatcher);
- } else {
- handler = new(std::nothrow)sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_event_callback_dispatcher);
- }
-
- if (!handler) {
- listener->set_max_batch_latency(prev_max_batch_latency);
- listener->set_interval(prev_interval);
- _E("Failed to allocate memory");
- return false;
- }
-
- listener->set_event_handler(handler);
-
- _D("Register event[%d]", listener->get_id());
-
- return true;
-}
-
-API bool sensord_register_event(int handle, unsigned int event_type,
- unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data)
-{
- return sensord_register_event_impl(handle, event_type, interval, max_batch_latency, (void*)cb, false, user_data);
-}
-
-static inline bool sensord_unregister_event_imple(int handle)
-{
- sensor::sensor_listener *listener;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- listener->unset_event_handler();
-
- _D("Unregister event[%d]", listener->get_id());
-
- return true;
-}
-
-API bool sensord_unregister_event(int handle, unsigned int event_type)
-{
- return sensord_unregister_event_imple(handle);
-}
-
-API bool sensord_register_events(int handle, unsigned int event_type, unsigned int max_batch_latency, sensor_events_cb_t cb, void *user_data)
-{
- return sensord_register_event_impl(handle, event_type, 0, max_batch_latency, (void*)cb, true, user_data);
-}
-
-API bool sensord_unregister_events(int handle, unsigned int event_type)
-{
- return sensord_unregister_event_imple(handle);
-}
-
-API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data)
-{
- sensor::sensor_listener *listener;
- sensor_listener_channel_handler *handler;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- handler = new(std::nothrow) sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_accuracy_changed_callback_dispatcher);
- retvm_if(!handler, false, "Failed to allocate memory");
-
- listener->set_accuracy_handler(handler);
-
- return true;
-}
-
-API bool sensord_unregister_accuracy_cb(int handle)
-{
- sensor::sensor_listener *listener;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- listener->unset_accuracy_handler();
-
- return true;
-}
-
-API bool sensord_register_attribute_int_changed_cb(int handle, sensor_attribute_int_changed_cb_t cb, void *user_data)
-{
- sensor::sensor_listener *listener;
- sensor_listener_channel_handler *handler;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- handler = new(std::nothrow) sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_attribute_int_changed_callback_dispatcher);
- retvm_if(!handler, false, "Failed to allocate memory");
-
- listener->set_attribute_int_changed_handler(handler);
-
- return true;
-}
-
-API bool sensord_unregister_attribute_int_changed_cb(int handle)
-{
- sensor::sensor_listener *listener;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- listener->unset_attribute_int_changed_handler();
-
- return true;
-}
-
-API bool sensord_register_attribute_str_changed_cb(int handle, sensor_attribute_str_changed_cb_t cb, void *user_data)
-{
- sensor::sensor_listener *listener;
- sensor_listener_channel_handler *handler;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- handler = new(std::nothrow) sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_attribute_str_changed_callback_dispatcher);
- retvm_if(!handler, false, "Failed to allocate memory");
-
- listener->set_attribute_str_changed_handler(handler);
-
- return true;
-}
-
-API bool sensord_unregister_attribute_str_changed_cb(int handle)
-{
- sensor::sensor_listener *listener;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- listener->unset_attribute_str_changed_handler();
-
- return true;
-}
-
-API bool sensord_start(int handle, int option)
-{
- sensor::sensor_listener *listener;
- int prev_pause;
- int pause;
- int interval, batch_latency;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- pause = CONVERT_OPTION_TO_PAUSE_POLICY(option);
- prev_pause = listener->get_pause_policy();
-
- if (listener->set_attribute(SENSORD_ATTRIBUTE_PAUSE_POLICY, pause) < 0) {
- _E("Failed to set pause policy[%d]", pause);
- return false;
- }
-
- if (listener->start() < 0) {
- listener->set_attribute(SENSORD_ATTRIBUTE_PAUSE_POLICY, prev_pause);
- _E("Failed to start listener");
- return false;
- }
-
- interval = listener->get_interval();
- if (interval > 0)
- listener->set_interval(interval);
-
- batch_latency = listener->get_max_batch_latency();
- if (batch_latency != SENSOR_BATCH_LATENCY_DEFAULT)
- listener->set_max_batch_latency(batch_latency);
-
- _D("Start[%d] with the interval[%d] batch_latency[%d]",
- listener->get_id(), interval, batch_latency);
-
- return true;
-}
-
-API bool sensord_stop(int handle)
-{
- int ret;
- sensor::sensor_listener *listener;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- ret = listener->stop();
-
- if (ret == -EAGAIN || ret == OP_SUCCESS)
- return true;
-
- _D("Stop[%d]", listener->get_id());
-
- return false;
-}
-
-API bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval)
-{
- sensor::sensor_listener *listener;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- if (listener->set_interval(interval) < 0) {
- _E("Failed to set interval to listener");
- return false;
- }
-
- _D("Set interval[%d, %d]", listener->get_id(), interval);
-
- return true;
-}
-
-API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency)
-{
- sensor::sensor_listener *listener;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- if (listener->set_max_batch_latency(max_batch_latency) < 0) {
- _E("Failed to set max_batch_latency to listener");
- return false;
- }
-
- _D("Set max batch latency[%d, %u]", listener->get_id(), max_batch_latency);
-
- return true;
-}
-
-API bool sensord_set_option(int handle, int option)
-{
- sensor::sensor_listener *listener;
- int pause;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- pause = CONVERT_OPTION_TO_PAUSE_POLICY(option);
-
- if (listener->set_attribute(SENSORD_ATTRIBUTE_PAUSE_POLICY, pause) < 0) {
- _E("Failed to set option[%d(%d)] to listener", option, pause);
- return false;
- }
-
- _D("Set pause option[%d, %d]", listener->get_id(), pause);
-
- return true;
-}
-
-API int sensord_set_attribute_int(int handle, int attribute, int value)
-{
- sensor::sensor_listener *listener;
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), -EINVAL, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- if (listener->set_attribute(attribute, value) < 0) {
- _E("Failed to set attribute[%d, %d]", attribute, value);
- return -EIO;
- }
-
- _D("Set attribute[%d, %d, %d]", listener->get_id(), attribute, value);
-
- return OP_SUCCESS;
-}
-
-API int sensord_get_attribute_int(int handle, int attribute, int* value)
-{
- sensor::sensor_listener *listener;
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), -EINVAL, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- if (listener->get_attribute(attribute, value) < 0) {
- _E("Failed to get attribute[%d]", attribute);
- return -EIO;
- }
-
- _D("Get attribute[%d, %d, %d]", listener->get_id(), attribute, *value);
-
- return OP_SUCCESS;
-}
-
-API int sensord_set_attribute_str(int handle, int attribute, const char *value, int len)
-{
- sensor::sensor_listener *listener;
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), -EINVAL, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- if (listener->set_attribute(attribute, value, len) < 0) {
- _E("Failed to set attribute[%d, %s]", attribute, value);
- return -EIO;
- }
- _D("Set attribute ID[%d], attr[%d], len[%d]", listener->get_id(), attribute, len);
-
- return OP_SUCCESS;
-}
-
-API int sensord_get_attribute_str(int handle, int attribute, char **value, int* len)
-{
- sensor::sensor_listener *listener;
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), -EINVAL, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- if (listener->get_attribute(attribute, value, len) < 0) {
- _E("Failed to get attribute[%d]", attribute);
- return -EIO;
- }
- _D("Get attribute ID[%d], attr[%d], len[%d]", listener->get_id(), attribute, *len);
-
- return OP_SUCCESS;
-}
-
-API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data)
-{
- sensor::sensor_listener *listener;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- if (listener->get_sensor_data(sensor_data) < 0) {
- _E("Failed to get sensor data from listener");
- return false;
- }
-
- return true;
-}
-
-API bool sensord_get_data_list(int handle, unsigned int data_id, sensor_data_t** sensor_data, int* count)
-{
- sensor::sensor_listener *listener;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- if (listener->get_sensor_data_list(sensor_data, count) < 0) {
- _E("Failed to get sensor data from listener");
- return false;
- }
-
- return true;
-}
-
-API bool sensord_flush(int handle)
-{
- sensor::sensor_listener *listener;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- if (listener->flush() < 0) {
- _E("Failed to flush sensor");
- return false;
- }
-
- return true;
-}
-
-API bool sensord_set_passive_mode(int handle, bool passive)
-{
- sensor::sensor_listener *listener;
-
- AUTOLOCK(lock);
-
- auto it = listeners.find(handle);
- retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
-
- listener = it->second;
-
- if (listener->set_passive_mode(passive) < 0) {
- _E("Failed to set passive mode");
- return false;
- }
-
- return true;
-}
-
-/* Sensor Internal API using URI */
-API int sensord_get_default_sensor_by_uri(const char *uri, sensor_t *sensor)
-{
- retvm_if(!sensor, -EINVAL, "Invalid parameter");
- retvm_if(!manager.connect(), -EIO, "Failed to connect");
-
- return manager.get_sensor(uri, sensor);
-}
-
-API int sensord_get_sensors_by_uri(const char *uri, sensor_t **list, int *count)
-{
- retvm_if((!list || !count), -EINVAL, "Invalid parameter");
- retvm_if(!manager.connect(), -EIO, "Failed to connect");
-
- return manager.get_sensors(uri, list, count);
-}
-
-API int sensord_add_sensor_added_cb(sensord_added_cb callback, void *user_data)
-{
- retvm_if(!callback, -EINVAL, "Invalid paramter");
- retvm_if(!manager.connect(), -EIO, "Failed to connect");
-
- manager.add_sensor_added_cb(callback, user_data);
- return OP_SUCCESS;
-}
-
-API int sensord_remove_sensor_added_cb(sensord_added_cb callback)
-{
- retvm_if(!callback, -EINVAL, "Invalid paramter");
- retvm_if(!manager.connect(), -EIO, "Failed to connect");
-
- manager.remove_sensor_added_cb(callback);
- return OP_SUCCESS;
-}
-
-API int sensord_add_sensor_removed_cb(sensord_removed_cb callback, void *user_data)
-{
- retvm_if(!callback, -EINVAL, "Invalid paramter");
- retvm_if(!manager.connect(), -EIO, "Failed to connect");
-
- manager.add_sensor_removed_cb(callback, user_data);
- return OP_SUCCESS;
-}
-
-API int sensord_remove_sensor_removed_cb(sensord_removed_cb callback)
-{
- retvm_if(!callback, -EINVAL, "Invalid paramter");
- retvm_if(!manager.connect(), -EIO, "Failed to connect");
-
- manager.remove_sensor_removed_cb(callback);
- return OP_SUCCESS;
-}
-
-/* Sensor provider */
-API int sensord_create_provider(const char *uri, sensord_provider_h *provider)
-{
- retvm_if(providerCnt >= MAX_PROVIDER, -EPERM, "Exceeded the maximum provider");
- retvm_if(!provider, -EINVAL, "Invalid paramter");
-
- std::string str_uri(uri);
- retvm_if(str_uri.find(PREDEFINED_TYPE_URI) != std::string::npos,
- -EINVAL, "Invalid URI format[%s]", uri);
-
- static std::regex uri_regex(SENSOR_URI_REGEX, std::regex::optimize);
- retvm_if(!std::regex_match(uri, uri_regex),
- -EINVAL, "Invalid URI format[%s]", uri);
-
- sensor_provider *p;
-
- p = new(std::nothrow) sensor_provider(uri);
- retvm_if(!p, -ENOMEM, "Failed to allocate memory");
-
- *provider = static_cast<sensord_provider_h>(p);
- providerCnt++;
- return OP_SUCCESS;
-}
-
-API int sensord_destroy_provider(sensord_provider_h provider)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
-
- delete static_cast<sensor::sensor_provider *>(provider);
- providerCnt--;
- return OP_SUCCESS;
-}
-
-API int sensord_add_provider(sensord_provider_h provider)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
- retvm_if(!manager.connect(), -EIO, "Failed to connect");
-
- int ret;
- sensor_provider *p = static_cast<sensor_provider *>(provider);
-
- ret = p->connect();
- retv_if(ret < 0, ret);
-
- ret = manager.add_sensor(p);
- if (ret < 0) {
- p->disconnect();
- return ret;
- }
-
- return OP_SUCCESS;
-}
-
-API int sensord_remove_provider(sensord_provider_h provider)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
- retvm_if(!manager.connect(), -EIO, "Failed to connect");
-
- int ret;
- sensor_provider *p = static_cast<sensor_provider *>(provider);
-
- if (!p->disconnect())
- return OP_ERROR;
-
- ret = manager.remove_sensor(p);
- if (ret < 0) {
- p->connect();
- return OP_ERROR;
- }
-
- return OP_SUCCESS;
-}
-
-API int sensord_provider_set_name(sensord_provider_h provider, const char *name)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
-
- sensor_provider *p = static_cast<sensor_provider *>(provider);
-
- sensor_info *info = p->get_sensor_info();
- info->set_model(name);
-
- return OP_SUCCESS;
-}
-
-API int sensord_provider_set_vendor(sensord_provider_h provider, const char *vendor)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
-
- sensor_provider *p = static_cast<sensor_provider *>(provider);
-
- sensor_info *info = p->get_sensor_info();
- info->set_vendor(vendor);
-
- return OP_SUCCESS;
-}
-
-API int sensord_provider_set_range(sensord_provider_h provider, float min_range, float max_range)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
-
- sensor_provider *p = static_cast<sensor_provider *>(provider);
-
- sensor_info *info = p->get_sensor_info();
- info->set_min_range(min_range);
- info->set_max_range(max_range);
-
- return OP_SUCCESS;
-}
-
-API int sensord_provider_set_resolution(sensord_provider_h provider, float resolution)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
-
- sensor_provider *p = static_cast<sensor_provider *>(provider);
-
- sensor_info *info = p->get_sensor_info();
- info->set_resolution(resolution);
-
- return OP_SUCCESS;
-}
-
-API int sensord_provider_set_start_cb(sensord_provider_h provider, sensord_provider_start_cb callback, void *user_data)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
- retvm_if(!callback, -EINVAL, "Invalid paramter");
-
- sensor_provider *p = static_cast<sensor_provider *>(provider);
-
- p->set_start_cb(callback, user_data);
-
- return OP_SUCCESS;
-}
-
-API int sensord_provider_set_stop_cb(sensord_provider_h provider, sensord_provider_stop_cb callback, void *user_data)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
- retvm_if(!callback, -EINVAL, "Invalid paramter");
-
- sensor_provider *p = static_cast<sensor_provider *>(provider);
-
- p->set_stop_cb(callback, user_data);
-
- return OP_SUCCESS;
-}
-
-API int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, sensord_provider_interval_changed_cb callback, void *user_data)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
- retvm_if(!callback, -EINVAL, "Invalid paramter");
-
- sensor_provider *p = static_cast<sensor_provider *>(provider);
-
- p->set_interval_cb(callback, user_data);
-
- return OP_SUCCESS;
-}
-
-API int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
- retvm_if(!callback, -EINVAL, "Invalid paramter");
-
- sensor_provider *p = static_cast<sensor_provider *>(provider);
-
- p->set_attribute_str_cb(callback, user_data);
-
- return OP_SUCCESS;
-}
-
-API int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
-
- sensor_provider *p = static_cast<sensor_provider *>(provider);
-
- /* TODO: synchronous call is enough? */
- return p->publish(data);
-}
-
-API int sensord_provider_publish_events(sensord_provider_h provider, sensor_data_t events[], int count)
-{
- retvm_if(!provider, -EINVAL, "Invalid paramter");
-
- sensor_provider *p = static_cast<sensor_provider *>(provider);
-
- return p->publish(events, count);
-};
-
-/* deperecated */
-API sensor_t sensord_get_sensor(sensor_type_t type)
-{
- sensor_t sensor;
-
- if (sensord_get_default_sensor(type, &sensor) < 0)
- return NULL;
-
- return sensor;
-}
-
-/* deprecated */
-API bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count)
-{
- return (sensord_get_sensors(type, list, sensor_count) == OP_SUCCESS);
-}
-
-/* deprecated */
-API bool sensord_register_hub_event(int handle, unsigned int event_type,
- unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data)
-{
- return false;
-}
-
-/* deprecated */
-API bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count)
-{
- /*
- * 1. check parameter
- * 2. if there is no sensor, return false
- * 3. memory allocation
- */
- return true;
-}
-
-/* deprecated(BUT it is used in C-API....) */
-API bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported)
-{
- if (!manager.is_supported(sensor))
- *supported = false;
- else
- *supported = true;
-
- return true;
-}
-
-/* deprecated */
-API bool sensord_send_sensorhub_data(int handle, const char *data, int data_len)
-{
- return (sensord_set_attribute_str(handle, 0, data, data_len) == OP_SUCCESS);
-}
-
-/* deprecated */
-API bool sensord_send_command(int handle, const char *command, int command_len)
-{
- return (sensord_set_attribute_str(handle, 0, command, command_len) == OP_SUCCESS);
-}
-
-/* deprecated */
-API bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege)
-{
- *privilege = SENSOR_PRIVILEGE_PUBLIC;
-
- return true;
-}
-
-/* deprecated */
-API int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data)
-{
- /*
- * 1. check parameter
- * 2. create handle in this client
- * 3. first connection(client)
- * 4. cmd_connect for external sensor with key
- */
- retvm_if(!key, -EINVAL, "Invalid key");
- return 0;
-}
-
-/* deprecated */
-API bool sensord_external_disconnect(int handle)
-{
- /*
- * 1. check parameter
- * 2. create handle in this client
- * 3. first connection(client)
- * 4. cmd_connect for external sensor with key
- * 5. disconnect this handle
- * 6. if there is no active sensor, remove client id and stop listener
- */
- return true;
-}
-
-/* deprecated */
-API bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt)
-{
- /*
- * 1. check parameter
- * 1.1 (data_cnt <= 0) || (data_cnt > POST_DATA_LEN_MAX)), return false
- * 2. cmd_post
- */
-
- return true;
-}
-
diff --git a/src/api/sensor_listener.cpp b/src/api/sensor_listener.cpp
index 7c3ab4b..c0953bf 100644
--- a/src/api/sensor_listener.cpp
+++ b/src/api/sensor_listener.cpp
@@ -20,8 +20,8 @@
#include "sensor_listener.h"
#include <channel_handler.h>
-#include <sensor_log.h>
-#include <sensor_types.h>
+#include <sensor-log.h>
+#include <sensor-types.h>
#include <command_types.h>
#include <ipc_client.h>
diff --git a/src/api/sensor_listener.h b/src/api/sensor_listener.h
index aed8b11..98b6787 100644
--- a/src/api/sensor_listener.h
+++ b/src/api/sensor_listener.h
@@ -25,7 +25,7 @@
#include <channel_handler.h>
#include <event_loop.h>
#include <sensor_info.h>
-#include <sensor_types.h>
+#include <sensor-types.h>
#include <cmutex.h>
#include <map>
#include <atomic>
diff --git a/src/api/sensor_manager.cpp b/src/api/sensor_manager.cpp
index cec6260..89504f6 100644
--- a/src/api/sensor_manager.cpp
+++ b/src/api/sensor_manager.cpp
@@ -19,7 +19,7 @@
#include "sensor_manager.h"
-#include <sensor_log.h>
+#include <sensor-log.h>
#include <sensor_info.h>
#include <sensor_utils.h>
#include <command_types.h>
diff --git a/src/api/sensor_manager.h b/src/api/sensor_manager.h
index a825f3e..770b80d 100644
--- a/src/api/sensor_manager.h
+++ b/src/api/sensor_manager.h
@@ -27,7 +27,7 @@
#include <list>
#include <atomic>
-#include "sensor_internal.h"
+#include "sensor-internal.h"
#include "sensor_provider_internal.h"
namespace sensor {
diff --git a/src/api/sensor_manager_channel_handler.cpp b/src/api/sensor_manager_channel_handler.cpp
index 3feed82..32d5d44 100644
--- a/src/api/sensor_manager_channel_handler.cpp
+++ b/src/api/sensor_manager_channel_handler.cpp
@@ -19,7 +19,7 @@
#include "sensor_manager_channel_handler.h"
-#include <sensor_log.h>
+#include <sensor-log.h>
#include <command_types.h>
#include "sensor_manager.h"
diff --git a/src/api/sensor_manager_channel_handler.h b/src/api/sensor_manager_channel_handler.h
index 99f76ed..024c6f4 100644
--- a/src/api/sensor_manager_channel_handler.h
+++ b/src/api/sensor_manager_channel_handler.h
@@ -20,7 +20,7 @@
#ifndef __SENSOR_MANAGER_CHANNEL_HANDLER__
#define __SENSOR_MANAGER_CHANNEL_HANDLER__
-#include <sensor_internal.h>
+#include <sensor-internal.h>
#include <sensor_manager.h>
#include <channel_handler.h>
#include <map>
diff --git a/src/api/sensor_provider.cpp b/src/api/sensor_provider.cpp
index 1f0dc26..f590388 100644
--- a/src/api/sensor_provider.cpp
+++ b/src/api/sensor_provider.cpp
@@ -15,12 +15,12 @@
*/
#include <sensor.h>
-#include <sensor_private.h>
-#include <sensor_internal.h>
+#include <sensor-private.h>
+#include <sensor-internal.h>
#include <new>
#include <map>
-#include "include/sensor_log.h"
+#include "include/sensor-log.h"
#define RETV_IF(expr, val) \
do { if (expr) { return (val); } } while (0)
@@ -201,4 +201,4 @@ int sensor_provider_publish_events(sensor_provider_h provider, sensor_event_s ev
RETV_IF(result < 0, SENSOR_ERROR_OPERATION_FAILED);
return SENSOR_ERROR_NONE;
-} \ No newline at end of file
+}
diff --git a/src/api/sensor_provider_channel_handler.cpp b/src/api/sensor_provider_channel_handler.cpp
index b39573b..c0aa88f 100644
--- a/src/api/sensor_provider_channel_handler.cpp
+++ b/src/api/sensor_provider_channel_handler.cpp
@@ -20,7 +20,7 @@
#include "sensor_provider_channel_handler.h"
#include <command_types.h>
-#include <sensor_log.h>
+#include <sensor-log.h>
#include "sensor_provider_internal.h"
using namespace sensor;
diff --git a/src/api/sensor_provider_channel_handler.h b/src/api/sensor_provider_channel_handler.h
index aa33006..9f8bfeb 100644
--- a/src/api/sensor_provider_channel_handler.h
+++ b/src/api/sensor_provider_channel_handler.h
@@ -21,7 +21,7 @@
#define __SENSOR_PROVIDER_CHANNEL_HANDLER__
#include <channel_handler.h>
-#include <sensor_internal.h>
+#include <sensor-internal.h>
#include "sensor_provider_internal.h"
namespace sensor {
diff --git a/src/api/sensor_provider_internal.cpp b/src/api/sensor_provider_internal.cpp
index 30762c4..c0471d8 100644
--- a/src/api/sensor_provider_internal.cpp
+++ b/src/api/sensor_provider_internal.cpp
@@ -21,8 +21,8 @@
#include <message.h>
#include <channel.h>
-#include <sensor_log.h>
-#include <sensor_types.h>
+#include <sensor-log.h>
+#include <sensor-types.h>
#include <sensor_utils.h>
#include <ipc_client.h>
#include <command_types.h>
diff --git a/src/api/sensor_provider_internal.h b/src/api/sensor_provider_internal.h
index e694b0e..66e14b1 100644
--- a/src/api/sensor_provider_internal.h
+++ b/src/api/sensor_provider_internal.h
@@ -24,9 +24,9 @@
#include <channel.h>
#include <channel_handler.h>
#include <event_loop.h>
-#include <sensor_internal.h>
+#include <sensor-internal.h>
#include <sensor_info.h>
-#include <sensor_types.h>
+#include <sensor-types.h>
#include <map>
#include <atomic>
diff --git a/src/api/sensor_reader.cpp b/src/api/sensor_reader.cpp
index bc3a7a1..ddfb0e9 100644
--- a/src/api/sensor_reader.cpp
+++ b/src/api/sensor_reader.cpp
@@ -19,8 +19,8 @@
#include "sensor_reader.h"
-#include <sensor_log.h>
-#include <sensor_types.h>
+#include <sensor-log.h>
+#include <sensor-types.h>
#include <chrono>
using namespace sensor;
diff --git a/src/api/sensor_recorder/sensor_recorder.cpp b/src/api/sensor_recorder/sensor_recorder.cpp
index 3139bc1..a20486b 100644
--- a/src/api/sensor_recorder/sensor_recorder.cpp
+++ b/src/api/sensor_recorder/sensor_recorder.cpp
@@ -16,7 +16,7 @@
#include <stdlib.h>
#include <sensor.h>
-#include <sensor_log.h>
+#include <sensor-log.h>
#include <sensor_recorder_internal.h>
#include <map>
#include <string>
diff --git a/src/api/sensor_recorder/sensor_recorder_dummy.cpp b/src/api/sensor_recorder/sensor_recorder_dummy.cpp
index 669afae..6eadce3 100644
--- a/src/api/sensor_recorder/sensor_recorder_dummy.cpp
+++ b/src/api/sensor_recorder/sensor_recorder_dummy.cpp
@@ -16,7 +16,7 @@
#include <stdlib.h>
#include <sensor.h>
-#include <sensor_log.h>
+#include <sensor-log.h>
int sensor_recorder_is_supported(sensor_type_e type, bool *supported)
{
diff --git a/src/shared/accept_event_handler.cpp b/src/shared/accept_event_handler.cpp
index 419d912..2030abc 100644
--- a/src/shared/accept_event_handler.cpp
+++ b/src/shared/accept_event_handler.cpp
@@ -19,7 +19,7 @@
#include "accept_event_handler.h"
-#include "sensor_log.h"
+#include "sensor-log.h"
#include "ipc_server.h"
using namespace ipc;
diff --git a/src/shared/cbase_lock.cpp b/src/shared/cbase_lock.cpp
index eafd601..02026f1 100644
--- a/src/shared/cbase_lock.cpp
+++ b/src/shared/cbase_lock.cpp
@@ -22,7 +22,7 @@
#include <errno.h>
#include <sys/time.h>
#include <cbase_lock.h>
-#include <sensor_log.h>
+#include <sensor-log.h>
using namespace sensor;
diff --git a/src/shared/channel.cpp b/src/shared/channel.cpp
index 26b654c..11b1ba9 100644
--- a/src/shared/channel.cpp
+++ b/src/shared/channel.cpp
@@ -24,7 +24,7 @@
#include <memory>
#include <algorithm>
-#include "sensor_log.h"
+#include "sensor-log.h"
#include "channel_event_handler.h"
#define SYSTEMD_SOCK_BUF_SIZE (128*1024)
diff --git a/src/shared/channel_event_handler.cpp b/src/shared/channel_event_handler.cpp
index 460b6a0..4d9ef07 100644
--- a/src/shared/channel_event_handler.cpp
+++ b/src/shared/channel_event_handler.cpp
@@ -21,7 +21,7 @@
#include "channel.h"
#include "channel_handler.h"
-#include "sensor_log.h"
+#include "sensor-log.h"
using namespace ipc;
diff --git a/src/shared/cmutex.cpp b/src/shared/cmutex.cpp
index d3d19dd..0ffc28d 100644
--- a/src/shared/cmutex.cpp
+++ b/src/shared/cmutex.cpp
@@ -18,7 +18,7 @@
*/
#include <cmutex.h>
-#include <sensor_log.h>
+#include <sensor-log.h>
using namespace sensor;
diff --git a/src/shared/command_types.h b/src/shared/command_types.h
index 29aaf86..1e2218c 100644
--- a/src/shared/command_types.h
+++ b/src/shared/command_types.h
@@ -20,7 +20,7 @@
#ifndef __COMMAND_TYPES_H__
#define __COMMAND_TYPES_H__
-#include <sensor_types.h>
+#include <sensor-types.h>
#include "sensor_info.h"
#define SENSOR_CHANNEL_PATH "/run/.sensord.socket"
diff --git a/src/shared/event_loop.cpp b/src/shared/event_loop.cpp
index 720687b..6185ba2 100644
--- a/src/shared/event_loop.cpp
+++ b/src/shared/event_loop.cpp
@@ -30,7 +30,7 @@
#include <queue>
#include "channel_event_handler.h"
-#include "sensor_log.h"
+#include "sensor-log.h"
#include "event_handler.h"
#include "channel.h"
diff --git a/src/shared/ipc_client.cpp b/src/shared/ipc_client.cpp
index 26c20a3..5af2852 100644
--- a/src/shared/ipc_client.cpp
+++ b/src/shared/ipc_client.cpp
@@ -19,7 +19,7 @@
#include "ipc_client.h"
-#include "sensor_log.h"
+#include "sensor-log.h"
#include "stream_socket.h"
#include "event_handler.h"
#include "channel_event_handler.h"
diff --git a/src/shared/ipc_server.cpp b/src/shared/ipc_server.cpp
index d25a562..9d204e8 100644
--- a/src/shared/ipc_server.cpp
+++ b/src/shared/ipc_server.cpp
@@ -20,7 +20,7 @@
#include "ipc_server.h"
#include "channel.h"
-#include "sensor_log.h"
+#include "sensor-log.h"
#include "event_loop.h"
#include "channel_event_handler.h"
#include "accept_event_handler.h"
diff --git a/src/shared/message.cpp b/src/shared/message.cpp
index 5f12d23..8d4bbe6 100644
--- a/src/shared/message.cpp
+++ b/src/shared/message.cpp
@@ -19,7 +19,7 @@
#include "message.h"
-#include <sensor_log.h>
+#include <sensor-log.h>
#include <atomic>
using namespace ipc;
diff --git a/src/shared/sensor_info.cpp b/src/shared/sensor_info.cpp
index f060083..b6de3ff 100644
--- a/src/shared/sensor_info.cpp
+++ b/src/shared/sensor_info.cpp
@@ -19,9 +19,9 @@
#include "sensor_info.h"
-#include <sensor_types.h>
+#include <sensor-types.h>
#include <sensor_types_private.h>
-#include <sensor_log.h>
+#include <sensor-log.h>
#include <cfloat>
#include <algorithm>
#include <string>
diff --git a/src/shared/sensor_info.h b/src/shared/sensor_info.h
index cbd5406..dd816cd 100644
--- a/src/shared/sensor_info.h
+++ b/src/shared/sensor_info.h
@@ -24,7 +24,7 @@
#include <string>
#include <vector>
#include <hal/hal-sensor-types.h>
-#include <sensor_types.h>
+#include <sensor-types.h>
namespace sensor {
diff --git a/src/shared/sensor_utils.cpp b/src/shared/sensor_utils.cpp
index 58a5978..9bd178d 100644
--- a/src/shared/sensor_utils.cpp
+++ b/src/shared/sensor_utils.cpp
@@ -28,8 +28,8 @@
#include <stddef.h>
#include <map>
-#include <sensor_log.h>
-#include <sensor_types.h>
+#include <sensor-log.h>
+#include <sensor-types.h>
#include <sensor_types_private.h>
#ifndef PATH_MAX
diff --git a/src/shared/sensor_utils.h b/src/shared/sensor_utils.h
index 3497dc7..b5bd95a 100644
--- a/src/shared/sensor_utils.h
+++ b/src/shared/sensor_utils.h
@@ -21,7 +21,7 @@
#define __SENSOR_UTILS_H__
#include <time.h>
-#include <sensor_types.h>
+#include <sensor-types.h>
#include <string>
#include <vector>
diff --git a/src/shared/seqpacket_socket.cpp b/src/shared/seqpacket_socket.cpp
index ad27394..cd0ea08 100644
--- a/src/shared/seqpacket_socket.cpp
+++ b/src/shared/seqpacket_socket.cpp
@@ -22,7 +22,7 @@
#include <sys/types.h>
#include <sys/socket.h>
-#include "sensor_log.h"
+#include "sensor-log.h"
using namespace ipc;
diff --git a/src/shared/socket.cpp b/src/shared/socket.cpp
index 6d11076..bbf4c8d 100644
--- a/src/shared/socket.cpp
+++ b/src/shared/socket.cpp
@@ -27,7 +27,7 @@
#include <sys/ioctl.h>
#include <systemd/sd-daemon.h>
-#include "sensor_log.h"
+#include "sensor-log.h"
#define SOCK_TIMEOUT 10
diff --git a/src/shared/stream_socket.cpp b/src/shared/stream_socket.cpp
index e583f26..18df444 100644
--- a/src/shared/stream_socket.cpp
+++ b/src/shared/stream_socket.cpp
@@ -22,7 +22,7 @@
#include <sys/types.h>
#include <sys/socket.h>
-#include "sensor_log.h"
+#include "sensor-log.h"
#define SLEEP_10_MS usleep(10000)