diff options
author | Abhay Agarwal <ay.agarwal@samsung.com> | 2021-05-03 16:45:03 +0530 |
---|---|---|
committer | Abhay Agarwal <ay.agarwal@samsung.com> | 2021-06-25 17:33:06 +0530 |
commit | 407403c8938da4622b1664af2ad17e71c68cefd9 (patch) | |
tree | 7152a6c3df6c5a73fb0795341738acb7757608e8 | |
parent | 51d1ba58d302a708eebbab1ce2d9e9dd9a0d4797 (diff) | |
download | user-awareness-407403c8938da4622b1664af2ad17e71c68cefd9.tar.gz user-awareness-407403c8938da4622b1664af2ad17e71c68cefd9.tar.bz2 user-awareness-407403c8938da4622b1664af2ad17e71c68cefd9.zip |
Add API to start location detection
Change-Id: Ib7e9714739cdeb94019623381f57d8cd3d2490cb
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
-rwxr-xr-x | include/user-awareness-internal-type.h | 54 | ||||
-rwxr-xr-x | include/user-awareness-internal.h | 29 | ||||
-rwxr-xr-x | include/user-awareness-private.h | 7 | ||||
-rwxr-xr-x | src/user-awareness-monitors.c | 91 |
4 files changed, 179 insertions, 2 deletions
diff --git a/include/user-awareness-internal-type.h b/include/user-awareness-internal-type.h index d43aab0..e627a1b 100755 --- a/include/user-awareness-internal-type.h +++ b/include/user-awareness-internal-type.h @@ -32,6 +32,13 @@ extern "C" { /** * @ingroup CAPI_NETWORK_UA_MODULE + * @brief The handle of location information. + * @since_tizen 6.5 + */ +typedef void *ua_location_h; + +/** + * @ingroup CAPI_NETWORK_UA_MODULE * @brief Enumerations of logical conjunction operation in between * AND and OR user detection conditions. * @since_tizen 6.5 @@ -63,6 +70,53 @@ typedef bool (*ua_registered_user_cb)( void *user_data); /** + * @ingroup CAPI_NETWORK_UA_MODULE + * @brief Callback to be invoked on detection of user and device location. + * @since_tizen 6.5 + * + * @remarks The @a monitor handle should not be released. + * @remarks The @a monitor handle can be used only in the callback. + * @remarks The @a service handle should not be released + * @remarks The @a service handle can be used only in the callback. + * @remarks The @a sensor handle should not be released. + * @remarks The @a sensor handle can be used only in the callback. + * @remarks The @a device handle should not be released. + * @remarks The @a device handle can be used only in the callback. + * @remarks The @a user handle should not be released. + * @remarks The @a user handle can be used only in the callback. + * @remarks The @a location handle should not be released. + * @remarks The @a location handle can be used only in the callback. + * + * @param[in] result The result error code of the requested operation. + * result is #UA_ERROR_NONE on success, otherwise appropriate error value. + * @details Following error codes can be delivered: + * #UA_ERROR_NONE Successful. + * #UA_ERROR_OPERATION_FAILED Operation failed + * + * @param[in] monitor The monitor handle + * @param[in] service The service handle with which location detection start was invoked. + * @param[in] sensor_type Sensor type + * @param[in] sensor The handle of the sensor which reported user/device location. + * @param[in] device The device handle on which sensor is detected. + * @param[in] user The user handle on which sensor is detected. + * @param[in] location The location handle. + * @param[in] user_data The user data passed in ua_monitor_start_location_detection() + * + * @see ua_monitor_start_location_detection() + */ +typedef void (*ua_location_detected_cb)( + ua_error_e result, + ua_monitor_h monitor, + ua_service_h service, + ua_sensor_type_e sensor_type, + ua_sensor_h sensor, + ua_device_h device, + ua_user_h user, + ua_location_h location, + void *user_data); + + +/** * @} */ diff --git a/include/user-awareness-internal.h b/include/user-awareness-internal.h index ea798a2..8b87267 100755 --- a/include/user-awareness-internal.h +++ b/include/user-awareness-internal.h @@ -348,6 +348,35 @@ int ua_service_get_device_discriminant( ua_device_h device, bool *discriminant); +/** + * @ingroup CAPI_NETWORK_UA_MODULE + * @brief Starts user location detection. + * @since_tizen 6.5 + * + * @param[in] monitor The monitor handle + * @param[in] service The service handle. If service is NULL then monitor will start for default service. + * @param[in] callback Callback to be invoked after device location detection. + * @param[in] user_data The user data to be passed when callback is called. + * + * @return 0 on success, otherwise a negative error value + * @retval #UA_ERROR_NONE Successful + * @retval #UA_ERROR_PERMISSION_DENIED Permission Denied + * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #UA_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #UA_ERROR_NO_DATA No sensor available + * @retval #UA_ERROR_OPERATION_FAILED Operation failed + * @retval #UA_ERROR_NOT_INITIALIZED Not initialized yet + * @retval #UA_ERROR_NOT_SUPPORTED Not Supported + * + * @see ua_location_detected_cb() + * @see ua_monitor_stop_location_detection() + */ +int ua_monitor_start_location_detection( + ua_monitor_h monitor, + ua_service_h service, + ua_location_detected_cb callback, + void *user_data); + /* Deprecated API's */ /** diff --git a/include/user-awareness-private.h b/include/user-awareness-private.h index 081cbfa..61a8d5c 100755 --- a/include/user-awareness-private.h +++ b/include/user-awareness-private.h @@ -295,6 +295,10 @@ typedef struct { GSList *user_state; /**< User current state i.e presence or absence */ void *user_data; /**< User data */ gboolean env_user_cb_sent; /** User presence callback sent or not flag for environmental sensors */ + + unsigned int location_detected_bitmask; /**< Detected Location bitmask */ + gboolean location_detection_started; /**< Is location detection started */ + ua_location_detected_cb location_cb; /**< Location detection callback */ } ua_monitor_s; /** @@ -371,7 +375,8 @@ typedef struct { */ typedef enum { UA_PRESENCE_DETECTION = 0x00, /**< Presence detcection */ - UA_ABSENCE_DETECTION /**< Absence detection */ + UA_ABSENCE_DETECTION, /**< Absence detection */ + UA_LOCATION_DETECTION /**< Location detection */ } ua_detection_type_e; /** diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c index 2648da5..6b3fcb1 100755 --- a/src/user-awareness-monitors.c +++ b/src/user-awareness-monitors.c @@ -91,8 +91,18 @@ static int __ua_start_monitoring(unsigned int bitmask, char *service, return ret; /* LCOV_EXCL_STOP */ } - } else + } else if (detect == UA_LOCATION_DETECTION) { + ret = _ua_get_error_code(_uam_start_location_detection(bitmask, service)); + if (UA_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ + UA_ERR("_ua_start_location_detection failed with %s(0x%X)", + _ua_get_error_string(ret), ret); + return ret; + /* LCOV_EXCL_STOP */ + } + } else { UA_ERR("invalid detection type"); + } FUNC_EXIT; return UA_ERROR_NONE; @@ -1633,6 +1643,85 @@ int ua_monitor_start_absence_detection( return UA_ERROR_NONE; } +int ua_monitor_start_location_detection( + ua_monitor_h monitor_handle, + ua_service_h service_handle, + ua_location_detected_cb callback, + void *user_data) +{ + FUNC_ENTRY; + int ret; + + char *service; + GSList *ua_services_list; + unsigned int available_sensors = 0; + ua_monitor_s *monitor = (ua_monitor_s *)monitor_handle; + ua_service_info_s *service_info = + (ua_service_info_s *)service_handle; + ua_detection_type_e detect = UA_LOCATION_DETECTION; + + UA_CHECK_SUPPORTED_FEATURE(UA_FEATURE_COMMON); + UA_CHECK_INIT_STATUS(); + UA_VALIDATE_INPUT_PARAMETER(monitor_handle); + UA_VALIDATE_HANDLE(monitor_handle, ua_monitor_list); + retv_if(TRUE == monitor->location_detection_started, + UA_ERROR_NOW_IN_PROGRESS); + + ua_services_list = _ua_service_get_services(); + if (service_handle) { + UA_VALIDATE_HANDLE(service_handle, ua_services_list); + service = g_strdup(service_info->name); + } else { + service = NULL; + } + + if (monitor->service) + if ((service && g_strcmp0(monitor->service, service)) || + (!service && g_strcmp0(monitor->service, + UA_SERVICE_DEFAULT))) { + g_free(service); + return UA_ERROR_NOT_PERMITTED; + } + + if (0 == monitor->sensor_bitmask) { + g_free(service); + return UA_ERROR_NO_DATA; + } + + if (!monitor->service) { + if (service == NULL) + monitor->service = g_strndup(UA_SERVICE_DEFAULT, + UA_MAX_SERVICE_LEN); + else + monitor->service = g_strndup(service, + UA_MAX_SERVICE_LEN); + } + + if (UA_ERROR_NONE != _ua_get_error_code( + _uam_get_available_sensors(&available_sensors))) + UA_WARN("_uam_get_available_sensors failed"); + + ret = __ua_start_monitoring(monitor->sensor_bitmask, + monitor->service, detect); + if (UA_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ + UA_ERR("Failed with error: %s(0x%X)", + _ua_get_error_string(ret), ret); + g_free(service); + return ret; + /* LCOV_EXCL_STOP */ + } + + monitor->location_cb = callback; + monitor->user_data = user_data; + monitor->location_detection_started = TRUE; + + g_free(service); + + FUNC_EXIT; + return UA_ERROR_NONE; +} + int ua_monitor_stop_presence_detection(ua_monitor_h handle) { FUNC_ENTRY; |