Provide sensor info in user absence detected callback
authorAbhay Agarwal <ay.agarwal@samsung.com>
Fri, 4 Oct 2019 11:20:04 +0000 (20:20 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Fri, 4 Oct 2019 11:26:23 +0000 (20:26 +0900)
Change-Id: I5c7164a7dd9f8e71f7b5a6654f736ef71acd0a59
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/user-awareness.h
src/user-awareness-monitors.c
test/uat-init.c

index 88c6388556533a5d8432cb9e01e7e3de85590d25..7f3134bee21d289a70605bbdd837ca520c2a597a 100644 (file)
@@ -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);
 
 /**
index d0a3ba63b3871afb8e38f96f59044fedc1dd2900..20bb90742fae30425ddf43b50766c0f306e88398 100644 (file)
@@ -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;
 
index 2381cfd409fca1c92cac011385b67d2f524c8c81..9a36364b0f0984077755cef8dcac650e0552ada6 100644 (file)
@@ -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);
 }