Added discriminant functionality 85/210885/1
authorsaerome.kim <saerome.kim@samsung.com>
Thu, 25 Jul 2019 06:02:13 +0000 (15:02 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 25 Jul 2019 22:45:45 +0000 (07:45 +0900)
This function is used to set/get 'discriminant' flag to determine
whether a device to be deteced or not.

Change-Id: I3797b778d050dfb1a6a3c2386ca87a19e6b3e521
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
13 files changed:
include/ua-api.h
include/ua-internal.h
ua-api/src/ua-api.c
ua-daemon/data/ua_db.sql
ua-daemon/include/ua-manager-core.h
ua-daemon/include/ua-manager-database.h
ua-daemon/src/pm/ua-ble-plugin-handler.c [changed mode: 0644->0755]
ua-daemon/src/pm/ua-pm-util.c [changed mode: 0644->0755]
ua-daemon/src/pm/ua-wifi-plugin-handler.c [changed mode: 0644->0755]
ua-daemon/src/ua-manager-core.c
ua-daemon/src/ua-manager-device-db.c
ua-daemon/src/ua-manager-request-handler.c
ua-plugins/include/ua-plugin.h

index 99262a4..9eed718 100644 (file)
@@ -440,6 +440,7 @@ typedef struct {
        char mac[UAM_MAC_ADDRESS_STRING_LEN]; /**< Device's MAC ADDRESS */
        char ipv4_addr[UAM_IP_ADDRESS_MAX_STRING_LEN];/**< Device's IPv4 address optional */
        char device_id[UAM_DEVICE_ID_MAX_STRING_LEN]; /**< Device's uniquie ID */
+       gboolean discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
        long last_seen; /**< Latest timestamp when device was discoverd */
 } uam_device_info_s;
 
@@ -1172,8 +1173,56 @@ int _uam_set_service_detection_cycle(const char *service, unsigned int cycle);
  */
 int _uam_get_service_detection_cycle(const char *service, unsigned int *cycle);
 
+/**
+ * @brief Resets contents in database.
+ * @since_tizen 5.5
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UAM_ERROR_NONE Successful
+ * @retval #UAM_ERROR_INTERNAL Internal error
+ *
+ * @exception
+ * @pre
+ * @post
+ */
 int _uam_db_reset(void);
 
+/**
+ * @brief Sets the device to determine whether to detect.
+ * @since_tizen 5.5
+ *
+ * @param[in] dev_info Device information.
+ * @param[in] discriminant Whether to detect this device or not
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UAM_ERROR_NONE Successful
+ * @retval #UAM_ERROR_INVALID_PARAMETER Invalid parameters
+ * @retval #UAM_ERROR_INTERNAL Internal error
+ *
+ * @exception
+ * @pre
+ * @post
+ */
+int _uam_request_set_device_discriminant(const char *mac, gboolean discriminant);
+
+/**
+ * @brief Sets the device to determine whether to detect.
+ * @since_tizen 5.5
+ *
+ * @param[in] dev_info Device information.
+ * @param[out] discriminant Whether to detect this device or not
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UAM_ERROR_NONE Successful
+ * @retval #UAM_ERROR_INVALID_PARAMETER Invalid parameters
+ * @retval #UAM_ERROR_INTERNAL Internal error
+ *
+ * @exception
+ * @pre
+ * @post
+ */
+int _uam_request_get_device_discriminant(const char *mac, gboolean *discriminant);
+
 #ifdef __cplusplus
 }
 #endif
index 372258c..bb0e1fc 100644 (file)
@@ -76,6 +76,8 @@ extern "C" {
        REQUEST(UAM_REQUEST_GET_SERVICE_DEVICES) \
        REQUEST(UAM_REQUEST_GET_SERVICE_USERS) \
        REQUEST(UAM_REQUEST_GET_SERVICES) \
+       REQUEST(UAM_REQUEST_GET_DEVICE_DISCRIMINANT) \
+       REQUEST(UAM_REQUEST_SET_DEVICE_DISCRIMINANT) \
        REQUEST(UAM_REQUEST_MAX)
 
 #define GENERATE_REQUEST_ENUM(ENUM) ENUM,
index 45583af..1c5b4a1 100644 (file)
@@ -122,7 +122,8 @@ UAM_EXPORT_API int _uam_get_registered_users(GPtrArray **user_list)
        return ret;
 }
 
