summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsaerome.kim <saerome.kim@samsung.com>2019-10-21 20:55:53 +0900
committersaerome.kim <saerome.kim@samsung.com>2019-11-01 12:49:13 +0900
commitd9a8ff5283b54bdc59d2c75b578e7549bebe1934 (patch)
tree5dcf684ea0d30aebe51c35894595287148c021d7
parent1a1d16753a8e4c8cfbb2336c99375ca500c3a71d (diff)
downloaduser-awareness-d9a8ff5283b54bdc59d2c75b578e7549bebe1934.tar.gz
user-awareness-d9a8ff5283b54bdc59d2c75b578e7549bebe1934.tar.bz2
user-awareness-d9a8ff5283b54bdc59d2c75b578e7549bebe1934.zip
Add functionality to report instant sensor status change
- Problem: in ABSENCE case, even the motion sensor detects ABSENCE ua-manager reports this ABSENCE state after the detection window complete. - Cause: If ABSENCE case, the ABSENCE can be jurged only when the detction window complete. - Solution: Whenever the sensor status is changed, plugin reports status changed event immediately so that the user can recognize ABSENCE event takes place during uncompleted ABSENCE detection window. Change-Id: I49254770cbab1c55aac7b9b893c5eec8d54139cf Signed-off-by: saerome.kim <saerome.kim@samsung.com>
-rw-r--r--CMakeLists.txt5
-rw-r--r--include/user-awareness-private.h14
-rw-r--r--include/user-awareness.h83
-rw-r--r--packaging/capi-network-ua.spec2
-rw-r--r--src/user-awareness-event-handler.c14
-rw-r--r--src/user-awareness-monitors.c75
-rw-r--r--src/user-awareness-util.c1
-rw-r--r--test/uat-init.c115
8 files changed, 285 insertions, 24 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7fbb441..4300258 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,14 +18,11 @@ IF (${SUSPEND_RESUME_TEST})
deviced
power-defs
)
+ ADD_DEFINITIONS(-DSUSPEND_RESUME_TEST)
ELSE (${SUSPEND_RESUME_TEST})
pkg_check_modules (PKGS REQUIRED ${PKG_MODULES})
ENDIF (${SUSPEND_RESUME_TEST})
-IF(${SUSPEND_RESUME_TEST})
- ADD_DEFINITIONS(-DSUSPEND_RESUME_TEST)
-ENDIF(${SUPPORT_BLE_ADV})
-
INCLUDE_DIRECTORIES(${PKGS_INCLUDE_DIRS})
LINK_DIRECTORIES(${PKGS_LIBRARY_DIRS})
diff --git a/include/user-awareness-private.h b/include/user-awareness-private.h
index d1ccf18..7e6478e 100644
--- a/include/user-awareness-private.h
+++ b/include/user-awareness-private.h
@@ -189,6 +189,7 @@ typedef struct {
ua_scan_completed_cb scan_device_cb; /**< Callback to let apps know scanned registered devices */
ua_presence_detected_cb presence_cb; /**< User presence detection callback */
ua_absence_detected_cb absence_cb; /**< Absence detection callback */
+ ua_callback_s sensor_status_cb; /**< Senser status changed callback */
char *service; /**< Service name */
GSList *user_state; /**< User current state i.e presence or absence */
void *user_data; /**< User data */
@@ -200,6 +201,7 @@ typedef struct {
* @since_tizen 5.5
*/
typedef struct {
+ unsigned int status; /**< Sensor status 1:PRESENCE 2:ABSENCE */
ua_sensor_h handle;
ua_sensor_e bitmask;
long int timestamp;
@@ -386,6 +388,18 @@ void _ua_monitor_handle_user_absence_detected(
uam_sensor_info_s *sensor_info, char *service, char *account);
/**
+ * @brief Calls the sensor status changed callback when notified of sensor status changed.
+ * @since_tizen 5.5
+ *
+ * @param[in] info Sensor information
+ *
+ * @exception
+ * @pre
+ * @post
+ */
+void _ua_monitor_handle_sensor_status_changed(uam_sensor_info_s *info);
+
+/**
* @brief Destroys a monitor handle.
* @since_tizen 5.5
*
diff --git a/include/user-awareness.h b/include/user-awareness.h
index 8ee579a..839f7d8 100644
--- a/include/user-awareness.h
+++ b/include/user-awareness.h
@@ -247,6 +247,16 @@ typedef enum {
/**
* @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Enumerations for sensor status
+ * @since_tizen 5.5
+ */
+typedef enum {
+ UA_SENSOR_PRESENCE = 0x01, /**< Sensor reports PRESENCE status */
+ UA_SENSOR_ABSENCE = 0x02 /**< Sensor reports ABSENCE status */
+} ua_sensor_status_e;
+
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
* @brief The handle of sensor information.
* @since_tizen 5.5
*/
@@ -600,6 +610,35 @@ typedef bool (*ua_service_added_device_cb)(
/**
* @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Callback to be invoked if a sensor status changed (presence <-> absence)
+ * immediately during detection operation.
+ * @since_tizen 5.5
+ *
+ * @remarks The @a handle should not be released.
+ * @remarks The @a handle can be used only in the callback.
+ * @remarks The @a sensor_handles should not be released.
+ * @remarks The @a sensor_handles can be used only in the callback.
+ *
+ * @param[in] status #UA_SENSOR_PRESENCE is sensor detects presence. \n
+ * #UA_SENSOR_ABSENCE is sensor detects presence.
+ * @param[in] sensor Sensor type for which status was changed.
+ * @param[in] handle The monitor handle for which sensor type was added.
+ * @param[in] sensor_handles The list of sensor handles on which user is not detected.
+ * @param[in] user_data The user data passed in ua_monitor_set_sensor_status_cb().
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ * @see ua_monitor_set_sensor_state_cb()
+ */
+typedef void (*ua_sensor_status_changed_cb)(
+ ua_sensor_status_e status,
+ ua_monitor_h handle,
+ ua_sensor_h sensor_handle,
+ void *user_data);
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
* @brief Initializes an user awareness framework.
* @since_tizen 5.5
*
@@ -866,6 +905,50 @@ int ua_monitor_unset_sensor_state_cb(
/**
* @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Sets sensor status changed callback.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The monitor handle
+ * @param[in] callback Sensor status changed callback
+ * @param[in] user_data The user data to be passed in sensor state changed callback.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ * @see ua_monitor_unset_sensor_state_cb()
+ */
+int ua_monitor_set_sensor_status_cb(
+ ua_monitor_h handle,
+ ua_sensor_status_changed_cb callback,
+ void *user_data);
+
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Unsets sensor status changed callback.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The monitor handle
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ * @see ua_monitor_set_sensor_state_cb()
+ */
+int ua_monitor_unset_sensor_status_cb(
+ ua_monitor_h handle);
+
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
* @brief Sets absence detected callback for all users.
* @since_tizen 5.5
*
diff --git a/packaging/capi-network-ua.spec b/packaging/capi-network-ua.spec
index 39ad397..5e4cc8d 100644
--- a/packaging/capi-network-ua.spec
+++ b/packaging/capi-network-ua.spec
@@ -1,6 +1,6 @@
Name: capi-network-ua
Summary: User Awareness Framework CAPI
-Version: 0.11.11
+Version: 0.12.0
Release: 1
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
diff --git a/src/user-awareness-event-handler.c b/src/user-awareness-event-handler.c
index 254bed5..3223f1d 100644
--- a/src/user-awareness-event-handler.c
+++ b/src/user-awareness-event-handler.c
@@ -112,6 +112,20 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param,
break;
}
+ case UAM_EVENT_SENSOR_STATUS_CHANGED: {
+ uam_sensor_info_s *sensor_info = NULL;
+
+ sensor_info = event_param->data;
+ ret_if(NULL == sensor_info);
+
+ UA_INFO("status [%d] sensor: [%u], timestamp [%ld], accuracy [%d], value [%f]",
+ sensor_info->status, sensor_info->sensor_bitmask, sensor_info->timestamp,
+ sensor_info->accuracy, sensor_info->values[0]);
+
+ _ua_monitor_handle_sensor_status_changed(sensor_info);
+
+ break;
+ }
case UAM_EVENT_DETECTION_STARTED: {
UA_INFO("Received DETECTION STARTED event !!");
break;
diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c
index debbc0b..b2a0bd7 100644
--- a/src/user-awareness-monitors.c
+++ b/src/user-awareness-monitors.c
@@ -363,12 +363,14 @@ static void __ua_monitor_send_env_user_presence_cb(ua_monitor_s *monitor)
sensors = ua_sensor_get_sensor_handle_list(monitor->presence_detected_bitmask
& filter_bitmask);
- ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)(
- UA_ERROR_NONE, monitor, NULL,
- NULL, sensors,
- monitor->presence_user_cb.user_data);
+ if (monitor->presence_user_cb.callback) {
+ ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)(
+ UA_ERROR_NONE, monitor, NULL,
+ NULL, sensors,
+ monitor->presence_user_cb.user_data);
- monitor->env_user_cb_sent = TRUE;
+ monitor->env_user_cb_sent = TRUE;
+ }
g_slist_free(sensors);
FUNC_EXIT;
@@ -987,6 +989,37 @@ void _ua_monitor_handle_sensor_state(unsigned int bitmask, gboolean ready)
FUNC_EXIT;
}
+void _ua_monitor_handle_sensor_status_changed(uam_sensor_info_s *info)
+{
+ FUNC_ENTRY;
+ GSList *l;
+ ua_sensor_info_s *sensor_info;
+ ret_if(NULL == info);
+
+ sensor_info = _uam_to_ua_sensor_info(info);
+ ret_if(NULL == sensor_info);
+
+ for (l = ua_monitor_list; l; l = g_slist_next(l)) {
+ ua_monitor_s *monitor = l->data;
+
+ if (!monitor || (!monitor->presence_detection_started
+ && !monitor->internal_presence_started)
+ || (!monitor->absence_detection_started))
+ continue;
+
+ if (0 == (sensor_info->bitmask & monitor->sensor_bitmask))
+ continue;
+
+ if (monitor->sensor_status_cb.callback)
+ ((ua_sensor_status_changed_cb)monitor->sensor_status_cb.callback)(
+ sensor_info->status, (ua_monitor_h)monitor, (ua_sensor_h)sensor_info,
+ monitor->sensor_state_cb.user_data);
+ }
+ _ua_free_sensor_info(sensor_info);
+
+ FUNC_EXIT;
+}
+
void _ua_free_ua_monitor_t(gpointer data)
{
FUNC_ENTRY;
@@ -1350,6 +1383,38 @@ int ua_monitor_set_user_absence_condition(
return UA_ERROR_NONE;
}
+int ua_monitor_set_sensor_status_cb(ua_monitor_h handle,
+ ua_sensor_status_changed_cb callback, void *user_data)
+{
+ FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(callback);
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+
+ monitor->sensor_status_cb.callback = callback;
+ monitor->sensor_status_cb.user_data = user_data;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_monitor_unset_sensor_status_cb(ua_monitor_h handle)
+{
+ FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+
+ monitor->sensor_status_cb.callback = NULL;
+ monitor->sensor_status_cb.user_data = NULL;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
int ua_monitor_add_sensor(
ua_monitor_h handle,
ua_sensor_e sensor_type)
diff --git a/src/user-awareness-util.c b/src/user-awareness-util.c
index 5e113f3..d066063 100644
--- a/src/user-awareness-util.c
+++ b/src/user-awareness-util.c
@@ -291,6 +291,7 @@ ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info)
if (!sensor_info)
return NULL;
+ sensor_info->status = info->status;
sensor_info->timestamp = info->timestamp;
sensor_info->count = info->count;
sensor_info->bitmask = _uam_to_ua_sensor(info->sensor_bitmask);
diff --git a/test/uat-init.c b/test/uat-init.c
index c91c617..10a0fad 100644
--- a/test/uat-init.c
+++ b/test/uat-init.c
@@ -39,7 +39,7 @@ static char g_ibeacon_adv_len[MENU_DATA_SIZE + 1] = {0,}; /**< iBeacon advertisi
static char g_ibeacon_adv_str[MENU_DATA_SIZE + 1] = {0,}; /**< iBeacon advertising data */
static void __user_detected_foreach_sensors(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
int ret;
char buf[MENU_DATA_SIZE] = {0, };
@@ -130,7 +130,7 @@ const char * __convert_device_mac_type_to_txt(ua_mac_type_e mac_type)
}
static void __user_presence_detected_foreach_devices(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
int ret;
ua_device_h device_handle = (ua_device_h)data;
@@ -155,8 +155,8 @@ static void __user_presence_detected_foreach_devices(gpointer data,
}
static void __user_presence_detected_cb(int result, ua_monitor_h monitor,
- ua_user_h user_handle, GSList *device_handles, GSList *sensor_handles,
- void *user_data)
+ ua_user_h user_handle, GSList *device_handles, GSList *sensor_handles,
+ void *user_data)
{
int ret;
char *account = NULL;
@@ -193,6 +193,58 @@ static void __sensor_state_changed_cb(bool ready,
msgb("sensor: %s is %s",
uat_get_sensor_bitmask_str(sensor), (ready ? "Ready" : "Not Ready"));
}
+static void __sensor_status_changed_cb(ua_sensor_status_e status,
+ ua_monitor_h handle, ua_sensor_h sensor_handle, void *user_data)
+{
+ int ret;
+ double *value;
+ GSList *l = 0;
+ long int timestamp;
+ int info_count = 0;
+ ua_sensor_e sensor;
+ GSList *values = NULL;
+ char buf[MENU_DATA_SIZE] = {0, };
+ char final_buf[MENU_DATA_SIZE * 4] = {0, };
+ char *pbuf = uat_get_time();
+
+ msgr("\n[%s] Sensor Status Changed -> %s",
+ pbuf, status == UA_SENSOR_PRESENCE ? "PRESENCE" : "ABSENCE");
+ free(pbuf);
+
+ ret = ua_sensor_get_bitmask(sensor_handle, &sensor);
+ if (UA_ERROR_NONE != ret) {
+ msg(" - ua_sensor_get_bitmask() ret: [0x%X] [%s]",
+ ret, uat_get_error_str(ret));
+ }
+
+ ret = ua_sensor_get_timestamp(sensor_handle, &timestamp);
+ if (UA_ERROR_NONE != ret) {
+ msg(" - ua_sensor_get_timestamp() ret: [0x%X] [%s]",
+ ret, uat_get_error_str(ret));
+ }
+
+ ret = ua_sensor_get_info_count(sensor_handle, &info_count);
+ if (UA_ERROR_NONE != ret) {
+ msg(" - ua_sensor_get_info_count() ret: [0x%X] [%s]",
+ ret, uat_get_error_str(ret));
+ }
+
+ values = ua_sensor_get_info_values(sensor_handle);
+ if (NULL == values) {
+ msg(" - ua_sensor_get_info_values() failed");
+ }
+
+ for (l = values; l; l = g_slist_next(l)) {
+ value = (double *)l->data;
+ snprintf(buf, MENU_DATA_SIZE, "%lF ", *value);
+ strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1);
+ memset(buf, 0, MENU_DATA_SIZE);
+ }
+ msgr("[%s] information detected at timestamp [%ld] value [%s]",
+ uat_get_sensor_bitmask_str(sensor), timestamp, final_buf);
+
+ g_slist_free(values);
+}
static int run_ua_monitor_create(MManager *mm, struct menu_data *menu)
{
@@ -295,6 +347,22 @@ static int run_ua_monitor_set_sensor_state_cb(
return RET_SUCCESS;
}
+static int run_ua_monitor_set_sensor_status_cb(
+ MManager *mm, struct menu_data *menu)
+{
+ int ret = UA_ERROR_NONE;
+
+ msg("ua_monitor_set_sensor_status_cb");
+
+ ret = ua_monitor_set_sensor_status_cb(g_ua_mon_h,
+ __sensor_status_changed_cb, g_ua_mon_h);
+
+ msg(" - ua_monitor_set_sensor_status_cb() ret: [0x%X] [%s]",
+ ret, uat_get_error_str(ret));
+
+ return RET_SUCCESS;
+}
+
static int run_ua_monitor_unset_user_absence_detected_cb(
MManager *mm, struct menu_data *menu)
{
@@ -340,6 +408,21 @@ static int run_ua_monitor_unset_sensor_state_cb(
return RET_SUCCESS;
}
+static int run_ua_monitor_unset_sensor_status_cb(
+ MManager *mm, struct menu_data *menu)
+{
+ int ret = UA_ERROR_NONE;
+
+ msg("ua_monitor_unset_sensor_status_cb");
+
+ ret = ua_monitor_unset_user_absence_detected_cb(g_ua_mon_h);
+
+ msg(" - ua_monitor_unset_sensor_status_cb() ret: [0x%X] [%s]",
+ ret, uat_get_error_str(ret));
+
+ return RET_SUCCESS;
+}
+
static int run_ua_set_app_info(MManager *mm, struct menu_data *menu)
{
int ret = UA_ERROR_NONE;
@@ -472,25 +555,29 @@ struct menu_data menu_ua_init[] = {
NULL, run_ua_monitor_create, NULL },
{ "2", "ua_monitor_destroy",
NULL, run_ua_monitor_destroy, NULL },
- { "3", "ua_monitor_set_user_sensor_state_cb",
+ { "3", "ua_monitor_set_sensor_state_cb",
NULL, run_ua_monitor_set_sensor_state_cb, NULL },
- { "4", "ua_monitor_unset_user_sensor_state_cb",
+ { "4", "ua_monitor_unset_sensor_state_cb",
NULL, run_ua_monitor_unset_sensor_state_cb, NULL },
- { "5", "ua_monitor_set_user_absence_detected_cb",
+ { "5", "ua_monitor_set_sensor_status_cb",
+ NULL, run_ua_monitor_set_sensor_status_cb, NULL },
+ { "6", "ua_monitor_unset_sensor_status_cb",
+ NULL, run_ua_monitor_unset_sensor_status_cb, NULL },
+ { "7", "ua_monitor_set_user_absence_detected_cb",
NULL, run_ua_monitor_set_user_absence_detected_cb, NULL },
- { "6", "ua_monitor_unset_absence_detected_cb",
+ { "8", "ua_monitor_unset_absence_detected_cb",
NULL, run_ua_monitor_unset_user_absence_detected_cb, NULL },
- { "7", "ua_monitor_set_user_presence_detected_cb",
+ { "9", "ua_monitor_set_user_presence_detected_cb",
NULL, run_ua_monitor_set_user_presence_detected_cb, NULL },
- { "8", "ua_monitor_unset_presence_detected_cb",
+ { "10", "ua_monitor_unset_presence_detected_cb",
NULL, run_ua_monitor_unset_user_presence_detected_cb, NULL },
- { "9", "ua_set_app_info",
+ { "11", "ua_set_app_info",
menu_ua_set_app_info, NULL, NULL},
- { "10", "ua_unset_app_info",
+ { "12", "ua_unset_app_info",
menu_ua_unset_app_info, NULL, NULL},
- { "11", "ua_reset_database",
+ { "13", "ua_reset_database",
NULL, run_ua_reset_database, NULL},
- { "12", "ua_add_ibeacon_adv_data",
+ { "14", "ua_add_ibeacon_adv_data",
menu_ua_add_ibeacon_adv_data, NULL, NULL},
{ NULL, NULL, },
};