filter list of found_devices of a user based on sensors mentioned in AND/OR conditions
authorLokesh <l.kasana@samsung.com>
Mon, 9 Sep 2019 05:39:14 +0000 (11:09 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 16 Sep 2019 12:05:14 +0000 (21:05 +0900)
Change-Id: I49c00ab54aa734506e4403b08f58fc04b2a4e9d7
Signed-off-by: Lokesh <l.kasana@samsung.com>
include/user-awareness-private.h
include/user-awareness-util.h
packaging/capi-network-ua.spec
src/user-awareness-monitors.c
src/user-awareness-util.c

index 7ac8781287a7c3231ad499bfee47e216841f5571..24764804b24717df37ceadabff71594ad82fc570 100644 (file)
@@ -199,6 +199,7 @@ typedef struct {
        gboolean cb_sent; /** User presence callback sent or not flag */
 } ua_user_state_info_s;
 
+//TODO Unused struct.
 /**
  * @brief Sensor state data structure.
  * @since_tizen 5.5
index 94e23368baa464cb5e057834ea59b5d51e18de38..de20517d30b48911d615b3509e8438ec8477f885 100644 (file)
@@ -146,6 +146,30 @@ const char* _ua_get_error_string(ua_error_code_e err);
  */
 uam_tech_type_e _ua_to_uam_tech_type(ua_mac_type_e type);
 
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @internal
+ * @brief Converts device's tech. type enum to sensor bitmask enum.
+ * @since_tizen 5.5
+ *
+ * @remarks The returned value can be used until return call function is valid.
+ *
+ * @param[in] type Tech code to be converted.
+ *
+ * @return Sensor bitmask
+ *
+ * @retval #UA_SENSOR_BT Bluetooth
+ * @retval #UA_SENSOR_BLE Bluetooth Low Energy
+ * @retval #UA_SENSOR_WIFI Wi-Fi
+ * @retval #UA_SENSOR_MAX Invalid
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+ua_sensor_e _ua_dev_type_to_sensor(ua_mac_type_e type);
+
 #ifdef __cplusplus
 }
 #endif
index 9c8f8525d80a7192a02cc529c4e89a0e782e16fe..d8633260ad98190e362aeea7adc984fc0b4ee71b 100644 (file)
@@ -1,6 +1,6 @@
 Name: capi-network-ua
 Summary: User Awareness Framework CAPI
-Version: 0.8.7
+Version: 0.8.8
 Release: 1
 License: Apache-2.0
 Source0: %{name}-%{version}.tar.gz
index 4f9f7fcd1eee6f578325a05ac47e401f58acd455..1408294c33622e011c59ecc705af85544aa2af7b 100644 (file)
@@ -160,6 +160,7 @@ static ua_sensor_e __ua_sensor_bitmask_to_type(unsigned int bitmask)
                UA_WARN("Unknown sensor bitmask [0x%8.8X]", bitmask);
                return UA_SENSOR_MAX;
        }
+       FUNC_EXIT;
 }
 /* LCOV_EXCL_STOP */
 
@@ -267,15 +268,23 @@ static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
        FUNC_ENTRY;
        unsigned int env_presence_bitmask = 0;
        unsigned int user_sensor_bitmask = user_state->sensor_bitmask;
+       unsigned int filter_bitmask = 0;
+       unsigned int dev_bitmask = 0;
+       GSList *l = 0;
+       GSList *devices = 0;
        gboolean and_condition = 0;
        gboolean or_condition = 0;
        gboolean condition_result = 0;
+       ua_dev_info_s *dev = 0;
+
        ret_if(NULL == user_state);
 
        ua_user_h user_handle = _ua_get_user_handle_by_account(
                        user_state->account);
        env_presence_bitmask = monitor->presence_detected_bitmask
                        & (UA_SENSOR_MOTION | UA_SENSOR_LIGHT);
+       filter_bitmask =
+                       monitor->presence_bitmask_and | monitor->presence_bitmask_or;
 
        /**
         * Check whether user_handle present or not and also check
@@ -317,12 +326,31 @@ static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
                return;
        }
 
+       /**
+        * Filter the list of found_devices according to sensors mentioned in
+        * AND/OR conditions.
+        */
+       for (l = user_state->found_devices; l; l = g_slist_next(l)) {
+               dev = (ua_dev_info_s *)l->data;
+               if(!dev)
+                       continue;
+
+               UA_DBG("device id [%s], dev type [%u]", dev->device_id, dev->type);
+
+               dev_bitmask = _ua_dev_type_to_sensor(dev->type);
+               if (dev_bitmask & filter_bitmask)
+                       devices = g_slist_prepend(devices, dev);
+       }
+
        ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)(
                                        UA_ERROR_NONE, monitor, user_handle,
-                                       user_state->found_devices,
+                                       devices,
                                        monitor->presence_user_cb.user_data);
 
        user_state->cb_sent = TRUE;
+
+       g_slist_free(devices);
+
        FUNC_EXIT;
        return;
 }
index d07ab50ba0750adc72b25fc0b4aa311a00a372a3..3500a37ce0e966701a1192323c44d576b7106083 100644 (file)
@@ -171,3 +171,21 @@ uam_tech_type_e _ua_to_uam_tech_type(ua_mac_type_e type)
                return UA_MAC_TYPE_INVALID;
        }
 }
+
+ua_sensor_e _ua_dev_type_to_sensor(ua_mac_type_e type)
+{
+       FUNC_ENTRY;
+
+       switch (type) {
+       case UA_MAC_TYPE_BT:
+               return UA_SENSOR_BT;
+       case UA_MAC_TYPE_BLE:
+               return UA_SENSOR_BLE;
+       case UA_MAC_TYPE_WIFI:
+               return UA_SENSOR_WIFI;
+       default:
+               UA_WARN("Uncompatible to convert. Mac type [%u]", type);
+               return UA_SENSOR_MAX;
+       }
+       FUNC_EXIT;
+}