return NULL;
}
-static void __remove_user_device(gpointer data)
+static int _uam_remove_user_device(uam_db_device_info_t *device)
{
FUNC_ENTRY;
- uam_db_device_info_t *device = data;
uam_device_info_s dev_info;
int user_id;
GSList *l;
+ int ret = UAM_ERROR_NONE;
- ret_if(NULL == device);
-
+ retv_if(NULL == device, UAM_ERROR_INVALID_PARAMETER);
user_id = device->user->user_id;
dev_info.operating_system = device->os;
g_strlcpy(dev_info.device_id, device->device_id, UAM_DEVICE_ID_MAX_STRING_LEN);
- ret_if(UAM_ERROR_NONE != __uam_db_begin_transaction());
+ retv_if(UAM_ERROR_NONE != __uam_db_begin_transaction(), UAM_ERROR_DB_FAILED);
for (l = device->tech_list; NULL != l; l = g_slist_next(l)) {
uam_db_tech_info_t *tech = l->data;
GSList *l1, *l2;
- int ret;
if (!tech)
continue;
__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(
- dev_info.device_id, dev_info.type, dev_info.mac)) {
+ ret = _uam_device_db_delete_device_info(
+ dev_info.device_id, dev_info.type, dev_info.mac);
+ if (UAM_ERROR_NONE != ret) {
UAM_ERR("_uam_device_db_delete_device_info failed");
__uam_db_end_transaction(0);
- return;
+ return ret;
}
}
__uam_db_end_transaction(1);
- __free_user_device(device);
-
FUNC_EXIT;
+ return ret;
}
-static void __free_uam_db_user_info(gpointer data)
+static int __free_uam_db_user_info(gpointer data)
{
FUNC_ENTRY;
uam_db_user_info_t *user = data;
+ GSList *l;
+ int ret = UAM_ERROR_NONE;
- g_slist_free_full(user->devices, __remove_user_device);
+ for (l = user->devices; NULL != l; l = g_slist_next(l)) {
+ uam_db_device_info_t *device = l->data;
+ ret = _uam_remove_user_device(device);
+ if (UAM_ERROR_NONE != ret) {
+ UAM_ERR("_uam_remove_user_device failed");
+ return ret;
+ }
+ }
+
+ g_slist_free_full(user->devices, __free_user_device);
/* Set/update registered device list to plugins */
if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices))
g_free(user->name);
g_free(user->account);
g_free(user);
+
FUNC_EXIT;
+ return ret;
}
static gint __compare_device_id(gconstpointer data, gconstpointer user_data)
FUNC_ENTRY;
GSList *l;
uam_db_user_info_t *user;
+ int ret = UAM_ERROR_NONE;
l = g_slist_find_custom(users, account, __compare_user_account);
retv_if((NULL == l), UAM_ERROR_NOT_REGISTERED);
user = l->data;
/* Remove user from database */
- if (UAM_ERROR_NONE != _uam_db_delete_by_user_id(user->user_id)) {
+ ret = _uam_db_delete_by_user_id(user->user_id);
+ if (UAM_ERROR_NONE != ret) {
UAM_ERR("_uam_db_delete_by_user_id failed");
- return UAM_ERROR_DB_FAILED;
+ return ret;
}
users = g_slist_remove(users, user);
UAM_ERROR_NONE, user->account, user->name)))
UAM_ERR("Failed to send UAM_EVENT_USER_REMOVED");
- __free_uam_db_user_info((gpointer)user);
+ ret = __free_uam_db_user_info((gpointer)user);
+ if (UAM_ERROR_NONE != ret) {
+ UAM_WARN("_free_uam_db_user_info failed");
+ }
FUNC_EXIT;
return UAM_ERROR_NONE;
FUNC_EXIT;
}
-void _uam_core_handle_presence_detected(unsigned int sensor,
+int _uam_core_handle_presence_detected(unsigned int sensor,
int user_id, void *info)
{
FUNC_ENTRY;
GSList *l;
uam_device_info_s *dev_info = NULL;
uam_sensor_info_s *sensor_info = NULL;
+ int ret = UAM_ERROR_NONE;
UAM_INFO("sensor: 0x%8.8X, user_id: %d", sensor, user_id);
if (NULL == dev_info) {
__send_sensor_presence_event(sensor_info, sensor);
- return;
+ return ret;
}
- ret_if(0 > user_id);
+ retv_if(0 > user_id, UAM_ERROR_INVALID_PARAMETER);
l = g_slist_find_custom(users, &user_id, __compare_user_id);
if (NULL == l) {
UAM_ERR("Invalid user_id [%d]", user_id);
- return;
+ return UAM_ERROR_INVALID_PARAMETER;
}
user = l->data;
if (NULL == l) {
UAM_ERR("Valid user_id [%d] but Invalid device_id [%s]",
user_id, dev_info->device_id);
- return;
+ return UAM_ERROR_INVALID_PARAMETER;
}
device = l->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);
- return;
+ return UAM_ERROR_INVALID_PARAMETER;
}
l = g_slist_find_custom(device->tech_list,
&(dev_info->type), __compare_tech_type);
if (NULL == l) {
UAM_ERR("Strange, tech type [%d] not found", dev_info->type);
- return;
+ return UAM_ERROR_INVALID_PARAMETER;
}
tech = l->data;
tech->presence_state = UAM_PRESENCE_STATE_PRESENT;
tech->timestamp = (unsigned long long)time(NULL);
- ret_if(UAM_ERROR_NONE != __uam_db_begin_transaction());
+ retv_if(UAM_ERROR_NONE != __uam_db_begin_transaction(), UAM_ERROR_INVALID_PARAMETER);
/* Check if IP address was updated then update in DB */
if (UAM_TECH_TYPE_WIFI == dev_info->type) {
uam_db_address_info_t *addr_info = NULL;
addr_info->address = g_strdup(dev_info->ipv4_addr);
/* Update address in DB */
- if (UAM_ERROR_NONE != _uam_device_db_update_device_ip_address(dev_info->device_id,
- dev_info->type, dev_info->mac, dev_info->ipv4_addr)) {
+ ret = _uam_device_db_update_device_ip_address(dev_info->device_id,
+ dev_info->type, dev_info->mac, dev_info->ipv4_addr);
+ if (UAM_ERROR_NONE != ret) {
UAM_WARN("_uam_device_db_update_device_ip_address failed");
__uam_db_end_transaction(0);
- return;
+ return ret;
}
}
}
/* Update database (presence state & timestamp) */
- if (UAM_ERROR_NONE != _uam_device_db_update_device_timestamp(dev_info->device_id,
- dev_info->type, dev_info->mac, tech->timestamp)) {
+ ret = _uam_device_db_update_device_timestamp(dev_info->device_id,
+ dev_info->type, dev_info->mac, tech->timestamp);
+ if (UAM_ERROR_NONE != ret) {
UAM_WARN("_uam_device_db_update_device_timestamp failed");
__uam_db_end_transaction(0);
- return;
+ return ret;
}
- if (UAM_ERROR_NONE != _uam_device_db_update_device_presence(dev_info->device_id,
- dev_info->type, dev_info->mac, tech->presence_state)) {
+ ret = _uam_device_db_update_device_presence(dev_info->device_id,
+ dev_info->type, dev_info->mac, tech->presence_state);
+ if (UAM_ERROR_NONE != ret) {
UAM_WARN("_uam_device_db_update_device_presence failed");
__uam_db_end_transaction(0);
- return;
+ return ret;
}
__send_user_presence_event(tech, sensor, dev_info->device_id);
__uam_db_end_transaction(1);
FUNC_EXIT;
+ return ret;
}
static void __send_user_absence_event(uam_tech_type_e type, unsigned int sensor)