summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhay Agarwal <ay.agarwal@samsung.com>2019-10-04 20:20:04 +0900
committersaerome.kim <saerome.kim@samsung.com>2019-10-04 20:26:23 +0900
commit860f7a089534c650e61dd0cca78745b89f5711aa (patch)
treee8571bd50d5f13ead0050c33657ba11fa98f55e1
parentbc903f646ce332f2a2b527de03ce94ecc2369c95 (diff)
downloaduser-awareness-860f7a089534c650e61dd0cca78745b89f5711aa.tar.gz
user-awareness-860f7a089534c650e61dd0cca78745b89f5711aa.tar.bz2
user-awareness-860f7a089534c650e61dd0cca78745b89f5711aa.zip
Provide sensor info in user absence detected callback
Change-Id: I5c7164a7dd9f8e71f7b5a6654f736ef71acd0a59 Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
-rw-r--r--include/user-awareness.h5
-rw-r--r--src/user-awareness-monitors.c18
-rw-r--r--test/uat-init.c107
3 files changed, 73 insertions, 57 deletions
diff --git a/include/user-awareness.h b/include/user-awareness.h
index 88c6388..7f3134b 100644
--- a/include/user-awareness.h
+++ b/include/user-awareness.h
@@ -395,7 +395,7 @@ typedef void (*ua_presence_detected_cb)(
* In case monitor has more than one sensor and detection mode is not
* #UA_DETECT_MODE_ANY_SENSOR, sensor will be set to #UA_SENSOR_MAX before
* invoking callback.
- * @param[in] sensor_info The sensor info for the detected sensor.
+ * @param[in] sensor_handle The sensor info for the detected sensor.
* @param[in] user_data The user data passed in ua_monitor_start_absence_detection()
*
* @exception
@@ -408,7 +408,7 @@ typedef void (*ua_absence_detected_cb)(
int result,
ua_monitor_h handle,
ua_sensor_e sensor,
- ua_sensor_h sensor_info,
+ ua_sensor_h sensor_handle,
void *user_data);
/**
@@ -439,6 +439,7 @@ typedef void (*ua_absence_user_detected_cb)(
int result,
ua_monitor_h handle,
ua_user_h user_handle,
+ GSList *sensor_handle,
void *user_data);
/**
diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c
index d0a3ba6..20bb907 100644
--- a/src/user-awareness-monitors.c
+++ b/src/user-awareness-monitors.c
@@ -472,6 +472,7 @@ static void __ua_monitor_send_user_absence_cb(ua_monitor_s *monitor,
gboolean and_condition = 0;
gboolean or_condition = 0;
gboolean condition_result = 0;
+ GSList *sensors = 0;
ua_user_h user_handle = _ua_get_user_handle_by_account(
user_state->account);
@@ -523,8 +524,11 @@ static void __ua_monitor_send_user_absence_cb(ua_monitor_s *monitor,
return;
}
+ /** Get sensor list*/
+ sensors = ua_sensor_get_sensor_handle_list(monitor->absence_detected_bitmask);
+
((ua_absence_user_detected_cb)monitor->absence_user_cb.callback)(
- UA_ERROR_NONE, monitor, user_handle,
+ UA_ERROR_NONE, monitor, user_handle, sensors,
monitor->absence_user_cb.user_data);
FUNC_EXIT;
@@ -590,10 +594,12 @@ static void __ua_sensor_absence_detected(ua_monitor_s *monitor,
FUNC_ENTRY;
bool all_absence;
GSList *l;
+ int ret = UA_ERROR_NONE;
int found = 0;
ua_user_state_info_s *user_state = NULL;
ua_sensor_e bitmask = sensor_info->bitmask;
ret_if(NULL == monitor);
+ ua_sensor_h sensor_handle;
if (account) {
for (l = monitor->user_state; l; l = g_slist_next(l)) {
@@ -619,6 +625,12 @@ static void __ua_sensor_absence_detected(ua_monitor_s *monitor,
monitor->absence_detected_bitmask |= bitmask;
}
+ ret = ua_sensor_get_by_sensor_info(sensor_info, &sensor_handle);
+ if (UA_ERROR_NONE != ret) {
+ UA_INFO("ua_device_get_by_device_id returned %s",
+ _ua_get_error_string(ret));
+ }
+
switch (monitor->absence_mode) {
case UA_DETECT_MODE_ALL_SENSOR:
break;
@@ -630,12 +642,12 @@ static void __ua_sensor_absence_detected(ua_monitor_s *monitor,
if (all_absence) {
if (monitor->absence_cb)
monitor->absence_cb(UA_ERROR_NONE, monitor,
- bitmask, sensor_info, monitor->user_data);
+ bitmask, sensor_handle, monitor->user_data);
}
} else {
if (monitor->absence_cb)
monitor->absence_cb(UA_ERROR_NONE, monitor,
- bitmask, sensor_info, monitor->user_data);
+ bitmask, sensor_handle, monitor->user_data);
}
break;
diff --git a/test/uat-init.c b/test/uat-init.c
index 2381cfd..9a36364 100644
--- a/test/uat-init.c
+++ b/test/uat-init.c
@@ -38,8 +38,58 @@ static char g_uid[MENU_DATA_SIZE + 1] = {0,}; /**< User id */
static char g_ibeacon_adv_len[MENU_DATA_SIZE + 1] = {0,}; /**< iBeacon advertising data length */
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)
+{
+ int ret;
+ char buf[MENU_DATA_SIZE] = {0, };
+ char final_buf[MENU_DATA_SIZE * 4] = {0, };
+ long int timestamp;
+ int info_count = 0;
+ GSList *values = NULL;
+ double *value;
+ GSList *l = 0;
+ ua_sensor_e bitmask;
+ ua_device_h sensor_handle = (ua_sensor_h)data;
+
+ ret = ua_sensor_get_bitmask(sensor_handle, &bitmask);
+ 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);
+ }
+ msgb("[%s] information detected at timestamp [%ld] value [%s]",
+ uat_get_sensor_bitmask_str(bitmask), timestamp,
+ final_buf);
+
+ g_slist_free(values);
+}
+
static void __user_absence_detected_cb(int result, ua_monitor_h monitor,
- ua_user_h user_handle, void *user_data)
+ ua_user_h user_handle, GSList *sensor_handles, void *user_data)
{
int ret;
char *account = NULL;
@@ -55,6 +105,9 @@ static void __user_absence_detected_cb(int result, ua_monitor_h monitor,
}
msgp("[%s] ABSENCE detected [%s]", account, uat_get_error_str(result));
+ g_slist_foreach(sensor_handles,
+ __user_detected_foreach_sensors, NULL);
+
if (account) {
free(account);
}
@@ -101,56 +154,6 @@ static void __user_presence_detected_foreach_devices(gpointer data,
g_free(mac);
}
-static void __user_presence_detected_foreach_sensors(gpointer data,
- gpointer user_data)
-{
- int ret;
- char buf[MENU_DATA_SIZE] = {0, };
- char final_buf[MENU_DATA_SIZE * 4] = {0, };
- long int timestamp;
- int info_count = 0;
- GSList *values = NULL;
- double *value;
- GSList *l = 0;
- ua_sensor_e bitmask;
- ua_device_h sensor_handle = (ua_sensor_h)data;
-
- ret = ua_sensor_get_bitmask(sensor_handle, &bitmask);
- 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);
- }
- msgb("[%s] information detected at timestamp [%ld] value [%s]",
- uat_get_sensor_bitmask_str(bitmask), timestamp,
- final_buf);
-
- g_slist_free(values);
-}
-
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)
@@ -173,7 +176,7 @@ static void __user_presence_detected_cb(int result, ua_monitor_h monitor,
account);
g_slist_foreach(sensor_handles,
- __user_presence_detected_foreach_sensors, NULL);
+ __user_detected_foreach_sensors, NULL);
g_free(account);
}