From 4c27ed72110577a8410371b3db839178da9bed3c Mon Sep 17 00:00:00 2001 From: TaeminYeom Date: Tue, 20 Sep 2022 17:45:13 +0900 Subject: [PATCH] Change not to make libsensor so file It will be removed Change-Id: I9f5d3434bfbfe94bf72a94afeae9e0b0c0cb7539 Signed-off-by: TaeminYeom --- CMakeLists.txt | 7 +- include/sensor-internal.h | 510 ---------------- packaging/capi-system-sensor.spec | 6 +- src/api/CMakeLists.txt | 10 +- src/api/api-sensor-internal.cpp | 1180 +------------------------------------ src/api/api-sensor-provider.cpp | 2 +- src/api/api-sensor.cpp | 2 +- 7 files changed, 10 insertions(+), 1707 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa65f1d..c52d415 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,13 +21,8 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}") # Internal Logging Option #ADD_DEFINITIONS("-DTIZEN_DEBUG") -ADD_SUBDIRECTORY(src/shared) ADD_SUBDIRECTORY(src/api) ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(tools) -INSTALL(DIRECTORY include/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor - FILES_MATCHING - PATTERN "*-private.h" EXCLUDE - PATTERN "*.h") +INSTALL(FILES include/sensor.h include/sensor-internal.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor) diff --git a/include/sensor-internal.h b/include/sensor-internal.h index 3d1e68e..04ef69a 100644 --- a/include/sensor-internal.h +++ b/include/sensor-internal.h @@ -17,23 +17,9 @@ #ifndef __SENSOR_INTERNAL_H__ #define __SENSOR_INTERNAL_H__ -#ifndef API -#define API __attribute__((visibility("default"))) -#endif - -#include -#include -#include - -/*header for common sensor type*/ #include -#include -#include -#include #include -#define SENSOR_BATCH_LATENCY_DEFAULT UINT_MAX - #ifdef __cplusplus extern "C" { @@ -43,496 +29,6 @@ typedef enum { SENSOR_LIDAR = 1000, } sensor_type_internel_e; -typedef void (*sensor_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data); -typedef void (*sensor_events_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t events[], int events_count, void *user_data); -typedef void (*sensorhub_cb_t)(sensor_t sensor, unsigned int event_type, sensorhub_data_t *data, void *user_data); -typedef void (*sensor_accuracy_changed_cb_t) (sensor_t sensor, unsigned long long timestamp, int accuracy, void *user_data); -typedef void (*sensor_attribute_int_changed_cb_t)(sensor_t sensor, int attribute, int value, void *user_data); -typedef void (*sensor_attribute_str_changed_cb_t)(sensor_t sensor, int attribute, const char *value, int len, void *user_data); - -/** - * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors. - * - * @param[in] type the type of sensors requested. - * @param[out] list the list of sensors matching the asked type, the caller should explicitly free this list. - * @param[out] sensor count the count of sensors contained in the list. - * @return true on success, otherwise false. - */ -bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count); - -/** - * @brief Get the default sensor for a given type. - * - * @param[in] type the type of a sensor requested. - * @return the default sensor matching the asked type on success, otherwise NULL. - */ -sensor_t sensord_get_sensor(sensor_type_t type); - -/** - * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors. - * - * @param[in] type the type of sensors requested. - * @param[out] list the list of sensors matching the asked type, the caller should explicitly free this list. - * @param[out] sensor count the count of sensors contained in the list. - * @return 0 on success, otherwise a negative error value - * @retval 0 Successful - * @retval -EPERM Operation not permitted - * @retval -EACCES Permission denied - * @retval -ENODATA NO sensor available - */ -int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count); - -/** - * @brief Get the default sensor for a given type. - * - * @param[in] type the type of a sensor requested. - * @param[out] a sensor matching the asked type. - * @return 0 on success, otherwise a negative error value - * @retval 0 Successful - * @retval -EPERM Operation not permitted - * @retval -EACCES Permission denied - */ -int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor); - -/** - * @brief Get the type of this sensor. - * - * @param[in] sensor a sensor to get type. - * @param[out] type the type of this sensor. - * @return return true on success, otherwise false. - */ -bool sensord_get_type(sensor_t sensor, sensor_type_t *type); - -/** - * @brief Get the URI string of this sensor. - * - * @param[in] sensor a sensor to get uri. - * @return the name string of this sensor on success, otherwise NULL. - */ -const char* sensord_get_uri(sensor_t sensor); - -/** - * @brief Get the name string of this sensor. - * - * @param[in] sensor a sensor to get name. - * @return the name string of this sensor on success, otherwise NULL. - */ -const char* sensord_get_name(sensor_t sensor); - -/** - * @brief Get the vendor string of this sensor. - * - * @param[in] sensor a sensor to get vendor. - * @return the vendor string of this sensor on success, otherwise NULL. - */ -const char* sensord_get_vendor(sensor_t sensor); - -/** - * @brief Get the privilege of this sensor. - * - * @param[in] sensor a sensor to get privilege. - * @param[out] privilege the privilege of this sensor. - * @return true on success, otherwise false. - */ -bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege); - -/** - * @brief Get the minimum range of this sensor in the sensor's unit. - * - * @param[in] sensor a sensor to get minimum range. - * @param[out] min_range the minimum range of this sensor in the sensor's unit. - * @return true on success, otherwise false. - */ -bool sensord_get_min_range(sensor_t sensor, float *min_range); - -/** - * @brief Get the maximum range of this sensor in the sensor's unit. - * - * @param[in] sensor a sensor to get maximum range. - * @param[out] max_range the maximum range of this sensor in the sensor's unit. - * @return true on success, otherwise false. - */ -bool sensord_get_max_range(sensor_t sensor, float *max_range); - -/** - * @brief Get the resolution of this sensor in the sensor's unit. - * - * @param[in] sensor a sensor to get resolution. - * @param[out] resolution the resolution of this sensor in the sensor's unit. - * @return true on success, otherwise false. - */ -bool sensord_get_resolution(sensor_t sensor, float *resolution); - -/** - * @brief Get the minimum interval allowed between two events in microsecond or zero if this sensor only returns a value when the data it's measuring changes. - * - * @param[in] sensor a sensor to get minimum interval. - * @param[out] min_interval the minimum interval of this sensor. - * @return true on success, otherwise false. - */ -bool sensord_get_min_interval(sensor_t sensor, int *min_interval); - -/** - * @brief Get the number of events reserved for this sensor in the batch mode FIFO. - * - * @param[in] sensor a sensor to get the number of fifo count - * @param[out] fifo_count the number of events reserved for this sensor in the batch mode FIFO - * @return true on success, otherwise false - */ -bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count); - -/** - * @brief Get the maximum number of events of this sensor that could be batched. If this value is zero it indicates that batch mode is not supported for this sensor. - * - * @param[in] sensor a sensor to the maximum number of events that could be batched. - * @param[out] max_batch_count the maximum number of events of this sensor that could be batched. - * @return true on success, otherwise false. - */ -bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count); - -/** - * @brief Get the supported event types of this sensor. - * - * @param[in] sensor a sensor to get the supported event types. - * @param[out] event_types the array containing supported event types of this sensor, the caller should explicitly free this array. - * @param[out] count the count of the supported event types of this sensor. - * @return true on success, otherwise false. - */ -bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count); - -/** - * @brief Check a given event type is supporeted by this sensor. - * - * @param[in] sensor a sensor to check a given event type is supporeted. - * @param[out] event_type an event type to be checked whether supported or not. - * @param[out] supported whether a given event is supported or not in this sensor. - * @return true on success, otherwise false. - */ -bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported); - -/** - * @brief Check a wakeup supported or not by this sensor. - * - * @param[in] sensor a sensor to check a given event type is supporeted. - * @return true on success, otherwise false. - */ -bool sensord_is_wakeup_supported(sensor_t sensor); - -/** - * @brief Connect a given sensor and get a handle of a given sensor. - * - * @param[in] sensor a sensor to connect - * @return a handle of a given sensor on success, otherwise negative value - */ -int sensord_connect(sensor_t sensor); - -/** - * @brief Disconnect a given sensor. - * - * @param[in] handle a handle to disconnect. - * @return true on success, otherwise false. - */ -bool sensord_disconnect(int handle); - -/** - * @brief Register a callback with a connected sensor for a given event_type. This callback will be called when a given event occurs in a connected sensor. - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] event_type an event type to register - * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval. - * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds. - * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled. - * @param[in] cb a callback which is called when a given event occurs - * @param[in] user_data the callback is called with user_data - * @return true on success, otherwise false. - */ -bool sensord_register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data); - -/** - * @brief Register a callback with a connected sensor for a given event_type. This callback will be called when a given event occurs in a connected sensor. - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] event_type an event type to register - * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled. - * @param[in] cb a callback which is called when a given event occurs - * @param[in] user_data the callback is called with user_data - * @return true on success, otherwise false. - */ -bool sensord_register_events(int handle, unsigned int event_type, unsigned int max_batch_latency, sensor_events_cb_t cb, void *user_data); - -/** - * @brief Register a callback with a connected context sensor for a given event_type. This callback will be called when a given event occurs in a connected context sensor. - * - * @param[in] handle a handle represensting a connected context sensor. - * @param[in] event_type an event type to register - * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval. - * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds. - * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled. - * @param[in] cb a callback which is called when a given event occurs - * @param[in] user_data the callback is called with user_data - * @return true on success, otherwise false. - */ -bool sensord_register_hub_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data); - -/** - * @brief Unregister a event with a connected sensor. After unregistering, that event will not be sent. - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] event_type an event type to unregister. - * @return true on success, otherwise false. - */ -bool sensord_unregister_event(int handle, unsigned int event_type); - -/** - * @brief Unregister a event with a connected sensor. After unregistering, that event will not be sent. - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] event_type an event type to unregister. - * @return true on success, otherwise false. - */ -bool sensord_unregister_events(int handle, unsigned int event_type); - -/** - * @brief Register a callback with a connected sensor. This callback will be called when the accuracy of a sensor has changed. - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] cb a callback which is called when he accuracy of a sensor has changed. - * @param[in] user_data the callback is called with user_data - * @return true on success, otherwise false. - */ -bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data); - -/** - * @brief Unregister a callback with a connected sensor. After unregistering, sensor_accuray_change_cb will not be called. - * - * @param[in] handle a handle represensting a connected sensor. - * @return true on success, otherwise false. - */ -bool sensord_unregister_accuracy_cb(int handle); - -/** - * @brief Register a callback with a connected sensor. This callback will be called when attributes of a sensor has changed. - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] cb a callback which is called when he attributes of a sensor has changed. - * @param[in] user_data the callback is called with user_data - * @return true on success, otherwise false. - */ -bool sensord_register_attribute_int_changed_cb(int handle, sensor_attribute_int_changed_cb_t cb, void *user_data); - -/** - * @brief Unregister a callback with a connected sensor. After unregistering, sensor_attribute_int_changed_cb will not be called. - * - * @param[in] handle a handle represensting a connected sensor. - * @return true on success, otherwise false. - */ -bool sensord_unregister_attribute_int_changed_cb(int handle); - -/** - * @brief Register a callback with a connected sensor. This callback will be called when attributes of a sensor has changed. - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] cb a callback which is called when he attributes of a sensor has changed. - * @param[in] user_data the callback is called with user_data - * @return true on success, otherwise false. - */ -bool sensord_register_attribute_str_changed_cb(int handle, sensor_attribute_str_changed_cb_t cb, void *user_data); - -/** - * @brief Unregister a callback with a connected sensor. After unregistering, sensor_attribute_str_changed_cb will not be called. - * - * @param[in] handle a handle represensting a connected sensor. - * @return true on success, otherwise false. - */ -bool sensord_unregister_attribute_str_changed_cb(int handle); - -/** - * @brief Start listening events with a connected sensor. - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] option either one of SENSOR_OPTION_DEFAULT and SENSOR_OPTION_ALWAYS_ON. - * with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode. - * with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode. - * @return true on success, otherwise false. - */ -bool sensord_start(int handle, int option); - -/** - * @brief Stop listening events with a connected sensor. - * - * @param[in] handle a handle represensting a connected sensor. - * @return true on success, otherwise false. - */ -bool sensord_stop(int handle); - -/** - * @brief Change the interval of a specifed event type in a connected sensor. - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] event_type an event type to change interval. - * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval. - * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds. - * @return true on success, otherwise false. - */ -bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval); - -/** - * @brief Change the max batch latency of a specifed event type in a connected sensor. - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] event_type an event type to change max batch latency - * @param[in] max_batch_latency an event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled. - * @return true on success, otherwise false. - */ -bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency); - -/** - * @brief Change the option of a connected sensor. - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] option either one of SENSOR_OPTION_DEFAULT and SENSOR_OPTION_ALWAYS_ON. - * with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode. - * with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode. - * @return true on success, otherwise false. - */ -bool sensord_set_option(int handle, int option); - -/* - * @brief Set the attribute to a connected sensor - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] attribute an attribute to change - * @param[in] value an attribute value - * @return 0 on success, otherwise a negative error value - * @retval 0 Successful - * @retval -EINVAL Invalid parameter - * @retval -EPERM Operation not permitted - */ -int sensord_set_attribute_int(int handle, int attribute, int value); - -/* - * @brief Get the attribute to a connected sensor - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] attribute an attribute to get value - * @param[out] value an attribute value - * @return 0 on success, otherwise a negative error value - * @retval 0 Successful - * @retval -EINVAL Invalid parameter - * @retval -EPERM Operation not permitted - */ -int sensord_get_attribute_int(int handle, int attribute, int* value); - -/** - * @brief Set the attribute to a connected sensor - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] attribute an attribute to change - * @param[in] value an attribute value - * @param[in] value_len the length of value - * @return 0 on success, otherwise a negative error value - * @retval 0 Successful - * @retval -EINVAL Invalid parameter - * @retval -EPERM Operation not permitted - */ -int sensord_set_attribute_str(int handle, int attribute, const char *value, int len); - -/** - * @brief Get the attribute to a connected sensor - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] attribute an attribute to get value - * @param[out] value an attribute value, the caller should explicitly free this value - * @param[out] len the length of value - * @return 0 on success, otherwise a negative error value - * @retval 0 Successful - * @retval -EINVAL Invalid parameter - * @retval -EPERM Operation not permitted - */ -int sensord_get_attribute_str(int handle, int attribute, char **value, int *len); - -/** - * @brief Send data to sensorhub - * - * @param[in] handle a handle represensting a connected context sensor. - * @param[in] data it holds data to send to sensorhub - * @param[in] data_len the length of data - * @return true on success, otherwise false. - */ -bool sensord_send_sensorhub_data(int handle, const char *data, int data_len); -bool sensord_send_command(int handle, const char *command, int command_len); - -/** - * @brief get sensor data from a connected sensor - * - * @param[in] handle a handle represensting a connected context sensor. - * @param[in] data_id it specifies data to get - * @param[out] sensor_data data from connected sensor - * @return true on success, otherwise false. - */ -bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data); - -/** - * @brief get sensor data from a connected sensor - * - * @param[in] handle a handle represensting a connected context sensor. - * @param[in] data_id it specifies data to get - * @param[out] sensor_data the data list from connected sensor, the caller should explicitly free this list. - * @param[out] count the count of data contained in the list. - * @return true on success, otherwise false. - */ -bool sensord_get_data_list(int handle, unsigned int data_id, sensor_data_t** sensor_data, int* count); - -/** - * @brief flush sensor data from a connected sensor - * - * @param[in] handle a handle represensting a connected context sensor. - * @return true on success, otherwise false. - */ -bool sensord_flush(int handle); - -bool sensord_set_passive_mode(int handle, bool passive); - - -/* Sensor Internal API using URI */ -int sensord_get_default_sensor_by_uri(const char *uri, sensor_t *sensor); -int sensord_get_sensors_by_uri(const char *uri, sensor_t **list, int *sensor_count); - -typedef void (*sensord_added_cb)(const char *uri, void *user_data); -int sensord_add_sensor_added_cb(sensord_added_cb callback, void *user_data); -int sensord_remove_sensor_added_cb(sensord_added_cb callback); - -typedef void (*sensord_removed_cb)(const char *uri, void *user_data); -int sensord_add_sensor_removed_cb(sensord_removed_cb callback, void *user_data); -int sensord_remove_sensor_removed_cb(sensord_removed_cb callback); - -/* Sensor provider */ -typedef void *sensord_provider_h; -int sensord_create_provider(const char *uri, sensord_provider_h *provider); -int sensord_destroy_provider(sensord_provider_h provider); -int sensord_add_provider(sensord_provider_h provider); -int sensord_remove_provider(sensord_provider_h provider); - -int sensord_provider_set_name(sensord_provider_h provider, const char *name); -int sensord_provider_set_vendor(sensord_provider_h provider, const char *vendor); -int sensord_provider_set_range(sensord_provider_h provider, float min_range, float max_range); -int sensord_provider_set_resolution(sensord_provider_h provider, float resolution); - -typedef void (*sensord_provider_start_cb)(sensord_provider_h provider, void *user_data); -int sensord_provider_set_start_cb(sensord_provider_h provider, sensord_provider_start_cb callback, void *user_data); - -typedef void (*sensord_provider_stop_cb)(sensord_provider_h provider, void *user_data); -int sensord_provider_set_stop_cb(sensord_provider_h provider, sensord_provider_stop_cb callback, void *user_data); - -typedef void (*sensord_provider_interval_changed_cb)(sensord_provider_h provider, unsigned int interval_ms, void *user_data); -int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, sensord_provider_interval_changed_cb callback, void *user_data); - -typedef void (*sensord_provider_attribute_str_cb)(sensord_provider_h provider, int attribute, const char *value, int count, void *user_data); -int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data); - -int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data); -int sensord_provider_publish_events(sensord_provider_h provider, sensor_data_t events[], int count); - /** * @brief Set the attribute to a connected sensor * @@ -559,12 +55,6 @@ int sensor_util_set_attribute_int(sensor_type_e type, sensor_attribute_e attr, i */ int sensor_util_get_attribute_int(sensor_type_e type, sensor_attribute_e attr, int *value); -/* Deprecated */ -typedef void (*sensor_external_command_cb_t)(int handle, const char* data, int data_cnt, void *user_data); -int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data); -bool sensord_external_disconnect(int handle); -bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt); - #ifdef __cplusplus } #endif diff --git a/packaging/capi-system-sensor.spec b/packaging/capi-system-sensor.spec index 1f82c04..7a737c7 100644 --- a/packaging/capi-system-sensor.spec +++ b/packaging/capi-system-sensor.spec @@ -14,10 +14,7 @@ Source0: %{name}-%{version}.tar.gz BuildRequires: cmake BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(vconf) -BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(libsystemd) -BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(sensor) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(hal-api-sensor) %if "%{?SENSOR_RECORDER}" == "on" @@ -102,7 +99,6 @@ find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';' %files %manifest packaging/capi-system-sensor.manifest %{_libdir}/libcapi-system-sensor.so.* -%{_libdir}/libsensor-shared.so %license LICENSE.APLv2 %files devel diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index 01741e9..ab451b6 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -2,7 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(capi-system-sensor) INCLUDE(GNUInstallDirs) -SET(DEPENDENTS "dlog glib-2.0 hal-api-sensor capi-base-common") +SET(DEPENDENTS "dlog glib-2.0 sensor hal-api-sensor capi-base-common") IF("${SENSOR_RECORDER}" STREQUAL "on") SET(DEPENDENTS "${DEPENDENTS} context-sensor-recorder-client") @@ -46,11 +46,7 @@ SET(SOURCES geomagnetic-field.c api-sensor.cpp api-sensor-internal.cpp - api-sensor-provider.cpp - sensor-listener.cpp - sensor-manager.cpp - sensor-provider.cpp - sensor-reader.cpp) + api-sensor-provider.cpp) IF("${SENSOR_RECORDER}" STREQUAL "on") SET(SOURCES ${SOURCES} api-sensor-recorder.cpp) @@ -60,7 +56,7 @@ ENDIF() ADD_LIBRARY(${PROJECT_NAME} SHARED ${SOURCES}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS} "sensor-shared") +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER} CLEAN_DIRECT_OUTPUT 1) CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc @ONLY) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/src/api/api-sensor-internal.cpp b/src/api/api-sensor-internal.cpp index db98eb0..514b95f 100644 --- a/src/api/api-sensor-internal.cpp +++ b/src/api/api-sensor-internal.cpp @@ -14,1185 +14,11 @@ * limitations under the License. */ -#include - -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#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 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)) - , 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)->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)->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)->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)->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)->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)->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)->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)->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)->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)->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; - unsigned int 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(p); - providerCnt++; - return OP_SUCCESS; -} - -API int sensord_destroy_provider(sensord_provider_h provider) -{ - retvm_if(!provider, -EINVAL, "Invalid paramter"); - - delete static_cast(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(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(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(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(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(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(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(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(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(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(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(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(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 +#include +#include int sensor_util_set_attribute_int(sensor_type_e type, sensor_attribute_e attr, int value) { diff --git a/src/api/api-sensor-provider.cpp b/src/api/api-sensor-provider.cpp index bcf8749..4752c79 100644 --- a/src/api/api-sensor-provider.cpp +++ b/src/api/api-sensor-provider.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include #include #include diff --git a/src/api/api-sensor.cpp b/src/api/api-sensor.cpp index e5e6a32..6d5cda9 100644 --- a/src/api/api-sensor.cpp +++ b/src/api/api-sensor.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include -- 2.7.4