#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"
{
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
*
*/
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
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 _SENSOR_LOG_H_
+#define _SENSOR_LOG_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <dlog/dlog.h>
+#include <sys/types.h>
+
+#ifdef LOG_TAG
+ #undef LOG_TAG
+#endif
+#define LOG_TAG "TIZEN_SYSTEM_SENSOR"
+
+/* Logging and Error Handling */
+#define _I SLOGI
+#define _D SLOGD
+#define _W SLOGW
+#define _E SLOGE
+#define _SI SECURE_SLOGI
+#define _SD SECURE_SLOGD
+#define _SW SECURE_SLOGW
+#define _SE SECURE_SLOGE
+
+#define _ERRNO(errno, tag, fmt, arg...) \
+ do { \
+ char buf[1024]; \
+ char *error = strerror_r(errno, buf, 1024); \
+ if (!error) { \
+ _E("Failed to strerror_r()"); \
+ break; \
+ } \
+ tag(fmt" (%s[%d])", ##arg, error, errno); \
+ } while (0)
+
+#define warn_if(expr, fmt, arg...) \
+ do { if (expr) { _E(fmt, ##arg); } } while (0)
+
+#define ret_if(expr) \
+ do { if (expr) { return; } } while (0)
+
+#define retv_if(expr, val) \
+ do { if (expr) { return (val); } } while (0)
+
+#define retm_if(expr, fmt, arg...) \
+ do { if (expr) { _E(fmt, ##arg); return; } } while (0)
+
+#define retvm_if(expr, val, fmt, arg...) \
+ do { if (expr) { _E(fmt, ##arg); return (val); } } while (0)
+
+#define LOG_DUMP(fp, fmt, arg...) \
+ do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while (0)
+
+#define log_oom() ({ \
+ _E("Out of memory"); \
+ -ENOMEM;})
+
+
+#define _MSG_SENSOR_ERROR_IO_ERROR "Io Error"
+#define _MSG_SENSOR_ERROR_INVALID_PARAMETER "Invalid Parameter"
+#define _MSG_SENSOR_ERROR_OUT_OF_MEMORY "Out of Memory"
+#define _MSG_SENSOR_ERROR_NOT_NEED_CALIBRATION "Not need calibration"
+#define _MSG_SENSOR_ERROR_NOT_SUPPORTED "Not supported"
+#define _MSG_SENSOR_ERROR_OPERATION_FAILED "Operation failed"
+
+#define _E_MSG(err) SLOGE(_MSG_##err "(0x%08x)", (err))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SENSOR_LOG_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 __SENSOR_PRIVATE_H__
+#define __SENSOR_PRIVATE_H__
+
+struct sensor_listener_s {
+ int id;
+ int type;
+ int pause;
+ unsigned int batch_latency;
+ unsigned int magic;
+ void *sensor;
+ void *callback;
+ void *user_data;
+ void *accu_callback;
+ void *accu_user_data;
+};
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+float clamp(float v);
+int getAngleChange(float *R, float *prevR, float *angleChange);
+int quatToMatrix(float *quat, float *R);
+int matrixToQuat(float *mat, float *q);
+int getRotationMatrix(float *accel, float *geo, float *R, float *I);
+int remapCoordinateSystem(float *inR, int X, int Y, float *outR);
+int getDeclination(float *decl);
+int getInclination(float *incl);
+int setCoordinate(float latitude, float longitude, float altitude, float *declination, float *inclination, int option);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __SENSOR_PRIVATE_H__
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2016 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 __SENSOR_TYPES_H__
+#define __SENSOR_TYPES_H__
+
+/* TODO: It is for compatibility with capi-system-sensor */
+#define __SENSOR_COMMON_H__
+
+#include <stddef.h>
+#include <stdint.h>
+#include <hal/hal-sensor-types.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifndef OP_SUCCESS
+#define OP_SUCCESS 0
+#endif
+#ifndef OP_ERROR
+#define OP_ERROR -1
+#endif
+#ifndef OP_DEFAULT
+#define OP_DEFAULT 1
+#endif
+#ifndef OP_CONTINUE
+#define OP_CONTINUE 2
+#endif
+#ifndef NAME_MAX
+#define NAME_MAX 256
+#endif
+
+#define SENSOR_TYPE_SHIFT 32
+#define SENSOR_EVENT_SHIFT 16
+#define SENSOR_INDEX_MASK 0xFFFFFFFF
+
+#define CONVERT_ID_TYPE(id) ((id) >> SENSOR_TYPE_SHIFT)
+#define CONVERT_TYPE_EVENT(type) ((type) << SENSOR_EVENT_SHIFT | 0x1)
+
+#define MICROSECONDS(tv) ((tv.tv_sec * 1000000ll) + tv.tv_usec)
+
+#define SENSOR_UNKNOWN_TYPE "http://tizen.org/sensor/unknown"
+#define SENSOR_UNKNOWN_NAME "Unknown"
+
+typedef int64_t sensor_id_t;
+typedef void *sensor_t;
+
+typedef enum sensor_type_t {
+ UNKNOWN_SENSOR = -2,
+ ALL_SENSOR = -1,
+ ACCELEROMETER_SENSOR = 0,
+ GRAVITY_SENSOR,
+ LINEAR_ACCEL_SENSOR,
+ GEOMAGNETIC_SENSOR,
+ ROTATION_VECTOR_SENSOR,
+ ORIENTATION_SENSOR,
+ GYROSCOPE_SENSOR,
+ LIGHT_SENSOR,
+ PROXIMITY_SENSOR,
+ PRESSURE_SENSOR,
+ ULTRAVIOLET_SENSOR,
+ TEMPERATURE_SENSOR,
+ HUMIDITY_SENSOR,
+ HRM_SENSOR,
+ BIO_HRM_SENSOR = HRM_SENSOR,
+ HRM_LED_GREEN_SENSOR,
+ BIO_LED_GREEN_SENSOR = HRM_LED_GREEN_SENSOR,
+ HRM_LED_IR_SENSOR,
+ BIO_LED_IR_SENSOR = HRM_LED_IR_SENSOR,
+ HRM_LED_RED_SENSOR,
+ BIO_LED_RED_SENSOR = HRM_LED_RED_SENSOR,
+ GYROSCOPE_UNCAL_SENSOR,
+ GEOMAGNETIC_UNCAL_SENSOR,
+ GYROSCOPE_RV_SENSOR,
+ GEOMAGNETIC_RV_SENSOR,
+
+ GYROSCOPE_ORIENTATION_SENSOR = 100,
+ GEOMAGNETIC_ORIENTATION_SENSOR = 105,
+
+ SIGNIFICANT_MOTION_SENSOR = 0x100, //256
+
+ HRM_BATCH_SENSOR = 0x200, //512
+ HRM_LED_GREEN_BATCH_SENSOR,
+
+ HUMAN_PEDOMETER_SENSOR = 0x300, //768
+ HUMAN_SLEEP_MONITOR_SENSOR,
+ HUMAN_SLEEP_DETECTOR_SENSOR,
+ SLEEP_DETECTOR_SENSOR = HUMAN_SLEEP_DETECTOR_SENSOR,
+ HUMAN_STRESS_MONITOR_SENSOR,
+ STRESS_MONITOR_SENSOR = HUMAN_STRESS_MONITOR_SENSOR,
+
+ LIDAR_SENSOR = 1000,
+
+ EXERCISE_WALKING_SENSOR = 0x400, //1024
+ EXERCISE_RUNNING_SENSOR,
+ EXERCISE_HIKING_SENSOR,
+ EXERCISE_CYCLING_SENSOR,
+ EXERCISE_ELLIPTICAL_SENSOR,
+ EXERCISE_INDOOR_CYCLING_SENSOR,
+ EXERCISE_ROWING_SENSOR,
+ EXERCISE_STEPPER_SENSOR,
+
+ DATA_JOURNAL_SENSOR = 0x500,
+ // 0x500~0x600 Reserved (1280 ~ 1536)
+
+ EXTERNAL_EXERCISE_SENSOR = 0x800, //2048
+ EXERCISE_SENSOR = EXTERNAL_EXERCISE_SENSOR,
+
+ FUSION_SENSOR = 0x900, //2304
+ AUTO_ROTATION_SENSOR,
+ AUTO_BRIGHTNESS_SENSOR,
+ MYOTEST_SENSOR,
+
+ GESTURE_MOVEMENT_SENSOR = 0x1200, //4608
+ GESTURE_WRIST_UP_SENSOR,
+ GESTURE_WRIST_DOWN_SENSOR,
+ GESTURE_MOVEMENT_STATE_SENSOR,
+ GESTURE_PICK_UP_SENSOR,
+ GESTURE_FACE_DOWN_SENSOR,
+
+ ACTIVITY_TRACKER_SENSOR = 0x1A00, //6656
+ ACTIVITY_LEVEL_MONITOR_SENSOR,
+ GPS_BATCH_SENSOR,
+ PPG_BATCH_SENSOR,
+ GPS_TIMESYNC_SENSOR,
+
+ HRM_CTRL_SENSOR = 0x1A80, //6784
+ REG_CTRL_SENSOR,
+ GPS_CTRL_SENSOR,
+
+ WEAR_STATUS_SENSOR = 0x2000, //8192
+ WEAR_ON_MONITOR_SENSOR,
+ NO_MOVE_DETECTOR_SENSOR,
+ RESTING_HR_SENSOR,
+ STEP_LEVEL_MONITOR_SENSOR,
+ EXERCISE_STANDALONE_SENSOR,
+ EXERCISE_COACH_SENSOR = EXERCISE_STANDALONE_SENSOR,
+ EXERCISE_HR_SENSOR,
+ WORKOUT_SENSOR,
+ AUTOSESSION_EXERCISE_SENSOR = WORKOUT_SENSOR,
+ CYCLE_MONITOR_SENSOR,
+ STAIR_TRACKER_SENSOR,
+ PRESSURE_INDICATOR_SENSOR,
+ PRESSURE_ALERT_SENSOR,
+ HR_CALORIE_SENSOR,
+ SWIMMING_TRACKER_SENSOR,
+ STRESS_TRACKER_SENSOR,
+ FAKE_MOTION_SENSOR,
+ GEOFENCE_SENSOR,
+ SWIMMING_OUTDOOR_SENSOR,
+ AUTO_SWIMMING_SENSOR,
+ INACTIVITY_DETECTOR_SENSOR,
+ HRM_BP_SENSOR,
+ ECG_SENSOR,
+ FALL_DETECTION_SENSOR,
+
+ CONTEXT_SENSOR = 0x7000, //28,672
+ MOTION_SENSOR,
+ PIR_SENSOR,
+ PIR_LONG_SENSOR,
+ DUST_SENSOR,
+ THERMOMETER_SENSOR,
+ PEDOMETER_SENSOR,
+ FLAT_SENSOR,
+ HRM_RAW_SENSOR,
+ BIO_SENSOR = HRM_RAW_SENSOR,
+ TILT_SENSOR,
+ RV_RAW_SENSOR,
+ GSR_SENSOR,
+ SIMSENSE_SENSOR,
+ PPG_SENSOR,
+
+ CUSTOM_SENSOR = 0X9000, //36,864
+} sensor_type_t;
+
+typedef struct sensor_info2_t {
+ uint32_t id;
+ sensor_type_t type;
+ const char *uri;
+ const char *vendor;
+ float min_range;
+ float max_range;
+ float resolution;
+ int min_interval;
+ int max_interval;
+ int max_batch_count;
+ bool wakeup_supported;
+ const char *privilege;
+ void *reserved[8];
+} sensor_info2_t;
+
+typedef enum sensor_privilege_t {
+ SENSOR_PRIVILEGE_PUBLIC = 0,
+} sensor_privilege_t;
+
+typedef struct sensor_event_t {
+ unsigned int event_type;
+ sensor_id_t sensor_id;
+ unsigned int data_length;
+ sensor_data_t *data;
+} sensor_event_t;
+
+/*
+ * To prevent naming confliction as using same enums as sensor CAPI use
+ */
+#ifndef __SENSOR_H__
+enum sensor_option_t {
+ SENSOR_OPTION_DEFAULT = 0,
+ SENSOR_OPTION_ON_IN_SCREEN_OFF = 1,
+ SENSOR_OPTION_ON_IN_POWERSAVE_MODE = 2,
+ SENSOR_OPTION_ALWAYS_ON = SENSOR_OPTION_ON_IN_SCREEN_OFF | SENSOR_OPTION_ON_IN_POWERSAVE_MODE,
+ SENSOR_OPTION_END
+};
+
+typedef enum sensor_option_t sensor_option_e;
+#endif
+
+enum sensord_attribute_e {
+ SENSORD_ATTRIBUTE_AXIS_ORIENTATION = 1,
+ SENSORD_ATTRIBUTE_PAUSE_POLICY,
+ SENSORD_ATTRIBUTE_INTERVAL = 0x10,
+ SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY,
+ SENSORD_ATTRIBUTE_PASSIVE_MODE,
+ SENSORD_ATTRIBUTE_FLUSH,
+ // 0x50~0x80 Reserved
+};
+
+enum sensord_axis_e {
+ SENSORD_AXIS_DEVICE_ORIENTED = 1,
+ SENSORD_AXIS_DISPLAY_ORIENTED,
+};
+
+enum sensord_pause_e {
+ SENSORD_PAUSE_NONE = 0,
+ SENSORD_PAUSE_ON_DISPLAY_OFF = 1,
+ SENSORD_PAUSE_ON_POWERSAVE_MODE = 2,
+ SENSORD_PAUSE_ALL = 3,
+ SENSORD_PAUSE_END,
+};
+
+enum poll_interval_t {
+ POLL_100HZ_MS = 10,
+ POLL_50HZ_MS = 20,
+ POLL_25HZ_MS = 40,
+ POLL_20HZ_MS = 50,
+ POLL_10HZ_MS = 100,
+ POLL_5HZ_MS = 200,
+ POLL_1HZ_MS = 1000,
+ POLL_MAX_HZ_MS = 255000,
+};
+
+#define DEFAULT_INTERVAL POLL_10HZ_MS
+
+enum sensor_interval_t {
+ SENSOR_INTERVAL_FASTEST = POLL_100HZ_MS,
+ SENSOR_INTERVAL_NORMAL = POLL_5HZ_MS,
+};
+
+enum proxi_change_state {
+ PROXIMITY_STATE_NEAR = 0,
+ PROXIMITY_STATE_FAR = 1,
+};
+
+enum auto_rotation_state {
+ AUTO_ROTATION_DEGREE_UNKNOWN = 0,
+ AUTO_ROTATION_DEGREE_0,
+ AUTO_ROTATION_DEGREE_90,
+ AUTO_ROTATION_DEGREE_180,
+ AUTO_ROTATION_DEGREE_270,
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SENSOR_TYPES_H__ */
+++ /dev/null
-/*
- * 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__ */
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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 _SENSOR_LOG_H_
-#define _SENSOR_LOG_H_
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include <dlog/dlog.h>
-#include <sys/types.h>
-
-#ifdef LOG_TAG
- #undef LOG_TAG
-#endif
-#define LOG_TAG "TIZEN_SYSTEM_SENSOR"
-
-/* Logging and Error Handling */
-#define _I SLOGI
-#define _D SLOGD
-#define _W SLOGW
-#define _E SLOGE
-#define _SI SECURE_SLOGI
-#define _SD SECURE_SLOGD
-#define _SW SECURE_SLOGW
-#define _SE SECURE_SLOGE
-
-#define _ERRNO(errno, tag, fmt, arg...) \
- do { \
- char buf[1024]; \
- char *error = strerror_r(errno, buf, 1024); \
- if (!error) { \
- _E("Failed to strerror_r()"); \
- break; \
- } \
- tag(fmt" (%s[%d])", ##arg, error, errno); \
- } while (0)
-
-#define warn_if(expr, fmt, arg...) \
- do { if (expr) { _E(fmt, ##arg); } } while (0)
-
-#define ret_if(expr) \
- do { if (expr) { return; } } while (0)
-
-#define retv_if(expr, val) \
- do { if (expr) { return (val); } } while (0)
-
-#define retm_if(expr, fmt, arg...) \
- do { if (expr) { _E(fmt, ##arg); return; } } while (0)
-
-#define retvm_if(expr, val, fmt, arg...) \
- do { if (expr) { _E(fmt, ##arg); return (val); } } while (0)
-
-#define LOG_DUMP(fp, fmt, arg...) \
- do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while (0)
-
-#define log_oom() ({ \
- _E("Out of memory"); \
- -ENOMEM;})
-
-
-#define _MSG_SENSOR_ERROR_IO_ERROR "Io Error"
-#define _MSG_SENSOR_ERROR_INVALID_PARAMETER "Invalid Parameter"
-#define _MSG_SENSOR_ERROR_OUT_OF_MEMORY "Out of Memory"
-#define _MSG_SENSOR_ERROR_NOT_NEED_CALIBRATION "Not need calibration"
-#define _MSG_SENSOR_ERROR_NOT_SUPPORTED "Not supported"
-#define _MSG_SENSOR_ERROR_OPERATION_FAILED "Operation failed"
-
-#define _E_MSG(err) SLOGE(_MSG_##err "(0x%08x)", (err))
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _SENSOR_LOG_H_ */
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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 __SENSOR_PRIVATE_H__
-#define __SENSOR_PRIVATE_H__
-
-struct sensor_listener_s {
- int id;
- int type;
- int pause;
- unsigned int batch_latency;
- unsigned int magic;
- void *sensor;
- void *callback;
- void *user_data;
- void *accu_callback;
- void *accu_user_data;
-};
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-float clamp(float v);
-int getAngleChange(float *R, float *prevR, float *angleChange);
-int quatToMatrix(float *quat, float *R);
-int matrixToQuat(float *mat, float *q);
-int getRotationMatrix(float *accel, float *geo, float *R, float *I);
-int remapCoordinateSystem(float *inR, int X, int Y, float *outR);
-int getDeclination(float *decl);
-int getInclination(float *incl);
-int setCoordinate(float latitude, float longitude, float altitude, float *declination, float *inclination, int option);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // __SENSOR_PRIVATE_H__
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2016 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 __SENSOR_TYPES_H__
-#define __SENSOR_TYPES_H__
-
-/* TODO: It is for compatibility with capi-system-sensor */
-#define __SENSOR_COMMON_H__
-
-#include <stddef.h>
-#include <stdint.h>
-#include <hal/hal-sensor-types.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#ifndef OP_SUCCESS
-#define OP_SUCCESS 0
-#endif
-#ifndef OP_ERROR
-#define OP_ERROR -1
-#endif
-#ifndef OP_DEFAULT
-#define OP_DEFAULT 1
-#endif
-#ifndef OP_CONTINUE
-#define OP_CONTINUE 2
-#endif
-#ifndef NAME_MAX
-#define NAME_MAX 256
-#endif
-
-#define SENSOR_TYPE_SHIFT 32
-#define SENSOR_EVENT_SHIFT 16
-#define SENSOR_INDEX_MASK 0xFFFFFFFF
-
-#define CONVERT_ID_TYPE(id) ((id) >> SENSOR_TYPE_SHIFT)
-#define CONVERT_TYPE_EVENT(type) ((type) << SENSOR_EVENT_SHIFT | 0x1)
-
-#define MICROSECONDS(tv) ((tv.tv_sec * 1000000ll) + tv.tv_usec)
-
-#define SENSOR_UNKNOWN_TYPE "http://tizen.org/sensor/unknown"
-#define SENSOR_UNKNOWN_NAME "Unknown"
-
-typedef int64_t sensor_id_t;
-typedef void *sensor_t;
-
-typedef enum sensor_type_t {
- UNKNOWN_SENSOR = -2,
- ALL_SENSOR = -1,
- ACCELEROMETER_SENSOR = 0,
- GRAVITY_SENSOR,
- LINEAR_ACCEL_SENSOR,
- GEOMAGNETIC_SENSOR,
- ROTATION_VECTOR_SENSOR,
- ORIENTATION_SENSOR,
- GYROSCOPE_SENSOR,
- LIGHT_SENSOR,
- PROXIMITY_SENSOR,
- PRESSURE_SENSOR,
- ULTRAVIOLET_SENSOR,
- TEMPERATURE_SENSOR,
- HUMIDITY_SENSOR,
- HRM_SENSOR,
- BIO_HRM_SENSOR = HRM_SENSOR,
- HRM_LED_GREEN_SENSOR,
- BIO_LED_GREEN_SENSOR = HRM_LED_GREEN_SENSOR,
- HRM_LED_IR_SENSOR,
- BIO_LED_IR_SENSOR = HRM_LED_IR_SENSOR,
- HRM_LED_RED_SENSOR,
- BIO_LED_RED_SENSOR = HRM_LED_RED_SENSOR,
- GYROSCOPE_UNCAL_SENSOR,
- GEOMAGNETIC_UNCAL_SENSOR,
- GYROSCOPE_RV_SENSOR,
- GEOMAGNETIC_RV_SENSOR,
-
- GYROSCOPE_ORIENTATION_SENSOR = 100,
- GEOMAGNETIC_ORIENTATION_SENSOR = 105,
-
- SIGNIFICANT_MOTION_SENSOR = 0x100, //256
-
- HRM_BATCH_SENSOR = 0x200, //512
- HRM_LED_GREEN_BATCH_SENSOR,
-
- HUMAN_PEDOMETER_SENSOR = 0x300, //768
- HUMAN_SLEEP_MONITOR_SENSOR,
- HUMAN_SLEEP_DETECTOR_SENSOR,
- SLEEP_DETECTOR_SENSOR = HUMAN_SLEEP_DETECTOR_SENSOR,
- HUMAN_STRESS_MONITOR_SENSOR,
- STRESS_MONITOR_SENSOR = HUMAN_STRESS_MONITOR_SENSOR,
-
- LIDAR_SENSOR = 1000,
-
- EXERCISE_WALKING_SENSOR = 0x400, //1024
- EXERCISE_RUNNING_SENSOR,
- EXERCISE_HIKING_SENSOR,
- EXERCISE_CYCLING_SENSOR,
- EXERCISE_ELLIPTICAL_SENSOR,
- EXERCISE_INDOOR_CYCLING_SENSOR,
- EXERCISE_ROWING_SENSOR,
- EXERCISE_STEPPER_SENSOR,
-
- DATA_JOURNAL_SENSOR = 0x500,
- // 0x500~0x600 Reserved (1280 ~ 1536)
-
- EXTERNAL_EXERCISE_SENSOR = 0x800, //2048
- EXERCISE_SENSOR = EXTERNAL_EXERCISE_SENSOR,
-
- FUSION_SENSOR = 0x900, //2304
- AUTO_ROTATION_SENSOR,
- AUTO_BRIGHTNESS_SENSOR,
- MYOTEST_SENSOR,
-
- GESTURE_MOVEMENT_SENSOR = 0x1200, //4608
- GESTURE_WRIST_UP_SENSOR,
- GESTURE_WRIST_DOWN_SENSOR,
- GESTURE_MOVEMENT_STATE_SENSOR,
- GESTURE_PICK_UP_SENSOR,
- GESTURE_FACE_DOWN_SENSOR,
-
- ACTIVITY_TRACKER_SENSOR = 0x1A00, //6656
- ACTIVITY_LEVEL_MONITOR_SENSOR,
- GPS_BATCH_SENSOR,
- PPG_BATCH_SENSOR,
- GPS_TIMESYNC_SENSOR,
-
- HRM_CTRL_SENSOR = 0x1A80, //6784
- REG_CTRL_SENSOR,
- GPS_CTRL_SENSOR,
-
- WEAR_STATUS_SENSOR = 0x2000, //8192
- WEAR_ON_MONITOR_SENSOR,
- NO_MOVE_DETECTOR_SENSOR,
- RESTING_HR_SENSOR,
- STEP_LEVEL_MONITOR_SENSOR,
- EXERCISE_STANDALONE_SENSOR,
- EXERCISE_COACH_SENSOR = EXERCISE_STANDALONE_SENSOR,
- EXERCISE_HR_SENSOR,
- WORKOUT_SENSOR,
- AUTOSESSION_EXERCISE_SENSOR = WORKOUT_SENSOR,
- CYCLE_MONITOR_SENSOR,
- STAIR_TRACKER_SENSOR,
- PRESSURE_INDICATOR_SENSOR,
- PRESSURE_ALERT_SENSOR,
- HR_CALORIE_SENSOR,
- SWIMMING_TRACKER_SENSOR,
- STRESS_TRACKER_SENSOR,
- FAKE_MOTION_SENSOR,
- GEOFENCE_SENSOR,
- SWIMMING_OUTDOOR_SENSOR,
- AUTO_SWIMMING_SENSOR,
- INACTIVITY_DETECTOR_SENSOR,
- HRM_BP_SENSOR,
- ECG_SENSOR,
- FALL_DETECTION_SENSOR,
-
- CONTEXT_SENSOR = 0x7000, //28,672
- MOTION_SENSOR,
- PIR_SENSOR,
- PIR_LONG_SENSOR,
- DUST_SENSOR,
- THERMOMETER_SENSOR,
- PEDOMETER_SENSOR,
- FLAT_SENSOR,
- HRM_RAW_SENSOR,
- BIO_SENSOR = HRM_RAW_SENSOR,
- TILT_SENSOR,
- RV_RAW_SENSOR,
- GSR_SENSOR,
- SIMSENSE_SENSOR,
- PPG_SENSOR,
-
- CUSTOM_SENSOR = 0X9000, //36,864
-} sensor_type_t;
-
-typedef struct sensor_info2_t {
- uint32_t id;
- sensor_type_t type;
- const char *uri;
- const char *vendor;
- float min_range;
- float max_range;
- float resolution;
- int min_interval;
- int max_interval;
- int max_batch_count;
- bool wakeup_supported;
- const char *privilege;
- void *reserved[8];
-} sensor_info2_t;
-
-typedef enum sensor_privilege_t {
- SENSOR_PRIVILEGE_PUBLIC = 0,
-} sensor_privilege_t;
-
-typedef struct sensor_event_t {
- unsigned int event_type;
- sensor_id_t sensor_id;
- unsigned int data_length;
- sensor_data_t *data;
-} sensor_event_t;
-
-/*
- * To prevent naming confliction as using same enums as sensor CAPI use
- */
-#ifndef __SENSOR_H__
-enum sensor_option_t {
- SENSOR_OPTION_DEFAULT = 0,
- SENSOR_OPTION_ON_IN_SCREEN_OFF = 1,
- SENSOR_OPTION_ON_IN_POWERSAVE_MODE = 2,
- SENSOR_OPTION_ALWAYS_ON = SENSOR_OPTION_ON_IN_SCREEN_OFF | SENSOR_OPTION_ON_IN_POWERSAVE_MODE,
- SENSOR_OPTION_END
-};
-
-typedef enum sensor_option_t sensor_option_e;
-#endif
-
-enum sensord_attribute_e {
- SENSORD_ATTRIBUTE_AXIS_ORIENTATION = 1,
- SENSORD_ATTRIBUTE_PAUSE_POLICY,
- SENSORD_ATTRIBUTE_INTERVAL = 0x10,
- SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY,
- SENSORD_ATTRIBUTE_PASSIVE_MODE,
- SENSORD_ATTRIBUTE_FLUSH,
- // 0x50~0x80 Reserved
-};
-
-enum sensord_axis_e {
- SENSORD_AXIS_DEVICE_ORIENTED = 1,
- SENSORD_AXIS_DISPLAY_ORIENTED,
-};
-
-enum sensord_pause_e {
- SENSORD_PAUSE_NONE = 0,
- SENSORD_PAUSE_ON_DISPLAY_OFF = 1,
- SENSORD_PAUSE_ON_POWERSAVE_MODE = 2,
- SENSORD_PAUSE_ALL = 3,
- SENSORD_PAUSE_END,
-};
-
-enum poll_interval_t {
- POLL_100HZ_MS = 10,
- POLL_50HZ_MS = 20,
- POLL_25HZ_MS = 40,
- POLL_20HZ_MS = 50,
- POLL_10HZ_MS = 100,
- POLL_5HZ_MS = 200,
- POLL_1HZ_MS = 1000,
- POLL_MAX_HZ_MS = 255000,
-};
-
-#define DEFAULT_INTERVAL POLL_10HZ_MS
-
-enum sensor_interval_t {
- SENSOR_INTERVAL_FASTEST = POLL_100HZ_MS,
- SENSOR_INTERVAL_NORMAL = POLL_5HZ_MS,
-};
-
-enum proxi_change_state {
- PROXIMITY_STATE_NEAR = 0,
- PROXIMITY_STATE_FAR = 1,
-};
-
-enum auto_rotation_state {
- AUTO_ROTATION_DEGREE_UNKNOWN = 0,
- AUTO_ROTATION_DEGREE_0,
- AUTO_ROTATION_DEGREE_90,
- AUTO_ROTATION_DEGREE_180,
- AUTO_ROTATION_DEGREE_270,
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __SENSOR_TYPES_H__ */
* 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)
{
#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 { \
+++ /dev/null
-/*
- * 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;
-}
-
#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>
#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>
#include "sensor_manager.h"
-#include <sensor_log.h>
+#include <sensor-log.h>
#include <sensor_info.h>
#include <sensor_utils.h>
#include <command_types.h>
#include <list>
#include <atomic>
-#include "sensor_internal.h"
+#include "sensor-internal.h"
#include "sensor_provider_internal.h"
namespace sensor {
#include "sensor_manager_channel_handler.h"
-#include <sensor_log.h>
+#include <sensor-log.h>
#include <command_types.h>
#include "sensor_manager.h"
#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>
*/
#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)
RETV_IF(result < 0, SENSOR_ERROR_OPERATION_FAILED);
return SENSOR_ERROR_NONE;
-}
\ No newline at end of file
+}
#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;
#define __SENSOR_PROVIDER_CHANNEL_HANDLER__
#include <channel_handler.h>
-#include <sensor_internal.h>
+#include <sensor-internal.h>
#include "sensor_provider_internal.h"
namespace sensor {
#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>
#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>
#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;
#include <stdlib.h>
#include <sensor.h>
-#include <sensor_log.h>
+#include <sensor-log.h>
#include <sensor_recorder_internal.h>
#include <map>
#include <string>
#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)
{
#include "accept_event_handler.h"
-#include "sensor_log.h"
+#include "sensor-log.h"
#include "ipc_server.h"
using namespace ipc;
#include <errno.h>
#include <sys/time.h>
#include <cbase_lock.h>
-#include <sensor_log.h>
+#include <sensor-log.h>
using namespace sensor;
#include <memory>
#include <algorithm>
-#include "sensor_log.h"
+#include "sensor-log.h"
#include "channel_event_handler.h"
#define SYSTEMD_SOCK_BUF_SIZE (128*1024)
#include "channel.h"
#include "channel_handler.h"
-#include "sensor_log.h"
+#include "sensor-log.h"
using namespace ipc;
*/
#include <cmutex.h>
-#include <sensor_log.h>
+#include <sensor-log.h>
using namespace sensor;
#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"
#include <queue>
#include "channel_event_handler.h"
-#include "sensor_log.h"
+#include "sensor-log.h"
#include "event_handler.h"
#include "channel.h"
#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"
#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"
#include "message.h"
-#include <sensor_log.h>
+#include <sensor-log.h>
#include <atomic>
using namespace ipc;
#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>
#include <string>
#include <vector>
#include <hal/hal-sensor-types.h>
-#include <sensor_types.h>
+#include <sensor-types.h>
namespace sensor {
#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
#define __SENSOR_UTILS_H__
#include <time.h>
-#include <sensor_types.h>
+#include <sensor-types.h>
#include <string>
#include <vector>
#include <sys/types.h>
#include <sys/socket.h>
-#include "sensor_log.h"
+#include "sensor-log.h"
using namespace ipc;
#include <sys/ioctl.h>
#include <systemd/sd-daemon.h>
-#include "sensor_log.h"
+#include "sensor-log.h"
#define SOCK_TIMEOUT 10
#include <sys/types.h>
#include <sys/socket.h>
-#include "sensor_log.h"
+#include "sensor-log.h"
#define SLEEP_10_MS usleep(10000)