#define UAM_MAX_USERS 255
#define USER_ACCOUNT_DEFAULT "default@default.com"
#define USER_NAME_DEFAULT "default"
+#define USER_ACCOUNT_DEFAULT_ID 1
typedef struct {
char *name;
FUNC_EXIT;
}
-static void __send_device_event(int event, const uam_device_info_s *dev_info)
+static void __send_device_event(int err, int event, const uam_device_info_s *dev_info)
{
FUNC_ENTRY;
GVariant *param;
UAM_INFO_C("Send %s to applications", _uam_manager_event_to_str(event));
/* Send device event to application */
param = g_variant_new("(iiisss)",
- UAM_ERROR_NONE,
+ err,
dev_info->operating_system,
dev_info->type,
dev_info->mac,
_uam_manager_error_to_str(ret));
/* Send device removed event to application */
- __send_device_event(UAM_EVENT_DEVICE_REMOVED, &dev_info);
+ __send_device_event(UAM_ERROR_NONE, UAM_EVENT_DEVICE_REMOVED, &dev_info);
/* Remove device from database */
if (UAM_ERROR_NONE != _uam_device_db_delete_device_info(
}
/* Send device removed event to application */
- __send_device_event(UAM_EVENT_DEVICE_REMOVED, dev_info);
+ __send_device_event(ret, UAM_EVENT_DEVICE_REMOVED, dev_info);
/* Remove device from database */
if (UAM_ERROR_NONE != _uam_device_db_delete_device_info(
{
FUNC_ENTRY;
GSList *l;
- uam_db_user_info_t *user = NULL;
int ret = UAM_ERROR_NONE;
+ uam_db_user_info_t *user = NULL;
+ GSList *svc_list = NULL;
+ long long timestamp;
/* Send reply over dbus for add device API */
l = _uam_manager_get_request_list();
break;
}
- if (UAM_ERROR_NONE == status) {
- GSList *svc_list = NULL;
- long long timestamp;
-
- if (0 > user_id) {
-
- l = g_slist_find_custom(users,
- USER_ACCOUNT_DEFAULT, __compare_user_account);
- if (NULL == l) {
- ret = _uam_core_add_user(
- USER_ACCOUNT_DEFAULT, USER_NAME_DEFAULT);
- if (UAM_ERROR_NONE != ret) {
- UAM_ERR("_uam_core_add_user failed with %s",
- _uam_manager_error_to_str(ret));
- return ret;
- }
- }
- l = g_slist_find_custom(users, USER_ACCOUNT_DEFAULT, __compare_user_account);
- if (!l) {
- UAM_ERR("_uam_core_add_user failed because user is null");
- ret = UAM_ERROR_NOT_FOUND;
- return ret;
- }
+ if (UAM_ERROR_NONE != status) {
+ __send_device_event(status, UAM_EVENT_DEVICE_ADDED, dev_info);
+ return status;
+ }
- user = l->data;
- user_id = user->user_id;
- } else {
- l = g_slist_find_custom(users, &user_id, __compare_user_id);
- if (NULL == l) {
- UAM_ERR("Invalid user Id: %d", user_id);
- ret = UAM_ERROR_NOT_FOUND;
+ if (0 > user_id) {
+ l = g_slist_find_custom(users,
+ USER_ACCOUNT_DEFAULT, __compare_user_account);
+ if (NULL == l) {
+ ret = _uam_core_add_user(
+ USER_ACCOUNT_DEFAULT, USER_NAME_DEFAULT);
+ if (UAM_ERROR_NONE != ret) {
+ UAM_ERR("_uam_core_add_user failed with %s",
+ _uam_manager_error_to_str(ret));
+ __send_device_event(ret, UAM_EVENT_DEVICE_ADDED, dev_info);
return ret;
}
- user = l->data;
}
+ user_id = USER_ACCOUNT_DEFAULT_ID;
+ }
+ l = g_slist_find_custom(users, &user_id, __compare_user_id);
+ if (NULL == l) {
+ UAM_ERR("Invalid user Id: %d", user_id);
+ ret = UAM_ERROR_NOT_FOUND;
+ __send_device_event(ret, UAM_EVENT_DEVICE_ADDED, dev_info);
+ return ret;
+ }
+ user = l->data;
- /* Get default service and add it to device's service list by default */
- l = g_slist_find_custom(services, UAM_SERVICE_DEFAULT, __compare_svc_name);
- if (!l) {
- uam_db_service_info_t *service = g_new0(uam_db_service_info_t, 1);
- service->name = g_strdup(UAM_SERVICE_DEFAULT);
- service->cycle = UAM_DETECTION_CYCLE_DEFAULT;
- services = g_slist_append(services, service);
- svc_list = g_slist_append(svc_list, service);
- } else {
- uam_db_service_info_t *service = l->data;
- svc_list = g_slist_append(svc_list, service);
- }
+ /* Get default service and add it to device's service list by default */
+ l = g_slist_find_custom(services, UAM_SERVICE_DEFAULT, __compare_svc_name);
+ if (!l) {
+ uam_db_service_info_t *service = g_new0(uam_db_service_info_t, 1);
+ service->name = g_strdup(UAM_SERVICE_DEFAULT);
+ service->cycle = UAM_DETECTION_CYCLE_DEFAULT;
+ services = g_slist_append(services, service);
+ svc_list = g_slist_append(svc_list, service);
+ } else {
+ uam_db_service_info_t *service = l->data;
+ svc_list = g_slist_append(svc_list, service);
+ }
- timestamp = time(NULL);
- __uam_core_add_dev_to_list(user, dev_info,
- UAM_PRESENCE_STATE_PRESENT, timestamp, svc_list);
+ timestamp = time(NULL);
+ __uam_core_add_dev_to_list(user, dev_info,
+ UAM_PRESENCE_STATE_PRESENT, timestamp, svc_list);
- /* Add device to database */
- ret = _uam_device_db_insert_device_info(user->user_id,
- dev_info, UAM_PRESENCE_STATE_PRESENT, timestamp);
- if (UAM_ERROR_NONE != ret) {
- UAM_WARN("Device addition to persistent DB failed");
- return ret;
- }
+ /* Add device to database */
+ ret = _uam_device_db_insert_device_info(user->user_id,
+ dev_info, UAM_PRESENCE_STATE_PRESENT, timestamp);
+ if (UAM_ERROR_NONE != ret) {
+ UAM_WARN("Device addition to persistent DB failed");
+ return ret;
+ }
- /* Insert device service info to db */
- ret = _uam_db_insert_device_service_info(
- dev_info->device_id, dev_info->type, dev_info->mac,
- UAM_SERVICE_DEFAULT, UAM_DETECTION_CYCLE_DEFAULT,
- dev_info->discriminant);
- if (UAM_ERROR_NONE != ret) {
- UAM_WARN("Device service addition to persistent DB failed");
- return ret;
- }
+ /* Insert device service info to db */
+ ret = _uam_db_insert_device_service_info(
+ dev_info->device_id, dev_info->type, dev_info->mac,
+ UAM_SERVICE_DEFAULT, UAM_DETECTION_CYCLE_DEFAULT,
+ dev_info->discriminant);
+ if (UAM_ERROR_NONE != ret) {
+ UAM_WARN("Device service addition to persistent DB failed");
+ __send_device_event(ret, UAM_EVENT_DEVICE_ADDED, dev_info);
+ return ret;
+ }
- ret = _uam_core_update_svc_dev_info(
- dev_info->device_id, dev_info->type,
- UAM_SERVICE_DEFAULT, dev_info->discriminant);
- if (UAM_ERROR_NONE != ret) {
- UAM_WARN("Device service mappiing update failed");
- return ret;
- }
+ ret = _uam_core_update_svc_dev_info(
+ dev_info->device_id, dev_info->type,
+ UAM_SERVICE_DEFAULT, dev_info->discriminant);
+ if (UAM_ERROR_NONE != ret) {
+ UAM_WARN("Device service mappiing update failed");
+ __send_device_event(ret, UAM_EVENT_DEVICE_ADDED, dev_info);
+ return ret;
+ }
- /* Send device added event to application */
- __send_device_event(UAM_EVENT_DEVICE_ADDED, dev_info);
+ /* Send device added event to application */
+ __send_device_event(ret, UAM_EVENT_DEVICE_ADDED, dev_info);
- /* 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");
- return 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");
+ return ret;
}
_uam_cloud_send_device_added(status, (user ? user->account : NULL), dev_info);