FUNC_EXIT;
}
+static void __add_service_to_dev_tech_mapping(
+ uam_db_tech_info_t *tech, uam_db_service_info_t *service)
+{
+ FUNC_ENTRY;
+
+ ret_if(NULL == tech);
+ ret_if(NULL == service);
+
+ tech->services = g_slist_append(tech->services, service);
+ service->dev_techs = g_slist_append(service->dev_techs, tech);
+
+ FUNC_EXIT;
+}
+
+static void __remove_service_to_dev_tech_mapping(
+ uam_db_tech_info_t *tech, uam_db_service_info_t *service)
+{
+ FUNC_ENTRY;
+
+ ret_if(NULL == tech);
+ ret_if(NULL == service);
+
+ tech->services = g_slist_remove(tech->services, service);
+ service->dev_techs = g_slist_remove(service->dev_techs, tech);
+
+ FUNC_EXIT;
+}
+
static void __remove_user_device(gpointer data)
{
FUNC_ENTRY;
tech->timestamp = timestamp;
tech->device = device;
+ tech->services = svc_list;
+ for (l = svc_list; NULL != l; l = g_slist_next(l)) {
+ uam_db_service_info_t *service = l->data;
+
+ if (!service)
+ continue;
+
+ service->dev_techs = g_slist_prepend(service->dev_techs, tech);
+ }
+
/* Add tech info to tech list */
device->tech_list = g_slist_append(device->tech_list, tech);
device->supported_techs |= tech->tech_type;
if (NULL != l2)
continue;
- tech->services = g_slist_append(tech->services, service);
+ __add_service_to_dev_tech_mapping(tech, service);
+
/*
* TODO: insert device service info to db
* if (UAM_ERROR_NONE != _uam_db_insert_device_service_info(device->device_id,
continue;
UAM_DBG("Service %s found, remove it from list", svc_name);
- tech->services = g_slist_remove(tech->services, l2->data);
+ __remove_service_to_dev_tech_mapping(
+ tech, (uam_db_service_info_t *)l2->data);
+
/*
* TODO: Remove service-device from DB
* if (UAM_ERROR_NONE != _uam_db_delete_device_service_info(
} else
service = l->data;
- tech_info->services = g_slist_append(tech_info->services, service);
+ __add_service_to_dev_tech_mapping(tech_info, service);
+
/*
* TODO: insert device service info to db
* if (UAM_ERROR_NONE != _uam_db_insert_device_service_info(device_id,
l = g_slist_find_custom(tech_info->services, svc_name, __compare_svc_name);
retv_if(NULL == l, UAM_ERROR_NOT_REGISTERED);
- tech_info->services = g_slist_remove(tech_info->services, l->data);
+ __remove_service_to_dev_tech_mapping(tech_info, (uam_db_service_info_t *)l->data);
+
/*
* TODO: Remove service-device from DB
* if (UAM_ERROR_NONE != _uam_db_delete_device_service_info(
FUNC_EXIT;
}
+void __send_user_presence_event(uam_db_tech_info_t *tech, unsigned int sensor)
+{
+ FUNC_ENTRY;
+ uam_db_user_info_t *user;
+ GSList *l;
+
+ ret_if(NULL == tech);
+ ret_if(NULL == tech->services);
+
+ user = tech->device->user;
+ for (l = tech->services; NULL != l; l = g_slist_next(l)) {
+ uam_db_service_info_t *svc = l->data;
+ GSList *l1;
+
+ if (!svc || !svc->monitors)
+ continue;
+
+ for (l1 = svc->monitors; NULL != l1; l1 = g_slist_next(l1)) {
+ uam_monitor_info_t *mon = l1->data;
+
+ if (!mon)
+ continue;
+
+ if (!(mon->sensors & sensor))
+ continue;
+
+ if (UAM_DETECT_PRESENCE != mon->mode)
+ continue;
+
+ _uam_manager_send_event(mon->name,
+ UAM_EVENT_USER_PRESENCE_DETECTED,
+ g_variant_new("(uss)", sensor,
+ user->account, svc->name));
+ UAM_DBG("Sent UAM_EVENT_USER_PRESENCE_DETECTED to %s"
+ " for 0x%8.8X, User: %s Service: %s",
+ mon->name, sensor, user->account, svc->name);
+ }
+ }
+
+ FUNC_EXIT;
+}
+
void _uam_core_handle_presence_detected(unsigned int sensor,
int user_id, uam_device_info_t *dev_info)
{
dev_info->type, dev_info->mac, tech->presence_state))
UAM_WARN("_ua_device_db_update_device_presence failed");
- _uam_manager_send_event(NULL, UAM_EVENT_USER_PRESENCE_DETECTED,
- g_variant_new("(us)", sensor, user->account));
- UAM_DBG("Sent UAM_EVENT_USER_PRESENCE_DETECTED for 0x%8.8X, User: %s",
- sensor, user->account);
+ __send_user_presence_event(tech, sensor);
FUNC_EXIT;
}
-static void __send_user_absence_event(uam_db_user_info_t *user,
- uam_tech_type_e type, unsigned int sensor)
+static void __send_user_absence_event(uam_tech_type_e type, unsigned int sensor)
{
FUNC_ENTRY;
- gboolean is_present = FALSE;
GSList *l;
/*
- * If none of the user's devices which support the tech_type, is PRESENT,
- * send user ABSENCE event (User absent for tech_type/sensor).
+ * For each service, find users absent on given sensor. Then for each
+ * monitor in serivce's monitor list, if it is monitoring ABSENCE on
+ * given sensor, send user ABSENCE event.
*/
- for (l = user->devices; NULL != l; l = g_slist_next(l)) {
- uam_db_device_info_t *device = l->data;
+ for (l = services; NULL != l; l = g_slist_next(l)) {
+ uam_db_service_info_t *svc = l->data;
+ GSList *absent_users = NULL;
+ GSList *present_users = NULL;
GSList *l1;
+ GSList *l2;
- if (!device)
- continue;
-
- if (!(device->supported_techs & type))
+ if (!svc || !svc->monitors || !svc->dev_techs)
continue;
- for (l1 = device->tech_list; NULL != l1; l1 = g_slist_next(l1)) {
- uam_db_tech_info_t *tech = l1->data;
+ for (l1 = svc->dev_techs; NULL != l1; l1 = g_slist_next(l1)) {
+ uam_db_tech_info_t *tech = l->data;
- if (!tech || tech->tech_type != type)
+ if (!tech || (tech->tech_type != type))
continue;
+ l2 = g_slist_find_custom(present_users,
+ &(tech->device->user->user_id), __compare_user_id);
if (UAM_PRESENCE_STATE_PRESENT == tech->presence_state) {
- is_present = TRUE;
- break;
+ /* 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)
+ 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 (!l2)
+ absent_users = g_slist_prepend(absent_users, tech->device->user);
}
}
- if (is_present)
- break;
- }
+ g_slist_free(present_users);
+ if (!absent_users)
+ continue;
+
+ for (l2 = svc->monitors; NULL != l2; l2 = g_slist_next(l2)) {
+ uam_monitor_info_t *mon = l2->data;
+
+ if (!mon)
+ continue;
+
+ if (!(mon->sensors & sensor))
+ continue;
+
+ if (UAM_DETECT_ABSENCE != mon->mode)
+ continue;
+
+ for (l1 = absent_users; NULL != l1; l1 = g_slist_next(l1)) {
+ uam_db_user_info_t *user = l1->data;
+
+ if (!user)
+ continue;
- if (!is_present) {
- _uam_manager_send_event(NULL, UAM_EVENT_USER_ABSENCE_DETECTED,
- g_variant_new("(us)", sensor, user->account));
- UAM_DBG("Sent UAM_EVENT_USER_ABSENCE_DETECTED for 0x%8.8X", sensor);
+ _uam_manager_send_event(mon->name,
+ UAM_EVENT_USER_PRESENCE_DETECTED,
+ g_variant_new("(uss)", sensor,
+ user->account, svc->name));
+ UAM_DBG("Sent UAM_EVENT_USER_PRESENCE_DETECTED to %s"
+ " for 0x%8.8X, User: %s Service: %s",
+ mon->name, sensor, user->account, svc->name);
+ }
+ }
+
+ g_slist_free(absent_users);
}
FUNC_EXIT;
dev_info->type, dev_info->mac, tech->presence_state))
UAM_WARN("_ua_device_db_update_device_presence failed");
- //__send_user_absence_event(user, dev_info->type, sensor);
-
FUNC_EXIT;
}
else if (UAM_SENSOR_BITMASK_WIFI == sensor)
type = UAM_TECH_TYPE_WIFI;
- if (UAM_TECH_TYPE_NONE != type) {
- GSList *l;
-
- for (l = users; NULL != l; l = g_slist_next(l)) {
- uam_db_user_info_t *user = l->data;
- if (!user)
- continue;
-
- __send_user_absence_event(user, type, sensor);
- }
- }
+ if (UAM_TECH_TYPE_NONE != type)
+ __send_user_absence_event(type, sensor);
if (0 == detecting_sensors)
/* Send detection stopped event */