Implemented ua_udpate_device API 82/211482/1
authorsaerome.kim <saerome.kim@samsung.com>
Mon, 5 Aug 2019 10:53:15 +0000 (19:53 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Tue, 6 Aug 2019 01:08:06 +0000 (10:08 +0900)
Implemented discriminant functionality

Change-Id: Id85aeedebd5323e6539a09a29297805b6fe30ebf
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
include/ua-api.h
include/ua-internal.h
packaging/ua-manager.spec
ua-api/src/ua-api.c
ua-daemon/include/ua-manager-core.h
ua-daemon/include/ua-manager-database.h
ua-daemon/src/pm/ua-pm-util.c [changed mode: 0755->0644]
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 6df8461..92fa95a 100644 (file)
@@ -1187,6 +1187,23 @@ int _uam_get_service_detection_cycle(const char *service, unsigned int *cycle);
  */
 int _uam_db_reset(void);
 
+/**
+ * @brief Updates the device.
+ * @since_tizen 5.5
+ *
+ * @param[in] dev_info Device information.
+ *
+ * @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_update_device(uam_device_info_s *device);
+
 #ifdef __cplusplus
 }
 #endif
index 372258c..06a0d5f 100644 (file)
@@ -44,6 +44,7 @@ extern "C" {
        REQUEST(UAM_REQUEST_GET_USERS) \
        REQUEST(UAM_REQUEST_ADD_DEVICE) \
        REQUEST(UAM_REQUEST_DELETE_DEVICE) \
+       REQUEST(UAM_REQUEST_UPDATE_DEVICE) \
        REQUEST(UAM_REQUEST_DELETE_DEVICE_BY_DEVICE_ID) \
        REQUEST(UAM_REQUEST_DELETE_DEVICE_BY_MAC) \
        REQUEST(UAM_REQUEST_GET_DEVICE_BY_DEVICE_ID) \
index ab3167e..100fd57 100644 (file)
@@ -1,6 +1,6 @@
 Name:       ua-manager
 Summary:    User awareness manager
-Version:    0.0.2
+Version:    0.6.0
 Release:    1
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index 652637f..57e1332 100644 (file)
@@ -1267,3 +1267,23 @@ UAM_EXPORT_API int _uam_request_get_service_users(char *svc_name,
        FUNC_EXIT;
        return ret;
 }
+
+UAM_EXPORT_API int _uam_request_update_device(uam_device_info_s *device)
+{
+       FUNC_ENTRY;
+       int ret;
+
+       UAM_VALIDATE_INPUT_PARAMETER(device);
+
+       UAM_INIT_PARAMS();
+       UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, device, sizeof(uam_device_info_s));
+       ret = _uam_sync_request(UAM_REQUEST_UPDATE_DEVICE,
+                       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;
+}
\ No newline at end of file
index b7d0af8..8ad7473 100644 (file)
@@ -203,6 +203,8 @@ 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_update_device(const uam_device_info_s *a_device);
+
 #ifdef __cplusplus
 }
 #endif
index fb5f3cd..1464854 100644 (file)
@@ -98,7 +98,6 @@ typedef struct {
        uam_device_info_s dev_info;
        int presence_state;
        long timestamp;
-       int discriminant;
 } db_device_info_t;
 
 /* db init/deinit */
@@ -128,8 +127,8 @@ int _ua_device_db_update_device_presence(
        char *device_id, int tech_type, char *address, 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);
+int _ua_device_db_update_device_device(char *device_id, int tech_type,
+       char *address, char *ip, char os_type, char discriminant);
 /* SERVICE QUERIES */
 
 typedef struct {
old mode 100755 (executable)
new mode 100644 (file)
index e545d7d..426a676
@@ -167,6 +167,7 @@ void _pm_util_uam_db_dev_to_uas_dev(unsigned int tech_type,
 
        (*device)->user_id = dev->user->user_id;
        (*device)->os = dev->os;
+       (*device)->discriminant = dev->discriminant;
        (*device)->device_id = g_strdup(dev->device_id);
 
        for (l = dev->tech_list; NULL != l; l = g_slist_next(l)) {
index 702c586..95a2373 100644 (file)
@@ -625,6 +625,7 @@ static void __uam_core_add_dev_to_list(
                device = g_new0(uam_db_device_info_t, 1);
                device->device_id = g_strdup(dev_info->device_id);
                device->os = dev_info->operating_system;
+               device->discriminant = dev_info->discriminant;
                device->user = user;
 
                /* Add device to global device list */
@@ -973,9 +974,8 @@ int _uam_core_remove_device_by_device_id(const char *device_id, int tech_type)
 
        ret = _uam_pm_unregister_device(device->user->user_id, &dev_info);
        if (UAM_ERROR_NONE != ret) {
-               UAM_ERR("_uam_pm_unregister_device failed with %s",
+               UAM_WARN("_uam_pm_unregister_device failed with %s",
                                _uam_manager_error_to_str(ret));
-               return ret;
        }
 
        /* Send device removed event to application */
@@ -1045,9 +1045,8 @@ int _uam_core_remove_device_by_mac(const char *mac)
 
        ret = _uam_pm_unregister_device(device->user->user_id, &dev_info);
        if (UAM_ERROR_NONE != ret) {
-               UAM_ERR("_uam_pm_unregister_device failed with %s",
-                               _uam_manager_error_to_str(ret));
-               return ret;
+               UAM_WARN("_uam_pm_unregister_device failed with %s",
+                       _uam_manager_error_to_str(ret));
        }
 
        /* Send device removed event to application */
@@ -1093,6 +1092,78 @@ int _uam_core_remove_device_by_mac(const char *mac)
        return UAM_ERROR_NONE;
 }
 
+int _uam_core_update_device(const uam_device_info_s *a_device)
+{
+       FUNC_ENTRY;
+
+       int ret;
+       GSList *l, *l1, *l2;
+
+       uam_device_info_s temp;
+       uam_db_user_info_t *user = NULL;
+       uam_db_device_info_t *device = NULL;
+       uam_db_tech_info_t *tech = NULL;
+
+       /* 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,
+                               a_device->device_id, __compare_device_id);
+               if (NULL == l1) {
+                       UAM_DBG("Valid user_id [%d] but Invalid device_id [%s]",
+                                       user->user_id, a_device->device_id);
+                       continue;
+               }
+
+               device = l1->data;
+               if (!(device->supported_techs & a_device->type)) {
+                       UAM_DBG("Valid device_id [%s] but Invalid tech type [%d]",
+                                       device->device_id, a_device->type);
+                       continue;
+               }
+
+               /* Update discriminant for devices */
+               device->discriminant = a_device->discriminant;
+               device->os = a_device->operating_system;
+
+               l2 = g_slist_find_custom(device->tech_list,
+                               &(a_device->type), __compare_tech_type);
+               if (NULL == l2) {
+                       UAM_DBG("device->tech_list, tech type [%d] not found", a_device->type);
+                       continue;
+               }
+
+               tech = l2->data;
+               if (!tech) {
+                       UAM_DBG("Device tech, tech type  [%d] not found", tech->tech_type);
+                       continue;
+               }
+
+               /* Update discriminant for device-tech */
+               tech->discriminant = a_device->discriminant;
+
+               /* Update device's discriminant to database */
+               __copy_tech_info_to_device_info(tech, &temp);
+
+               ret = _ua_device_db_update_device_device(temp.device_id, temp.type,
+                               temp.mac, temp.ipv4_addr, temp.operating_system, temp.discriminant);
+               if (UAM_ERROR_NONE != ret)
+                       UAM_WARN("_ua_device_db_update_device_device failed [%d]", ret);
+       }
+
+       /* Set/update registered device list to plugins */
+       ret = _uam_pm_set_registered_devices(devices);
+       if (UAM_ERROR_NONE != ret)
+               UAM_ERR("_uam_pm_set_registered_devices failed [%d]", ret);
+
+       /* Set/update registered device list to cloud plugin */
+       _uam_cloud_update_registered_devices();
+
+       FUNC_EXIT;
+       return UAM_ERROR_NONE;
+}
+
 int _uam_core_get_default_user(uam_user_info_s *user_info)
 {
        FUNC_ENTRY;
@@ -2231,6 +2302,7 @@ void __send_user_presence_event(uam_db_tech_info_t *tech, unsigned int sensor)
                                continue;
 
                        user->timestamp = (long) time(NULL);
+                       UAM_INFO("sensor [%d]", sensor);
                        _uam_manager_send_event(mon->name,
                                        UAM_EVENT_USER_PRESENCE_DETECTED,
                                        g_variant_new("(ussx)", sensor,
@@ -2377,27 +2449,41 @@ static void __send_user_absence_event(uam_tech_type_e type, unsigned int sensor)
                for (l1 = svc->dev_techs; NULL != l1; l1 = g_slist_next(l1)) {
                        uam_db_tech_info_t *tech = l1->data;
 
-                       if (!tech || (tech->tech_type != type))
+                       if (!tech || (tech->tech_type != type)) {
+                               UAM_WARN("tech is NULL or tech->tech_type [%d] != type [%d]",
+                                       tech->tech_type, type);
                                continue;
+                       }
 
-                       if (!tech->device || !tech->device->user)
+                       if (!tech->device || !tech->device->user) {
+                               UAM_WARN("tech->device is NULL or tech->device->user is NULL");
                                continue;
+                       }
 
                        l2 = g_slist_find_custom(present_users,
                                        &(tech->device->user->user_id), __compare_user_id);
-                       if (UAM_PRESENCE_STATE_PRESENT == tech->presence_state) {
+
+                       if (UAM_PRESENCE_STATE_PRESENT == tech->presence_state && tech->discriminant) {
+                               UAM_DBG("tech->discriminant [%d] device_id [%s] account [%s]",
+                                       tech->discriminant,
+                                       tech->device->device_id,
+                                       tech->device->user->account);
                                /* Remove user from absent list */
                                absent_users = g_slist_remove(absent_users, tech->device->user);
 
                                /* If user not in present list, add user to the list */
-                               if (!l2)
+                               if (!l2) {
+                                       UAM_DBG("added present user [%s]", tech->device->user->account);
                                        present_users = g_slist_prepend(present_users, tech->device->user);
+                               }
                        } else {
                                /* If user not in the present list then only add it to absent list */
                                if ((NULL == l2) && (NULL == g_slist_find_custom(
                                                                absent_users, &(tech->device->user->user_id),
-                                                               __compare_user_id)))
-                               absent_users = g_slist_prepend(absent_users, tech->device->user);
+                                                               __compare_user_id))) {
+                                       UAM_DBG("added absent user [%s]", tech->device->user->account);
+                                       absent_users = g_slist_prepend(absent_users, tech->device->user);
+                               }
                        }
                }
 
index 9fc1817..d5ac744 100644 (file)
@@ -52,8 +52,9 @@
 #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 UPDATE_DEVICE "UPDATE devices " \
+       "SET (os_type, discriminant, ip_address) = (?, ?, ?) " \
+       "WHERE device_id = ? AND tech_type = ? AND address = ?"
 
 #define DELETE_ALL_DEVICES "delete from devices "
 
@@ -76,7 +77,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;
+static sqlite3_stmt *update_device;
 
 /* INSERT statements */
 static sqlite3_stmt *insert_device_info;
@@ -122,7 +123,7 @@ static void __ua_device_finalize_update(void)
        FINALIZE(update_timestamp);
        FINALIZE(update_presence);
        FINALIZE(update_ip_address);
-       FINALIZE(update_discriminant);
+       FINALIZE(update_device);
 
        FUNC_EXIT;
 }
@@ -190,8 +191,8 @@ static int __ua_device_prepare_update(sqlite3 *db)
                UPDATE_PRESENCE, __ua_device_finalize_update);
        PREPARE_QUERY(rc, db, update_ip_address,
                UPDATE_IP_ADDRESS, __ua_device_finalize_update);
-       PREPARE_QUERY(rc, db, update_discriminant,
-               UPDATE_DISCRIMINANT, __ua_device_finalize_update);
+       PREPARE_QUERY(rc, db, update_device,
+               UPDATE_DEVICE, __ua_device_finalize_update);
 
        initialized = 1;
        FUNC_EXIT;
@@ -416,22 +417,26 @@ handle_error:
        return error_code;
 }
 
-int _ua_device_db_update_device_discriminant(char *device_id, int tech_type,
-                                         char *address, char discriminant)
+int _ua_device_db_update_device_device(char *device_id, int tech_type,
+       char *address, char *ip, char os_type, char discriminant)
 {
        int error_code = UAM_ERROR_NONE;
-       sqlite3_stmt *stmt = update_discriminant;
+       sqlite3_stmt *stmt = update_device;
 
        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_int(stmt, 1, os_type),
                error_code, handle_error);
-       DB_ACTION(sqlite3_bind_text(stmt, 2, device_id, -1, SQLITE_TRANSIENT),
+       DB_ACTION(sqlite3_bind_int(stmt, 2, discriminant),
                error_code, handle_error);
-       DB_ACTION(sqlite3_bind_int(stmt, 3, tech_type),
+       DB_ACTION(sqlite3_bind_text(stmt, 3, ip, -1, SQLITE_TRANSIENT),
                error_code, handle_error);
-       DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT),
+       DB_ACTION(sqlite3_bind_text(stmt, 4, device_id, -1, SQLITE_TRANSIENT),
+               error_code, handle_error);
+       DB_ACTION(sqlite3_bind_int(stmt, 5, tech_type),
+               error_code, handle_error);
+       DB_ACTION(sqlite3_bind_text(stmt, 6, address, -1, SQLITE_TRANSIENT),
                error_code, handle_error);
 
        if (sqlite3_step(stmt) != SQLITE_DONE) {
@@ -566,7 +571,7 @@ int _ua_device_db_get_device(char *device_id, int tech_type, char *address,
                info->presence_state = sqlite3_column_int(stmt, 5);
                info->dev_info.operating_system = sqlite3_column_int(stmt, 6);
                info->user_id = sqlite3_column_int(stmt, 7);
-               info->discriminant = sqlite3_column_int(stmt, 8);
+               info->dev_info.discriminant = sqlite3_column_int(stmt, 8);
 
                UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d",
                        info->dev_info.device_id,
@@ -577,7 +582,7 @@ int _ua_device_db_get_device(char *device_id, int tech_type, char *address,
                        info->presence_state,
                        info->dev_info.operating_system,
                        info->user_id,
-                       info->discriminant);
+                       info->dev_info.discriminant);
        }
 
 handle_error:
@@ -657,7 +662,7 @@ GSList *_ua_device_db_get_all_devices(void)
                        info->presence_state = sqlite3_column_int(stmt, 5);
                        info->dev_info.operating_system = sqlite3_column_int(stmt, 6);
                        info->user_id = sqlite3_column_int(stmt, 7);
-                       info->discriminant = sqlite3_column_int(stmt, 8);
+                       info->dev_info.discriminant = sqlite3_column_int(stmt, 8);
 
                        UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d",
                                info->dev_info.device_id,
@@ -668,7 +673,7 @@ GSList *_ua_device_db_get_all_devices(void)
                                info->presence_state,
                                info->dev_info.operating_system,
                                info->user_id,
-                               info->discriminant);
+                               info->dev_info.discriminant);
 
                        device_list = g_slist_append(device_list, info);
                        break;
index 3b14100..827551f 100644 (file)
@@ -204,8 +204,9 @@ static int __uam_manager_sync_request_handler(
 
                __uam_manager_copy_params(in_param1,
                                &dev_info, sizeof(uam_device_info_s));
-               UAM_DBG("DeviceId: [%s], Type: %d, MAC: [%s]",
-                               dev_info.device_id, dev_info.type, dev_info.mac);
+               UAM_DBG("DeviceId: [%s], Type: %d, MAC: [%s], discriminant: [%s]",
+                               dev_info.device_id, dev_info.type, dev_info.mac,
+                               dev_info.discriminant ? "True" : "False");
 
                result = _uam_core_is_device_added(&dev_info, &is_added);
                g_array_append_vals(*out_param1,
@@ -225,6 +226,18 @@ static int __uam_manager_sync_request_handler(
                result = _uam_core_remove_device(account, &dev_info);
                break;
        }
+       case UAM_REQUEST_UPDATE_DEVICE: {
+               uam_device_info_s dev_info;
+
+               __uam_manager_copy_params(in_param1,
+                               &dev_info, sizeof(uam_device_info_s));
+               UAM_DBG("Device ID: [%s], Type: %d, MAC: [%s], discriminant: [%s]",
+                               dev_info.device_id, dev_info.type, dev_info.mac,
+                               dev_info.discriminant ? "True" : "False");
+
+               result = _uam_core_update_device(&dev_info);
+               break;
+       }
        case UAM_REQUEST_DELETE_DEVICE_BY_DEVICE_ID: {
                const char *device_id;
                int tech_type;
@@ -717,6 +730,7 @@ static gboolean __uam_manager_is_sync_function(int function)
        case UAM_REQUEST_GET_USERS:
        case UAM_REQUEST_IS_DEVICE_ADDED:
        case UAM_REQUEST_DELETE_DEVICE:
+       case UAM_REQUEST_UPDATE_DEVICE:
        case UAM_REQUEST_DELETE_DEVICE_BY_DEVICE_ID:
        case UAM_REQUEST_DELETE_DEVICE_BY_MAC:
        case UAM_REQUEST_GET_DEVICE_BY_DEVICE_ID:
index e549763..65a89ee 100644 (file)
@@ -107,7 +107,7 @@ typedef struct {
        int os;
        int num_addr;
        uas_address_info_t *addr_list;
-       char discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
+       int discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
 } uas_device_info_t;
 
 /* Active scan event types */