*/
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
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) \
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
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
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
uam_device_info_s dev_info;
int presence_state;
long timestamp;
- int discriminant;
} db_device_info_t;
/* db init/deinit */
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 {
(*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)) {
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 */
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 */
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 */
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;
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,
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);
+ }
}
}
#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 "
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;
FINALIZE(update_timestamp);
FINALIZE(update_presence);
FINALIZE(update_ip_address);
- FINALIZE(update_discriminant);
+ FINALIZE(update_device);
FUNC_EXIT;
}
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;
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) {
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,
info->presence_state,
info->dev_info.operating_system,
info->user_id,
- info->discriminant);
+ info->dev_info.discriminant);
}
handle_error:
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,
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;
__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,
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;
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:
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 */