From: Abhay Agarwal Date: Mon, 17 May 2021 05:53:43 +0000 (+0530) Subject: Handle location detection event X-Git-Tag: accepted/tizen/unified/20210630.144044^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0ffd1125105dabe8db44c5d58f34f204c6125c56;p=platform%2Fcore%2Fconnectivity%2Fua-manager.git Handle location detection event Change-Id: Iabe4f904c98237948e83eac894893a04fea8f3c4 Signed-off-by: Abhay Agarwal --- diff --git a/include/ua-api.h b/include/ua-api.h index eb4e07a..c37e8c3 100755 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -166,6 +166,7 @@ typedef enum { UAM_EVENT_USER_PRESENCE_DETECTED, /**< User presence detected */ UAM_EVENT_ABSENCE_DETECTED, /**< Absence detected */ UAM_EVENT_USER_ABSENCE_DETECTED, /**< User absence detected */ + UAM_EVENT_USER_LOCATION_DETECTED, /**< User location detected */ UAM_EVENT_AMBIANT_MODE_ENABLED, /**< Ambient mode enabled */ UAM_EVENT_AMBIANT_MODE_DISABLED, /**< Ambient mode disabled */ UAM_EVENT_SENSOR_STATE_READY, /**< Sensor state ready */ @@ -560,6 +561,10 @@ typedef struct { gboolean discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */ unsigned long long last_seen; /**< Latest seen time when device was discoverd */ int app_num; /**<*App Number*/ + int distance_mm; /** Device distance */ + int x; /** Device x coordinate */ + int y; /** Device y coordinate */ + int z; /** Device z coordinate */ } uam_device_info_s; /** @@ -606,6 +611,10 @@ typedef struct { char service[UAM_SERVICE_MAX_STRING_LEN]; /**< Service name */ unsigned long long last_seen; /**< The last time of detection */ char device_id[UAM_DEVICE_ID_MAX_STRING_LEN]; /**< Device's unique ID */ + int distance_mm; /* Device distance */ + int x; /* x coordinate */ + int y; /* y coordinate */ + int z; /* z coordinate */ } uam_detection_event_data_s; /** diff --git a/include/ua-internal.h b/include/ua-internal.h index 41156af..5e1b2dd 100755 --- a/include/ua-internal.h +++ b/include/ua-internal.h @@ -111,6 +111,7 @@ typedef enum { #define UAM_SIGNAL_USER_PRESENCE_DETECTED "UserPresenceDetected" #define UAM_SIGNAL_ABSENCE_DETECTED "AbsenceDetected" #define UAM_SIGNAL_USER_ABSENCE_DETECTED "UserAbsenceDetected" +#define UAM_SIGNAL_USER_LOCATION_DETECTED "UserLocationDetected" #define UAM_SIGNAL_SENSOR_STATE_READY "SensorReady" #define UAM_SIGNAL_SENSOR_STATE_NOT_READY "SensorNotReady" #define UAM_SIGNAL_DETECTION_STARTED "DetectionStarted" diff --git a/ua-api/src/ua-common.c b/ua-api/src/ua-common.c index 91e756d..b600003 100644 --- a/ua-api/src/ua-common.c +++ b/ua-api/src/ua-common.c @@ -101,6 +101,7 @@ const char *_uam_event_to_str(unsigned int event) CASE_TO_STR(UAM_EVENT_USER_PRESENCE_DETECTED) CASE_TO_STR(UAM_EVENT_ABSENCE_DETECTED) CASE_TO_STR(UAM_EVENT_USER_ABSENCE_DETECTED) + CASE_TO_STR(UAM_EVENT_USER_LOCATION_DETECTED) CASE_TO_STR(UAM_EVENT_AMBIANT_MODE_ENABLED) CASE_TO_STR(UAM_EVENT_AMBIANT_MODE_DISABLED) CASE_TO_STR(UAM_EVENT_SENSOR_STATE_READY) diff --git a/ua-api/src/ua-event-handler.c b/ua-api/src/ua-event-handler.c index 7a19c87..cfd83e8 100644 --- a/ua-api/src/ua-event-handler.c +++ b/ua-api/src/ua-event-handler.c @@ -142,6 +142,39 @@ static void __uam_event_handler(GDBusConnection *connection, __uam_send_event(event, result, &event_data, event_info->cb, event_info->user_data); + + } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_USER_LOCATION_DETECTED)) { + uam_detection_event_data_s event_data; + unsigned int sensor_bitmask; + const char *account = NULL; + const char *service = NULL; + const char *device_id = NULL; + unsigned long long last_seen = 0; + unsigned int distance = 0; + unsigned int x = 0; + unsigned int y = 0; + unsigned int z = 0; + + g_variant_get(parameters, "(ut&s&s&siiii)", &sensor_bitmask, &last_seen, &account, + &service, &device_id, &distance, &x, &y, &z); + + UAM_DBG("Sensor: 0x%8.8X, User: %s, Device: %s timestamp [%llu] distance %d" + " coordinates x:%d, y:%d, z:%d", sensor_bitmask, account, device_id, + last_seen, distance, x, y, z); + event = UAM_EVENT_USER_LOCATION_DETECTED; + event_data.sensor_bitmask = sensor_bitmask; + g_strlcpy(event_data.account, account, + UAM_USER_ACCOUNT_MAX_STRING_LEN); + g_strlcpy(event_data.service, service, UAM_SERVICE_MAX_STRING_LEN); + event_data.last_seen = last_seen; + event_data.distance_mm = distance; + event_data.x = x; + event_data.y = y; + event_data.z = z; + g_strlcpy(event_data.device_id, device_id, UAM_DEVICE_ID_MAX_STRING_LEN); + + __uam_send_event(event, result, &event_data, + event_info->cb, event_info->user_data); } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_PRESENCE_DETECTED)) { uam_sensor_info_s sensor_info; unsigned int sensor_bitmask; diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index d9b72ff..54d0972 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -223,6 +223,9 @@ int _uam_core_handle_presence_detected(unsigned int sensor, void _uam_core_handle_absence_detected(unsigned int sensor, int user_id, void *sensor_info); +int _uam_core_handle_location_detected(unsigned int sensor, + int user_id, void *sensor_info); + void _uam_core_cleanup_monitor(char *name); void _uam_core_reset_database(void); diff --git a/ua-daemon/src/pm/ua-plugin-handler.c b/ua-daemon/src/pm/ua-plugin-handler.c index 47acfa1..4f98f1e 100644 --- a/ua-daemon/src/pm/ua-plugin-handler.c +++ b/ua-daemon/src/pm/ua-plugin-handler.c @@ -142,6 +142,13 @@ static void device_detected_callback(int id, _pm_util_uas_payload_to_uam_payload(payload, device->payload); } + if (device->location) { + dev_info->distance_mm = device->location->distance_mm; + dev_info->x = device->location->x; + dev_info->y = device->location->y; + dev_info->z = device->location->z; + } + if (UAS_PRESENCE == type) { UAM_DBG("Presence detected for device %s on sensor 0x%2.2X", dev_info->device_id, sensor); @@ -151,6 +158,15 @@ static void device_detected_callback(int id, if (UAM_ERROR_NONE != ret) UAM_WARN("_uam_core_handle_presence_detected failed"); + } else if (UAS_LOCATION == type) { + UAM_DBG("Location detected for device %s on sensor 0x%2.2X", + dev_info->device_id, sensor); + + ret = _uam_core_handle_location_detected(sensor, + device->user_id, dev_info); + if (UAM_ERROR_NONE != ret) + UAM_WARN("_uam_core_handle_location_detected failed"); + } else { UAM_DBG("Absence detected for device %s on sensor 0x%2.2X", dev_info->device_id, sensor); diff --git a/ua-daemon/src/ua-manager-common.c b/ua-daemon/src/ua-manager-common.c index 1de7fa9..3b7cc1b 100644 --- a/ua-daemon/src/ua-manager-common.c +++ b/ua-daemon/src/ua-manager-common.c @@ -84,6 +84,7 @@ const char *_uam_manager_event_to_str(unsigned int event) CASE_TO_STR(UAM_EVENT_USER_PRESENCE_DETECTED) CASE_TO_STR(UAM_EVENT_ABSENCE_DETECTED) CASE_TO_STR(UAM_EVENT_USER_ABSENCE_DETECTED) + CASE_TO_STR(UAM_EVENT_USER_LOCATION_DETECTED) CASE_TO_STR(UAM_EVENT_AMBIANT_MODE_ENABLED) CASE_TO_STR(UAM_EVENT_AMBIANT_MODE_DISABLED) CASE_TO_STR(UAM_EVENT_SENSOR_STATE_READY) diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index da316e5..ab7e1da 100755 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -441,6 +441,7 @@ static void __uam_core_copy_addr(uam_device_info_s *device, uam_db_address_info_ case UAM_ADDR_TYPE_BT: case UAM_ADDR_TYPE_P2P: case UAM_ADDR_TYPE_WIFI: + case UAM_ADDR_TYPE_UWB: g_strlcpy(device->mac, addr->address, UAM_MAC_ADDRESS_STRING_LEN); break; @@ -1151,7 +1152,8 @@ unsigned int _uam_core_get_active_sensors(int detection_mode) GSList *l; retv_if((UAM_DETECT_PRESENCE != detection_mode) && - (UAM_DETECT_ABSENCE != detection_mode), 0); + (UAM_DETECT_ABSENCE != detection_mode) && + (UAM_DETECT_LOCATION != detection_mode), 0); for (l = monitors; NULL != l; l = g_slist_next(l)) { uam_monitor_info_t *monitor = l->data; @@ -2786,7 +2788,7 @@ static gboolean __start_detection(gpointer data) if (!service || !service->monitors) continue; - UAM_DBG("service: %p, monitors: %p", service, service->monitors); + UAM_DBG("service: %s, monitors: %p", service->name, service->monitors); UAM_DBG("service->remaining_time: %d", service->remaining_time); service->remaining_time -= UAM_DETECTION_CYCLE_MIN; if (0 >= service->remaining_time) { @@ -4039,6 +4041,143 @@ int _uam_core_handle_presence_detected(unsigned int sensor, return ret; } +void __send_user_location_event(uam_db_tech_info_t *tech, + unsigned int sensor, uam_device_info_s *dev_info) +{ + FUNC_ENTRY; + + GSList *l; + uam_db_user_info_t *user; + uam_svc_dev_info_t *svc_dev = NULL; + unsigned long long timestamp; + + ret_if(NULL == tech); + ret_if(NULL == tech->svc_list); + ret_if(NULL == dev_info); + + user = tech->device->user; + + for (l = tech->svc_list; NULL != l; l = g_slist_next(l)) { + uam_db_service_info_t *svc = l->data; + GSList *l1; + + if (!svc || !svc->monitors) + continue; + + UAM_DBG("Check service device discriminant"); + svc_dev = _uam_core_find_svc_dev_info(dev_info->device_id, + dev_info->type, svc->name, dev_info->app_num); + if (!svc_dev || !svc_dev->discriminant) + continue; + + UAM_DBG("Send event"); + 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_LOCATION != mon->mode) + continue; + + /* + * For current service, if any of its running monitor has same sensor + * and detection_mode + */ + + timestamp = _uam_get_timestamp(); + UAM_INFO("sensor [%d]", sensor); + _uam_manager_send_event(mon->name, + UAM_EVENT_USER_LOCATION_DETECTED, + g_variant_new("(utsssiiii)", sensor, timestamp, + user->account, svc->name, dev_info->device_id, + dev_info->distance_mm, dev_info->x, dev_info->y, + dev_info->z)); + UAM_DBG("Sent UAM_EVENT_USER_LOCATION_DETECTED to %s" + " on device %s for 0x%8.8X, User: %s" + " Service: %s Timestamp: %llu distance: %d" + " coordinates x:%d y:%d z:%d", + mon->name, dev_info->device_id, + sensor, user->account, svc->name, + timestamp, dev_info->distance_mm, + dev_info->x, dev_info->y, dev_info->z); + } + } + + FUNC_EXIT; +} + +int _uam_core_handle_location_detected(unsigned int sensor, + int user_id, void *info) +{ + FUNC_ENTRY; + int ret = UAM_ERROR_NONE; + + GSList *l; + uam_db_user_info_t *user; + uam_db_device_info_t *device; + uam_db_tech_info_t *tech; + uam_device_info_s *dev_info = NULL; + + UAM_INFO("sensor: 0x%8.8X, user_id: %d", sensor, user_id); + + if (info && (sensor & _uam_core_get_user_sensors())) { + /* Received info is device information */ + dev_info = info; + } + + if (NULL == dev_info) { + /* To-Do: Handle location detection if no dev info available */ + return ret; + } + + retv_if(0 > user_id, UAM_ERROR_INVALID_PARAMETER); + + /* fetch the app_num info for the corresponding user_id */ + _uam_core_get_app_num_from_userid(user_id, &dev_info->app_num); + + /* Search user */ + l = g_slist_find_custom(users, &user_id, __compare_user_id); + if (NULL == l) { + UAM_ERR("Invalid user_id [%d]", user_id); + return UAM_ERROR_INVALID_PARAMETER; + } + user = l->data; + + /* Search device */ + l = g_slist_find_custom(user->devices, + dev_info->device_id, __compare_device_id); + if (NULL == l) { + UAM_ERR("Valid user_id [%d] but Invalid device_id [%s]", + user_id, dev_info->device_id); + 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 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 UAM_ERROR_INVALID_PARAMETER; + } + tech = l->data; + + /* Send user location event */ + __send_user_location_event(tech, sensor, dev_info); + + FUNC_EXIT; + return ret; +} + static void __send_user_absence_event(uam_tech_type_e type, unsigned int sensor) { FUNC_ENTRY; diff --git a/ua-daemon/src/ua-manager-event-sender.c b/ua-daemon/src/ua-manager-event-sender.c index 6c0daee..a5e1e32 100644 --- a/ua-daemon/src/ua-manager-event-sender.c +++ b/ua-daemon/src/ua-manager-event-sender.c @@ -43,6 +43,7 @@ const char* __uam_event_str(int event) CASE_TO_STR(UAM_EVENT_USER_PRESENCE_DETECTED) CASE_TO_STR(UAM_EVENT_ABSENCE_DETECTED) CASE_TO_STR(UAM_EVENT_USER_ABSENCE_DETECTED) + CASE_TO_STR(UAM_EVENT_USER_LOCATION_DETECTED) CASE_TO_STR(UAM_EVENT_DETECTION_STARTED) CASE_TO_STR(UAM_EVENT_DETECTION_STOPPED) CASE_TO_STR(UAM_EVENT_DEVICE_FOUND) @@ -160,6 +161,9 @@ int _uam_manager_send_event(const char *dest, int event, GVariant *param) case UAM_EVENT_USER_ABSENCE_DETECTED: signal = UAM_SIGNAL_USER_ABSENCE_DETECTED; break; + case UAM_EVENT_USER_LOCATION_DETECTED: + signal = UAM_SIGNAL_USER_LOCATION_DETECTED; + break; case UAM_EVENT_DETECTION_STARTED: signal = UAM_SIGNAL_DETECTION_STARTED; break; diff --git a/ua-plugins/include/ua-plugin.h b/ua-plugins/include/ua-plugin.h index 74a964d..23c8709 100644 --- a/ua-plugins/include/ua-plugin.h +++ b/ua-plugins/include/ua-plugin.h @@ -108,6 +108,14 @@ typedef struct { char *address; /**< Address data */ } uas_address_info_t; +/* Device location information structure */ +typedef struct { + int distance_mm; /** Device distance (mm) */ + int x; /** x coordinate */ + int y; /** x coordinate */ + int z; /** x coordinate */ +} uas_location_info_t; + /* Device payload information structure */ typedef struct { char primary_key; /** Primary Key */ @@ -132,6 +140,7 @@ typedef struct { unsigned long long last_seen; /**< Last seen time */ int num_payload; /**< The number of payloads */ uas_payload_info_t *payload; /**< Payload for device filtering */ + uas_location_info_t *location; /**< Device Location */ } uas_device_info_t; /* Sensor information structure */