Modify uat-test that detection cases can be distinguish more cleary
authorsaerome.kim <saerome.kim@samsung.com>
Tue, 22 Oct 2019 07:30:58 +0000 (16:30 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Wed, 23 Oct 2019 00:32:21 +0000 (09:32 +0900)
Change-Id: Iddd83f882579b6eaac368749426ecb0932988c5f
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
include/user-awareness-private.h
include/user-awareness.h [changed mode: 0755->0644]
packaging/capi-network-ua.spec
src/user-awareness-monitors.c
src/user-awareness-util.c
test/uat-common.h
test/uat-detections.c
test/uat-init.c
test/uat-menu.h

index 0a507f583fa3bb662010f0941a0f42f963f88d96..3d48c5d3f971589c8603f1a70dd157896dffff25 100644 (file)
@@ -201,7 +201,7 @@ typedef struct {
  * @since_tizen 5.5
  */
 typedef struct {
-       unsigned  int status; /**< Sensor status 1:PRESENCE 2:ABSENCE */
+       unsigned int status; /**< Sensor status 1:PRESENCE 2:ABSENCE */
        ua_sensor_h handle; /**< Sensor handle */
        ua_sensor_e bitmask; /**< Sensor bitmask */
        unsigned long long timestamp; /**< Timestamp */
old mode 100755 (executable)
new mode 100644 (file)
index 53bd1ad..a35b31f
@@ -315,6 +315,35 @@ typedef void (*ua_monitor_sensor_state_changed_cb)(
                ua_monitor_h handle,
                void *user_data);
 
+/**
+ * @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_monitor_h handle,
+               ua_sensor_h sensor_handle,
+               void *user_data);
+
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
  * @brief Callback to get all sensors for a handle.
@@ -608,35 +637,6 @@ typedef bool (*ua_service_added_device_cb)(
                ua_device_h device_handle,
                void *user_data);
 
-/**
- * @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.
@@ -2874,6 +2874,27 @@ int ua_device_foreach_added_by_user(
                ua_registered_dev_cb foreach_cb,
                void *user_data);
 
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Gets sensor's status.
+ * @since_tizen 5.5
+ *
+ * @param[in] sensor_handle The sensor handle
+ * @param[out] status The sensor's status.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+int ua_sensor_get_status(
+               ua_sensor_h sensor_handle,
+               ua_sensor_status_e *status);
+
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
  * @brief Gets sensor's timestamp.
index 8d926e513d815b46de381c0231a9cdc3a7a0fb4c..c78d9c9ceedf48c7976c8bbb867ca8d84b7398fc 100644 (file)
@@ -1,6 +1,6 @@
 Name: capi-network-ua
 Summary: User Awareness Framework CAPI
-Version: 0.12.1
+Version: 0.12.2
 Release: 1
 License: Apache-2.0
 Source0: %{name}-%{version}.tar.gz
index b2a0bd7d3c6aca8c012a57910442aac869bf855a..7650639c08ac7f26710a175a96df0fbfe938ee89 100644 (file)
@@ -427,7 +427,7 @@ static void __ua_monitor_send_sensor_presence_cb(ua_monitor_s *monitor,
 
        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_INFO("ua_sensor_get_by_sensor_info returned %s",
                                _ua_get_error_string(ret));
        }
 
@@ -719,7 +719,7 @@ static void __ua_sensor_absence_detected(ua_monitor_s *monitor,
 
        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_INFO("ua_sensor_get_by_sensor_info returned %s",
                                _ua_get_error_string(ret));
        }
 
@@ -992,13 +992,23 @@ void _ua_monitor_handle_sensor_state(unsigned int bitmask, gboolean ready)
 void _ua_monitor_handle_sensor_status_changed(uam_sensor_info_s *info)
 {
        FUNC_ENTRY;
+
+       int ret;
        GSList *l;
+       ua_sensor_h dummy;
+
        ua_sensor_info_s *sensor_info;
        ret_if(NULL == info);
 
        sensor_info = _uam_to_ua_sensor_info(info);
        ret_if(NULL == sensor_info);
 
+       ret = ua_sensor_get_by_sensor_info(sensor_info, &dummy);
+       if (UA_ERROR_NONE != ret) {
+               UA_INFO("ua_sensor_get_by_sensor_info returned %s",
+                               _ua_get_error_string(ret));
+       }
+
        for (l = ua_monitor_list; l; l = g_slist_next(l)) {
                ua_monitor_s *monitor = l->data;
 
@@ -1012,7 +1022,7 @@ void _ua_monitor_handle_sensor_status_changed(uam_sensor_info_s *info)
 
                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,
+                               (ua_monitor_h)monitor, (ua_sensor_h)sensor_info,
                                monitor->sensor_state_cb.user_data);
        }
        _ua_free_sensor_info(sensor_info);
index 40dc102d4760ecbee63a9fcd29a6a826af3e5777..af99a2fd961aeebfbddea22c690fb29642bb1e13 100644 (file)
@@ -360,6 +360,23 @@ GSList *ua_sensor_get_sensor_handle_list(
        return sensors;
 }
 
+int ua_sensor_get_status(
+               ua_sensor_h sensor_handle,
+               ua_sensor_status_e *status)
+{
+       FUNC_ENTRY;
+       ua_sensor_info_s *sensor;
+
+       UA_VALIDATE_INPUT_PARAMETER(sensor_handle);
+       UA_INFO("Sensor Handle [%p]", sensor_handle);
+       sensor = (ua_sensor_info_s *)sensor_handle;
+
+       *status = sensor->status;
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
 int ua_sensor_get_timestamp(
                ua_sensor_h sensor_handle,
                unsigned long long *timestamp)
index 6e617633117987695dd8403f1c624d38872be1d1..f009d544bda721214e9f6ab190cf83dc16f896b2 100644 (file)
@@ -39,6 +39,11 @@ typedef enum {
        UAT_MAC_TYPE_MAX
 } uat_mac_type_e;
 
+typedef enum {
+       UAT_PRESENCE = 1,
+       UAT_ABSENCE = 2
+} uat_detection_type_e;
+
 const char* uat_get_error_str(int err);
 const char* uat_get_sensor_str(int sensors);
 const char* uat_get_mac_type_str(int sensor);
index b0b24b316ac2b287dcde4fce92aceb2903a42b2d..711c2cf98736271e50fe5f6d5d435395576d0e5d 100644 (file)
@@ -54,8 +54,8 @@ static char g_lpm_onoff[MENU_DATA_SIZE + 1] = "1"; /**<  LPM mode on/off */
 static void __sensor_presence_detected_device(ua_device_h device_handle)
 {
        int ret;
-       ua_mac_type_e mac_type;
        char *mac = NULL;
+       ua_mac_type_e mac_type;
 
        ret = ua_device_get_mac_address(device_handle, &mac);
        if (UA_ERROR_NONE != ret) {
@@ -67,23 +67,23 @@ static void __sensor_presence_detected_device(ua_device_h device_handle)
                msg(" - ua_device_get_mac_type() ret: [0x%X] [%s]",
                        ret, uat_get_error_str(ret));
        }
-       msgb("Presence detected on [%s][%s]",
-            __convert_device_mac_type_to_txt(mac_type), mac);
+       msgb("[%s] Presence detected on [%s]",
+             __convert_device_mac_type_to_txt(mac_type), mac);
 
        g_free(mac);
 }
 
-static void __sensor_presence_detected_sensor_info(ua_sensor_e sensor,
-       ua_sensor_h sensor_handle)
+static void __sensor_detected_sensor_info(int type,
+       ua_sensor_e sensor, ua_sensor_h sensor_handle)
 {
        int ret;
-       char buf[MENU_DATA_SIZE] = {0, };
-       char final_buf[MENU_DATA_SIZE * 4] = {0, };
-       unsigned long long timestamp;
-       int info_count = 0;
-       GSList *values = NULL;
        double *value;
        GSList *l = 0;
+       int info_count = 0;
+       GSList *values = NULL;
+       unsigned long long timestamp;
+       char buf[MENU_DATA_SIZE] = {0, };
+       char final_buf[MENU_DATA_SIZE * 4] = {0, };
 
        ret = ua_sensor_get_timestamp(sensor_handle, &timestamp);
        if (UA_ERROR_NONE != ret) {
@@ -108,9 +108,13 @@ static void __sensor_presence_detected_sensor_info(ua_sensor_e sensor,
                strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1);
                memset(buf, 0, MENU_DATA_SIZE);
        }
-       msgb("[%s] information detected at timestamp [%llu] value [%s]",
-               uat_get_sensor_bitmask_str(sensor), timestamp,
-                       final_buf);
+
+       if (UAT_PRESENCE == type)
+               msgb("[%s] timestamp [%llu] value [%s]",
+                       uat_get_sensor_bitmask_str(sensor), timestamp, final_buf);
+       else
+               msgp("[%s] timestamp [%llu] value [%s]",
+                       uat_get_sensor_bitmask_str(sensor), timestamp, final_buf);
 
        g_slist_free(values);
 }
@@ -120,7 +124,7 @@ static void __sensor_presence_detected_cb(int result, ua_monitor_h monitor,
                void *user_data)
 {
        char *pbuf = uat_get_time();
-       msg("\n[%s] Sensor PRESENCE [%d]", pbuf, sensor);
+       msgb("\n[%s]", pbuf);
        free(pbuf);
 
        if (UA_SENSOR_BLE == (UA_SENSOR_BLE & sensor)) {
@@ -145,14 +149,14 @@ static void __sensor_presence_detected_cb(int result, ua_monitor_h monitor,
                __sensor_presence_detected_device(device_handle);
        /* For sensor information */
        if (sensor_handle && (sensor & (UA_SENSOR_LIGHT | UA_SENSOR_MOTION)))
-               __sensor_presence_detected_sensor_info(sensor, sensor_handle);
+               __sensor_detected_sensor_info(UAT_PRESENCE, sensor, sensor_handle);
 }
 
 static void __sensor_absence_detected_cb(int result, ua_monitor_h monitor,
        ua_sensor_e sensor, ua_sensor_h sensor_handle, void *user_data)
 {
        char *pbuf = uat_get_time();
-       msg("\n[%s] Sensor ABSENCE", pbuf);
+       msgp("\n[%s]", pbuf);
        free(pbuf);
 
        if (UA_SENSOR_BLE == (UA_SENSOR_BLE & sensor)) {
@@ -173,7 +177,7 @@ static void __sensor_absence_detected_cb(int result, ua_monitor_h monitor,
        }
        /* For sensor information */
        if (sensor_handle && (sensor & (UA_SENSOR_LIGHT | UA_SENSOR_MOTION)))
-               __sensor_presence_detected_sensor_info(sensor, sensor_handle);
+               __sensor_detected_sensor_info(UAT_ABSENCE, sensor, sensor_handle);
 }
 
 void __ua_test_scan_completed_cb(ua_active_scan_type_e result,
index 508168bc99d0eb17555f860d30843ed13f6c44c2..1392e01b216371b3ba5b268d49f15b90b3f95233 100644 (file)
@@ -42,13 +42,15 @@ 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, };
-       unsigned long long timestamp;
-       int info_count = 0;
-       GSList *values = NULL;
        double *value;
        GSList *l = 0;
+       int info_count = 0;
+       GSList *values = NULL;
+       int type = (int)user_data;
+       unsigned long long timestamp;
+       char buf[MENU_DATA_SIZE] = {0, };
+       char final_buf[MENU_DATA_SIZE * 4] = {0, };
+
        ua_sensor_e bitmask;
        ua_device_h sensor_handle = (ua_sensor_h)data;
 
@@ -81,9 +83,13 @@ static void __user_detected_foreach_sensors(gpointer data,
                strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1);
                memset(buf, 0, MENU_DATA_SIZE);
        }
-       msgb("[%s] information detected at timestamp [%llu] value [%s]",
-               uat_get_sensor_bitmask_str(bitmask), timestamp,
-                       final_buf);
+
+       if (UAT_PRESENCE == type)
+               msgbr("[%s] timestamp [%llu] value [%s]",
+                       uat_get_sensor_bitmask_str(bitmask), timestamp, final_buf);
+       else
+               msgr("[%s] timestamp [%llu] value [%s]",
+                       uat_get_sensor_bitmask_str(bitmask), timestamp, final_buf);
 
        g_slist_free(values);
 }
@@ -95,7 +101,7 @@ static void __user_absence_detected_cb(int result, ua_monitor_h monitor,
        char *account = NULL;
        char *pbuf = uat_get_time();
 
-       msg("\n[%s]", pbuf);
+       msgr("\n[%s]", pbuf);
        free(pbuf);
 
        ret = ua_user_get_account(user_handle, &account);
@@ -103,10 +109,10 @@ static void __user_absence_detected_cb(int result, ua_monitor_h monitor,
                msg(" - ua_user_get_account() ret: [0x%X] [%s]",
                        ret, uat_get_error_str(ret));
        }
-       msgp("[%s] ABSENCE detected [%s]", account, uat_get_error_str(result));
+       msgr("[%s] ABSENCE detected [%s]", account, uat_get_error_str(result));
 
        g_slist_foreach(sensor_handles,
-                       __user_detected_foreach_sensors, NULL);
+               __user_detected_foreach_sensors, (void* )UAT_ABSENCE);
 
        if (account) {
                free(account);
@@ -148,7 +154,7 @@ static void __user_presence_detected_foreach_devices(gpointer data,
                msg(" - ua_device_get_mac_type() ret: [0x%X] [%s]",
                        ret, uat_get_error_str(ret));
        }
-       msgb("[%s] detected on [%s][%s]", account,
+       msgbr("[%s] detected on [%s][%s]", account,
             __convert_device_mac_type_to_txt(mac_type), mac);
 
        g_free(mac);
@@ -162,7 +168,7 @@ static void __user_presence_detected_cb(int result, ua_monitor_h monitor,
        char *account = NULL;
        char *pbuf = uat_get_time();
 
-       msg("\n[%s]", pbuf);
+       msgbr("\n[%s]", pbuf);
        free(pbuf);
 
        if (user_handle) {
@@ -171,18 +177,16 @@ static void __user_presence_detected_cb(int result, ua_monitor_h monitor,
                        msg(" - ua_user_get_account() ret: [0x%X] [%s]",
                                ret, uat_get_error_str(ret));
                }
-               msgb("[%s] PRESENCE detected [%s]", account, uat_get_error_str(result));
-               g_slist_foreach(device_handles,
-                               __user_presence_detected_foreach_devices,
-                               account);
+               msgbr("[%s] PRESENCE detected [%s]", account, uat_get_error_str(result));
+               g_slist_foreach(device_handles, __user_presence_detected_foreach_devices, account);
        }
 
        if (!account) {
-               msgb("[No user information] PRESENCE detected [%s]", uat_get_error_str(result));
+               msgbr("[No user information] PRESENCE detected [%s]", uat_get_error_str(result));
        }
 
        g_slist_foreach(sensor_handles,
-                       __user_detected_foreach_sensors, NULL);
+                       __user_detected_foreach_sensors, (void *)UAT_PRESENCE);
 
        g_free(account);
 }
@@ -190,27 +194,36 @@ static void __user_presence_detected_cb(int result, ua_monitor_h monitor,
 static void __sensor_state_changed_cb(bool ready,
                ua_sensor_e sensor, ua_monitor_h monitor, void *user_data)
 {
-       msgb("sensor: %s is %s",
+       msgn("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)
+static void __sensor_status_changed_cb(ua_monitor_h handle,
+       ua_sensor_h sensor_handle, void *user_data)
 {
        int ret;
        double *value;
        GSList *l = 0;
-       unsigned long long timestamp;
        int info_count = 0;
        ua_sensor_e sensor;
        GSList *values = NULL;
+       ua_sensor_status_e status;
+       unsigned long long timestamp;
        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");
+       msgc("\n[%s]", pbuf);
        free(pbuf);
 
+       ret = ua_sensor_get_status(sensor_handle, &status);
+       if (UA_ERROR_NONE != ret) {
+               msg(" - ua_sensor_get_status() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+       }
+       msgc("[%s] Sensor Status Changed -> %s",
+               uat_get_sensor_bitmask_str(sensor),
+               status == UA_SENSOR_PRESENCE ? "PRESENCE" : "ABSENCE");
+
        ret = ua_sensor_get_bitmask(sensor_handle, &sensor);
        if (UA_ERROR_NONE != ret) {
                msg(" - ua_sensor_get_bitmask() ret: [0x%X] [%s]",
@@ -240,7 +253,7 @@ static void __sensor_status_changed_cb(ua_sensor_status_e status,
                strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1);
                memset(buf, 0, MENU_DATA_SIZE);
        }
-       msgr("[%s] information detected at timestamp [%llu] value [%s]",
+       msgc("[%s] timestamp [%llu] value [%s]",
                uat_get_sensor_bitmask_str(sensor), timestamp, final_buf);
 
        g_slist_free(values);
@@ -415,7 +428,7 @@ static int run_ua_monitor_unset_sensor_status_cb(
 
        msg("ua_monitor_unset_sensor_status_cb");
 
-       ret = ua_monitor_unset_user_absence_detected_cb(g_ua_mon_h);
+       ret = ua_monitor_unset_sensor_status_cb(g_ua_mon_h);
 
        msg(" - ua_monitor_unset_sensor_status_cb() ret: [0x%X] [%s]",
                        ret, uat_get_error_str(ret));
index a26c8565c5b55197502e2b133d92890c642f1b32..a3e1482eb13b5ffffea79ced56f5700381382d2f 100644 (file)
@@ -58,6 +58,23 @@ __BEGIN_DECLS
 #define msgp(fmt, args...) do { fprintf(stdout, ANSI_COLOR_LIGHTMAGENTA fmt \
                ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
 
+/* Bold (Cyan) */
+#define msgc(fmt, args...) do { fprintf(stdout, ANSI_COLOR_CYAN fmt \
+               ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
+
+/* Bold (Yellow) */
+#define msgy(fmt, args...) do { fprintf(stdout, ANSI_COLOR_YELLOW fmt \
+               ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
+
+/* Bold (Light Red) */
+#define msglr(fmt, args...) do { fprintf(stdout, ANSI_COLOR_LIGHTRED fmt \
+               ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
+
+/* Bold (Blue) */
+#define msgbr(fmt, args...) do { fprintf(stdout, ANSI_COLOR_BLUE fmt \
+               ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0)
+
+
 #define msgt(n, fmt, args...) do { fprintf(stdout, "\e[%dC" fmt "\n", \
                3 + ((n) * 2), ##args); fflush(stdout); } while (0)