-UAM_EXPORT_API int _uam_is_device_registered(uam_device_info_s *dev_info, gboolean *is_registered)
+UAM_EXPORT_API int _uam_is_device_registered(uam_device_info_s *dev_info,
+       gboolean *is_registered)
 {
        FUNC_ENTRY;
        int ret;
@@ -533,7 +534,8 @@ UAM_EXPORT_API int _uam_request_get_devices(GPtrArray **devices_list)
        return ret;
 }
 
-UAM_EXPORT_API int _uam_request_get_user_devices(char *account, GPtrArray **devices_list)
+UAM_EXPORT_API int _uam_request_get_user_devices(char *account,
+       GPtrArray **devices_list)
 {
        FUNC_ENTRY;
        int ret;
@@ -575,7 +577,8 @@ UAM_EXPORT_API int _uam_request_get_user_devices(char *account, GPtrArray **devi
        return ret;
 }
 
-UAM_EXPORT_API int _uam_request_set_detection_threshold(unsigned int sensor_type, int presence_threshold, int absence_threshold)
+UAM_EXPORT_API int _uam_request_set_detection_threshold(
+       unsigned int sensor_type, int presence_threshold, int absence_threshold)
 {
        FUNC_ENTRY;
        int ret;
@@ -596,7 +599,8 @@ UAM_EXPORT_API int _uam_request_set_detection_threshold(unsigned int sensor_type
        return ret;
 }
 
-UAM_EXPORT_API int _uam_start_presence_detection(unsigned int bitmask, const char *service)
+UAM_EXPORT_API int _uam_start_presence_detection(unsigned int bitmask,
+       const char *service)
 {
        FUNC_ENTRY;
        int ret;
@@ -620,7 +624,8 @@ UAM_EXPORT_API int _uam_start_presence_detection(unsigned int bitmask, const cha
        return ret;
 }
 
-UAM_EXPORT_API int _uam_stop_presence_detection(unsigned int bitmask, const char *service)
+UAM_EXPORT_API int _uam_stop_presence_detection(unsigned int bitmask,
+       const char *service)
 {
        FUNC_ENTRY;
        int ret;
@@ -644,7 +649,8 @@ UAM_EXPORT_API int _uam_stop_presence_detection(unsigned int bitmask, const char
        return ret;
 }
 
-UAM_EXPORT_API int _uam_start_absence_detection(unsigned int bitmask, const char *service)
+UAM_EXPORT_API int _uam_start_absence_detection(unsigned int bitmask,
+       const char *service)
 {
        FUNC_ENTRY;
        int ret;
@@ -668,7 +674,8 @@ UAM_EXPORT_API int _uam_start_absence_detection(unsigned int bitmask, const char
        return ret;
 }
 
-UAM_EXPORT_API int _uam_stop_absence_detection(unsigned int bitmask, const char *service)
+UAM_EXPORT_API int _uam_stop_absence_detection(unsigned int bitmask,
+       const char *service)
 {
        FUNC_ENTRY;
        int ret;
@@ -792,7 +799,8 @@ UAM_EXPORT_API int _uam_set_detection_window(unsigned int window)
        return ret;
 }
 
-UAM_EXPORT_API int _uam_start_search_active_devices(unsigned int bitmask, int detection_period)
+UAM_EXPORT_API int _uam_start_search_active_devices(unsigned int bitmask,
+       int detection_period)
 {
        FUNC_ENTRY;
        int ret;
@@ -901,7 +909,8 @@ UAM_EXPORT_API int _uam_service_add_user(const char *service, const char *accoun
        return ret;
 }
 
-UAM_EXPORT_API int _uam_service_remove_user(const char *service, const char *account)
+UAM_EXPORT_API int _uam_service_remove_user(const char *service,
+       const char *account)
 {
        FUNC_ENTRY;
        int ret;
@@ -929,7 +938,8 @@ UAM_EXPORT_API int _uam_service_remove_user(const char *service, const char *acc
        return ret;
 }
 
-UAM_EXPORT_API int _uam_service_add_device(const char *service, char *device_id, uam_tech_type_e tech_type)
+UAM_EXPORT_API int _uam_service_add_device(const char *service, char *device_id,
+       uam_tech_type_e tech_type)
 {
        FUNC_ENTRY;
        int ret;
@@ -958,7 +968,8 @@ UAM_EXPORT_API int _uam_service_add_device(const char *service, char *device_id,
        return ret;
 }
 
-UAM_EXPORT_API int _uam_service_remove_device(const char *service, char *device_id, uam_tech_type_e tech_type)
+UAM_EXPORT_API int _uam_service_remove_device(const char *service,
+       char *device_id, uam_tech_type_e tech_type)
 {
        FUNC_ENTRY;
        int ret;
@@ -987,7 +998,8 @@ UAM_EXPORT_API int _uam_service_remove_device(const char *service, char *device_
        return ret;
 }
 
-UAM_EXPORT_API int _uam_set_service_detection_cycle(const char *service, unsigned int cycle)
+UAM_EXPORT_API int _uam_set_service_detection_cycle(const char *service,
+       unsigned int cycle)
 {
        FUNC_ENTRY;
        int ret;
@@ -1011,7 +1023,8 @@ UAM_EXPORT_API int _uam_set_service_detection_cycle(const char *service, unsigne
        return ret;
 }
 
-UAM_EXPORT_API int _uam_get_service_detection_cycle(const char *service, unsigned int *cycle)
+UAM_EXPORT_API int _uam_get_service_detection_cycle(const char *service,
+       unsigned int *cycle)
 {
        FUNC_ENTRY;
        int ret;
@@ -1169,7 +1182,8 @@ UAM_EXPORT_API int _uam_get_registered_services(GPtrArray **service_list)
        return ret;
 }
 
-UAM_EXPORT_API int _uam_request_get_service_devices(char *svc_name, GPtrArray **devices_list)
+UAM_EXPORT_API int _uam_request_get_service_devices(char *svc_name,
+       GPtrArray **devices_list)
 {
        FUNC_ENTRY;
        int ret;
@@ -1211,7 +1225,8 @@ UAM_EXPORT_API int _uam_request_get_service_devices(char *svc_name, GPtrArray **
        return ret;
 }
 
-UAM_EXPORT_API int _uam_request_get_service_users(char *svc_name, GPtrArray **users_list)
+UAM_EXPORT_API int _uam_request_get_service_users(char *svc_name,
+       GPtrArray **users_list)
 {
        FUNC_ENTRY;
        int ret;
@@ -1252,3 +1267,58 @@ UAM_EXPORT_API int _uam_request_get_service_users(char *svc_name, GPtrArray **us
        FUNC_EXIT;
        return ret;
 }
+
+UAM_EXPORT_API int _uam_request_set_device_discriminant(
+       const char *mac, gboolean discriminant)
+{
+       FUNC_ENTRY;
+       int ret;
+       char str[UAM_MAC_ADDRESS_STRING_LEN + 1] = {0, };
+       int tmp = discriminant ? 1 : 0;
+
+       UAM_VALIDATE_INPUT_PARAMETER(mac);
+
+       UAM_INIT_PARAMS();
+       UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_strlcpy(str, mac, UAM_MAC_ADDRESS_STRING_LEN);
+       g_array_append_vals(in_param1, str, sizeof(str));
+       g_array_append_vals(in_param2, &tmp, sizeof(int));
+
+       ret = _uam_sync_request(UAM_REQUEST_SET_DEVICE_DISCRIMINANT,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       FUNC_EXIT;
+       return ret;
+}
+
+UAM_EXPORT_API int _uam_request_get_device_discriminant(
+       const char *mac, gboolean *discriminant)
+{
+       FUNC_ENTRY;
+       int ret;
+       char str[UAM_MAC_ADDRESS_STRING_LEN + 1] = {0, };
+       int tmp = 0;
+
+       UAM_VALIDATE_INPUT_PARAMETER(mac);
+
+       UAM_INIT_PARAMS();
+       UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_strlcpy(str, mac, UAM_MAC_ADDRESS_STRING_LEN);
+       g_array_append_vals(in_param1, str, sizeof(str));
+
+       ret = _uam_sync_request(UAM_REQUEST_GET_DEVICE_DISCRIMINANT,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+       if (UAM_ERROR_NONE == ret)
+               tmp = g_array_index(out_param, int, 0);
+
+       *discriminant = tmp ? TRUE : FALSE;
+
+       UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       FUNC_EXIT;
+       return ret;
+}
\ No newline at end of file
index d571135..3105942 100644 (file)
@@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS devices (
   timestamp LONG,
   presence_state INTEGER,
   os_type INTEGER,
+  discriminant INTETER,
   FOREIGN KEY(user_id) REFERENCES userdata(user_id),
   PRIMARY KEY(device_id, tech_type, address)
 );
index fdd2291..31bddc2 100644 (file)
@@ -62,6 +62,7 @@ typedef struct {
        GSList *addresses;
        int presence_state;
        long timestamp;
+       gboolean discriminant;
        struct uam_db_device_info *device;
        GSList *svc_list;
 } uam_db_tech_info_t;
@@ -74,6 +75,7 @@ typedef struct uam_db_device_info {
 //     int presence_state;
 //     long timestamp;
        struct uam_db_user_info *user;
+       gboolean discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
 } uam_db_device_info_t;
 
 typedef struct uam_db_user_info {
@@ -201,6 +203,10 @@ int _uam_core_set_service_detection_cycle(const char *svc_name, unsigned int cyc
 
 int _uam_core_get_service_detection_cycle(const char *svc_name, unsigned int *cycle);
 
+int _uam_core_set_devcie_discriminant(const char *mac, gboolean discriminant);
+
+int _uam_core_get_devcie_discriminant(const char *mac, gboolean *discriminant);
+
 #ifdef __cplusplus
 }
 #endif
index c86384e..ae695a7 100644 (file)
@@ -82,7 +82,8 @@ int _ua_device_db_update_device_presence(char *device_id, int tech_type, char *a
                int presence_state);
 int _ua_device_db_update_device_ip_address(char *device_id, int tech_type, char *address,
                char *ip_address);
-
+int _ua_device_db_update_device_discriminant(char *device_id, int tech_type,
+                                         char *address, char discriminant);
 /* SERVICE QUERIES */
 
 typedef struct {
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index e286587..e545d7d
@@ -207,7 +207,10 @@ uas_device_info_t *_pm_util_uam_dev_info_to_uas_dev_info(const uam_device_info_s
        retv_if(NULL == dev, NULL);
 
        device = g_new0(uas_device_info_t, 1);
+       retv_if(NULL == device, NULL);
+
        device->os = dev->operating_system;
+       device->discriminant = dev->discriminant;
 
        if (0 < strlen(dev->mac)) {
                switch (dev->type) {
@@ -266,7 +269,10 @@ uam_device_info_s *_pm_util_uas_dev_info_to_uam_dev_info(const uas_device_info_t
        retv_if(NULL == dev, NULL);
 
        device = g_new0(uam_device_info_s, 1);
+       retv_if(NULL == device, NULL);
+
        device->operating_system = dev->os;
+       device->discriminant = dev->discriminant;
 
        g_strlcpy(device->device_id, dev->device_id, UAM_DEVICE_ID_MAX_STRING_LEN);
 
old mode 100644 (file)
new mode 100755 (executable)
index 835cf7f..1ccafb8 100644 (file)
@@ -454,6 +454,7 @@ static void __get_uam_db_dev_list_to_uam_dev_list(
                        (*device_list)[indx].operating_system = db_info->os;
                        g_strlcpy((*device_list)[indx].device_id, db_info->device_id,
                                        UAM_DEVICE_ID_MAX_STRING_LEN);
+                       (*device_list)[indx].discriminant = tech->discriminant;
                        (*device_list)[indx].last_seen = tech->timestamp;
                        (*device_list)[indx++].type = tech->tech_type;
                }
@@ -499,6 +500,7 @@ static int __copy_tech_info_to_device_info(uam_db_tech_info_t *tech, uam_device_
        g_strlcpy(device->device_id, tech->device->device_id,
                        UAM_DEVICE_ID_MAX_STRING_LEN);
        device->type = tech->tech_type;
+       device->discriminant= tech->discriminant;
 
        FUNC_EXIT;
        return UAM_ERROR_NONE;
@@ -637,6 +639,7 @@ static void __uam_core_add_dev_to_list(
        tech->presence_state = presence_state;
        tech->timestamp = timestamp;
        tech->device = device;
+       tech->discriminant = dev_info->discriminant;
 
        tech->svc_list = svc_list;
        g_slist_foreach(tech->svc_list, __print_service, tech);
@@ -1223,6 +1226,7 @@ int _uam_core_get_devcie_by_device_id(
                g_strlcpy(device->device_id, db_info->device_id,
                                UAM_DEVICE_ID_MAX_STRING_LEN);
                device->type = tech->tech_type;
+               device->discriminant = tech->discriminant;
        }
 
        retv_if(UAM_TECH_TYPE_NONE == device->type, UAM_ERROR_NOT_FOUND);
@@ -1902,6 +1906,104 @@ int _uam_core_set_detection_window(unsigned int window)
        return UAM_ERROR_NONE;
 }
 
+int _uam_core_set_devcie_discriminant(const char *mac, gboolean discriminant)
+{
+       FUNC_ENTRY;
+
+       int ret;
+       GSList *l, *l1;
+
+       uam_db_user_info_t *user;
+       uam_db_device_info_t *device;
+       uam_db_tech_info_t *tech;
+
+       uam_device_info_s dev_info;
+
+       retv_if(NULL == mac, UAM_ERROR_INVALID_PARAMETER);
+
+       /* Get tech device info by using MAC address */
+       tech = __get_tech_info_by_mac(mac);
+       retv_if(NULL == tech, UAM_ERROR_NOT_FOUND);
+       device = tech->device;
+
+       ret = __copy_tech_info_to_device_info(tech, &dev_info);
+       if (UAM_ERROR_NONE != ret) {
+               UAM_ERR("__copy_tech_info_to_device_info failed");
+               return UAM_ERROR_INTERNAL;
+       }
+
+       /* Find all tech-devices in users' devices */
+       for (l = users; NULL != l; l = g_slist_next(l)) {
+               user = l->data;
+
+               l1 = g_slist_find_custom(user->devices,
+                               dev_info.device_id, __compare_device_id);
+               if (NULL == l) {
+                       UAM_ERR("Valid user_id [%d] but Invalid device_id [%s]",
+                                       user->user_id, dev_info.device_id);
+                       continue;
+               }
+
+               device = l1->data;
+               if (!(device->supported_techs & dev_info.type)) {
+                       UAM_ERR("Valid device_id [%s] but Invalid tech type [%d]",
+                                       dev_info.device_id, dev_info.type);
+                       continue;
+               }
+
+               l1 = g_slist_find_custom(device->tech_list,
+                               &(dev_info.type), __compare_tech_type);
+               if (NULL == l) {
+                       UAM_ERR("device->tech_list, tech type [%d] not found", dev_info.type);
+                       continue;
+               }
+
+               tech = l1->data;
+               if (!tech) {
+                       UAM_ERR("Device tech, tech type  [%d] not found", dev_info.type);
+                       continue;
+               }
+               /* Set discriminant */
+               tech->discriminant = discriminant;
+
+               /* Update device's discriminant to database */
+               if (UAM_ERROR_NONE != _ua_device_db_update_device_discriminant(
+                               dev_info.device_id, dev_info.type, dev_info.mac, discriminant))
+                       UAM_WARN("_ua_device_db_update_device_discriminant failed");
+       }
+
+       FUNC_EXIT;
+       return UAM_ERROR_NONE;
+}
+
+int _uam_core_get_devcie_discriminant(const char *mac, gboolean* discriminant)
+{
+       FUNC_ENTRY;
+
+       int ret;
+       uam_db_tech_info_t *tech;
+       uam_device_info_s dev_info;
+
+       retv_if(NULL == mac, UAM_ERROR_INVALID_PARAMETER);
+
+       tech = __get_tech_info_by_mac(mac);
+       retv_if(NULL == tech, UAM_ERROR_NOT_FOUND);
+
+       ret = __copy_tech_info_to_device_info(tech, &dev_info);
+       if (UAM_ERROR_NONE != ret) {
+               UAM_ERR("__copy_tech_info_to_device_info failed");
+               return UAM_ERROR_INTERNAL;
+       }
+
+       *discriminant = dev_info.discriminant;
+
+       UAM_DBG("DeviceId [%s], Discriminant [%s]", dev_info.device_id,
+               dev_info.discriminant ? "true" : "false");
+       FUNC_EXIT;
+       return UAM_ERROR_NONE;
+
+}
+
 int _uam_core_init(void)
 {
        FUNC_ENTRY;
@@ -2994,6 +3096,7 @@ static void __get_service_dev_list(
                g_strlcpy((*device_list)[indx].device_id, db_info->device_id,
                                UAM_DEVICE_ID_MAX_STRING_LEN);
                (*device_list)[indx].last_seen = tech->timestamp;
+               (*device_list)[indx].discriminant = tech->discriminant;
                (*device_list)[indx++].type = tech->tech_type;
        }
 
index 108ea4c..cec06da 100644 (file)
@@ -36,8 +36,8 @@
 
 #define INSERT_DEVICE "insert into devices " \
        "(device_id, tech_type, address, ip_address, timestamp, " \
-       "presence_state, os_type, user_id, device_number)" \
-       "values (?, ?, ?, ?, ?, ?, ?, ?, ?)"
+       "presence_state, os_type, user_id, discriminant, device_number)" \
+       "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
 
 #define UPDATE_TIMESTAMP "UPDATE devices " \
        "SET timestamp = ? WHERE device_id = ? AND tech_type = ? AND address = ?"
@@ -45,6 +45,8 @@
        "SET presence_state = ? WHERE device_id = ? AND tech_type = ? AND address = ?"
 #define UPDATE_IP_ADDRESS "UPDATE devices " \
        "SET ip_address = ? WHERE device_id = ? AND tech_type = ? AND address = ?"
+#define UPDATE_DISCRIMINANT "UPDATE devices " \
+       "SET discriminant = ? WHERE device_id = ? AND tech_type = ? AND address = ?"
 
 #define DELETE_ALL_DEVICES "delete from devices "
 
@@ -145,6 +147,7 @@ static sqlite3_stmt *select_max_device_number;
 static sqlite3_stmt *update_timestamp;
 static sqlite3_stmt *update_presence;
 static sqlite3_stmt *update_ip_address;
+static sqlite3_stmt *update_discriminant;
 
 /* INSERT statements */
 static sqlite3_stmt *insert_device_info;
@@ -258,6 +261,7 @@ static int __ua_device_prepare_update(sqlite3 *db)
        PREPARE_UPDATE(update_timestamp, UPDATE_TIMESTAMP);
        PREPARE_UPDATE(update_presence, UPDATE_PRESENCE);
        PREPARE_UPDATE(update_ip_address, UPDATE_IP_ADDRESS);
+       PREPARE_UPDATE(update_discriminant, UPDATE_DISCRIMINANT);
 
        initialized = 1;
        FUNC_EXIT;
@@ -342,6 +346,7 @@ static void _ua_device_finalize_update(void)
        FINALIZE(update_timestamp);
        FINALIZE(update_presence);
        FINALIZE(update_ip_address);
+       FINALIZE(update_discriminant);
 
        FUNC_EXIT;
 }
@@ -513,6 +518,35 @@ handle_error:
        return error_code;
 }
 
+int _ua_device_db_update_device_discriminant(char *device_id, int tech_type,
+                                         char *address, char discriminant)
+{
+       int error_code = UAM_ERROR_NONE;
+       sqlite3_stmt *stmt = update_discriminant;
+
+       retv_if(NULL == device_id, UAM_ERROR_INVALID_PARAMETER);
+       retv_if(NULL == address, UAM_ERROR_INVALID_PARAMETER);
+
+       DB_ACTION(sqlite3_bind_int(stmt, 1, discriminant));
+       DB_ACTION(sqlite3_bind_text(stmt, 2, device_id, -1, SQLITE_TRANSIENT));
+       DB_ACTION(sqlite3_bind_int(stmt, 3, tech_type));
+       DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT));
+
+       if (sqlite3_step(stmt) != SQLITE_DONE) {
+               UAM_ERR("Failed to update device discriminant: %s",
+                        sqlite3_errmsg(__ua_device_db_get_database()));
+
+               error_code = UAM_ERROR_DB_FAILED;
+               goto handle_error;
+       }
+
+       UAM_DBG("Device discriminant updated [%s]", discriminant ? "true" : "false");
+
+handle_error:
+       sqlite3_reset(stmt);
+       return error_code;
+}
+
 int _ua_device_db_insert_device_info(int user_id, const uam_device_info_s *dev_info,
                                     int presence_state, long timestamp)
 {
@@ -522,9 +556,10 @@ int _ua_device_db_insert_device_info(int user_id, const uam_device_info_s *dev_i
 
        retv_if(NULL == dev_info, UAM_ERROR_INVALID_PARAMETER);
 
-       UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d", dev_info->device_id,
+       UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d", dev_info->device_id,
                        dev_info->type, dev_info->mac, dev_info->ipv4_addr,
-                       timestamp, presence_state, dev_info->operating_system, user_id);
+                       timestamp, presence_state, dev_info->operating_system, dev_info->discriminant,
+                       user_id);
 
        DB_ACTION(sqlite3_bind_text(stmt, 1, dev_info->device_id, -1, SQLITE_TRANSIENT));
        DB_ACTION(sqlite3_bind_int(stmt, 2, dev_info->type));
@@ -533,8 +568,9 @@ int _ua_device_db_insert_device_info(int user_id, const uam_device_info_s *dev_i
        DB_ACTION(sqlite3_bind_int64(stmt, 5, timestamp));
        DB_ACTION(sqlite3_bind_int(stmt, 6, presence_state));
        DB_ACTION(sqlite3_bind_int(stmt, 7, dev_info->operating_system));
-       DB_ACTION(sqlite3_bind_int(stmt, 8, user_id));
-       DB_ACTION(sqlite3_bind_int(stmt, 9, max_device_number + 1));
+       DB_ACTION(sqlite3_bind_int(stmt, 9, user_id));
+       DB_ACTION(sqlite3_bind_int(stmt, 10, dev_info->discriminant));
+       DB_ACTION(sqlite3_bind_int(stmt, 11, max_device_number + 1));
 
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to insert device info: %s",
index bf0c99d..f531bf2 100644 (file)
@@ -599,6 +599,34 @@ static int __uam_manager_sync_request_handler(
                }
                break;
        }
+       case UAM_REQUEST_SET_DEVICE_DISCRIMINANT: {
+               const char *mac;
+               gboolean discriminant = FALSE;
+               int tmp = 0;
+
+               mac = (char *)g_variant_get_data(in_param1);
+               __uam_manager_copy_params(in_param2, &tmp, sizeof(int));
+               discriminant = tmp ? TRUE : FALSE;
+               UAM_DBG("mac: [%s] discriminant: [%s]", mac, discriminant ? "true" : "false");
+
+               result = _uam_core_set_devcie_discriminant(mac, discriminant);
+               break;
+       }
+       case UAM_REQUEST_GET_DEVICE_DISCRIMINANT: {
+               const char *mac;
+               gboolean discriminant;
+               int tmp = 0;
+
+               mac = (char *)g_variant_get_data(in_param1);
+
+               result = _uam_core_get_devcie_discriminant(mac, &discriminant);
+               if (UAM_ERROR_NONE == result)
+                       UAM_DBG("mac: [%s] discriminant: [%s]", mac, discriminant ? "true" : "false");
+
+               tmp = discriminant ? 1 : 0;
+               g_array_append_vals(*out_param1, &tmp, sizeof(int));
+               break;
+       }
        default:
                UAM_WARN("UnSupported function [%s(0x%4.4X)]",
                                _uam_manager_request_to_str(function), function);
@@ -679,9 +707,10 @@ static int __uam_manager_async_request_handler(
                account = (char *)g_variant_get_data(in_param1);
                __uam_manager_copy_params(in_param2,
                                &dev_info, sizeof(uam_device_info_s));
-               UAM_DBG("Account: [%s], Type: %d, MAC: [%s] IP: [%s], ID: [%s]",
+               UAM_DBG("Account: [%s], Type: %d, MAC: [%s] IP: [%s], ID: [%s], Discriminant: [%s]",
                                account, dev_info.type, dev_info.mac,
-                               dev_info.ipv4_addr, dev_info.device_id);
+                               dev_info.ipv4_addr, dev_info.device_id,
+                               dev_info.discriminant ? "true" : "false");
 
                result = _uam_core_add_device(account, &dev_info);
                if (UAM_ERROR_NONE == result) {
@@ -747,6 +776,8 @@ static gboolean __uam_manager_is_sync_function(int function)
        case UAM_REQUEST_GET_SERVICE_DEVICES:
        case UAM_REQUEST_GET_SERVICE_USERS:
        case UAM_REQUEST_GET_SERVICES:
+       case UAM_REQUEST_SET_DEVICE_DISCRIMINANT:
+       case UAM_REQUEST_GET_DEVICE_DISCRIMINANT:
                return TRUE;
        default:
                return FALSE;
index a723d67..e549763 100644 (file)
@@ -107,6 +107,7 @@ typedef struct {
        int os;
        int num_addr;
        uas_address_info_t *addr_list;
+       char discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
 } uas_device_info_t;
 
 /* Active scan event types */