From ac181e06beb04bc074c8e62ea58dfce0bdec71e9 Mon Sep 17 00:00:00 2001 From: Abhay agarwal Date: Mon, 23 Dec 2019 17:46:10 +0530 Subject: [PATCH] Update registered device list to plugin with payload information Signed-off-by: Abhay agarwal --- ua-daemon/src/pm/ua-pm-util.c | 30 ++++++++++++++++++++++++++++ ua-daemon/src/ua-manager-core.c | 26 +++++++++++++++++++++--- ua-daemon/src/ua-manager-device-service-db.c | 2 +- ua-plugins/include/ua-plugin.h | 1 + 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/ua-daemon/src/pm/ua-pm-util.c b/ua-daemon/src/pm/ua-pm-util.c index 6bab1d5..b698b27 100644 --- a/ua-daemon/src/pm/ua-pm-util.c +++ b/ua-daemon/src/pm/ua-pm-util.c @@ -131,6 +131,21 @@ uas_address_type_e _pm_util_uam_addr_type_to_uas_addr_type(uam_addr_type_e type) } } +void _pm_util_uam_db_payload_to_uas_payload( + uas_payload_info_t *dst_payload, uam_db_payload_info_t *src_payload) +{ + if (src_payload) { + dst_payload->primary_key = src_payload->primary_key; + dst_payload->device_icon = src_payload->device_icon; + dst_payload->secondary_key = src_payload->secondary_key; + dst_payload->device_uid = g_memdup(&(src_payload->device_uid), + UAM_BLE_PAYLOAD_DEVICE_UID_LEN); + dst_payload->bt_mac = g_memdup(&(src_payload->bt_mac), + UAM_BT_MAC_ADDRESS_STRING_LEN); + } + UAM_DBG("payload primary key: [%d]", dst_payload->primary_key); +} + void _pm_util_uas_device_info_free(uas_device_info_t *device) { FUNC_ENTRY; @@ -153,6 +168,7 @@ void _pm_util_uam_db_dev_to_uas_dev(unsigned int tech_type, FUNC_ENTRY; int i = 0; GSList *l; + int len = 0; ret_if(NULL == dev); ret_if(NULL == dev->user); @@ -190,6 +206,20 @@ void _pm_util_uam_db_dev_to_uas_dev(unsigned int tech_type, (*device)->addr_list[i].type = _pm_util_uam_addr_type_to_uas_addr_type(addr->addr_type); (*device)->addr_list[i++].address = g_strdup(addr->address); } + + /** update payload list */ + len = g_slist_length(tech->svc_dev_list); + (*device)->num_payload = len; + (*device)->payload = g_new0(uas_payload_info_t, len); + for (l1 = tech->svc_dev_list; NULL != l1; l1 = g_slist_next(l1)) { + uam_svc_dev_info_t *svc_dev = l1->data; + uam_db_payload_info_t *payload = svc_dev->payload; + + if (!payload) + continue; + + _pm_util_uam_db_payload_to_uas_payload(&(*device)->payload[i], payload); + } } FUNC_EXIT; diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index a29582f..05fb7b5 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -328,7 +328,7 @@ static int __copy_tech_info_to_device_info(uam_db_tech_info_t *tech, uam_device_ device->operating_system = tech->device->os; g_strlcpy(device->device_id, tech->device->device_id, - UAM_DEVICE_ID_MAX_STRING_LEN); + UAM_DEVICE_ID_MAX_STRING_LEN); device->type = tech->tech_type; device->discriminant = tech->discriminant; device->last_seen = tech->last_seen; @@ -4070,6 +4070,7 @@ int _uam_core_service_add_payload(uam_ble_payload_s *payload, uam_db_service_info_t *service; uam_db_payload_info_t *db_payload; uam_svc_dev_info_t *svc_dev; + uam_db_device_info_t *device; GSList *l; retv_if(NULL == payload, UAM_ERROR_INVALID_PARAMETER); @@ -4093,8 +4094,27 @@ int _uam_core_service_add_payload(uam_ble_payload_s *payload, svc_dev = _uam_core_find_svc_dev_info(db_payload->device_id, db_payload->tech_type, service->name); retv_if(NULL == svc_dev, UAM_ERROR_INVALID_PARAMETER); - /** Update svc_dev list for device*/ - /** Update registered devices for ble*/ + + /**Update svc_dev list for device*/ + l = g_slist_find_custom(devices, db_payload->device_id, __compare_device_id); + device = l->data; + + for (l = device->tech_list; NULL != l; l = g_slist_next(l)) { + uam_db_tech_info_t *tech = l->data; + + if (!tech) + continue; + + if (db_payload->tech_type != tech->tech_type) + continue; + + tech->svc_dev_list = g_slist_append(tech->svc_dev_list, svc_dev); + } + + /* Set/update registered device list to plugins */ + if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) + UAM_ERR("_uam_pm_set_registered_devices failed"); + /*** Add payload service mapping to database ***/ ret = _uam_db_update_device_service_payload_info(payload, service->name); diff --git a/ua-daemon/src/ua-manager-device-service-db.c b/ua-daemon/src/ua-manager-device-service-db.c index 2ba41c1..2696b8d 100644 --- a/ua-daemon/src/ua-manager-device-service-db.c +++ b/ua-daemon/src/ua-manager-device-service-db.c @@ -33,7 +33,7 @@ #define SELECT_DEVICE_SERVICES \ "SELECT D.device_id, D.tech_type, S.service_name, X.discriminant, X.last_seen, " \ - "P.primary_key, P.secondary_key, P.device_uid, P.device_icon" \ + "P.primary_key, P.secondary_key, P.device_uid, P.device_icon " \ "FROM device_services as X JOIN services as S USING(service_number) JOIN devices as D " \ "USING(device_number) JOIN payloads as P USING(payload_number)" diff --git a/ua-plugins/include/ua-plugin.h b/ua-plugins/include/ua-plugin.h index 3cc420e..0059618 100644 --- a/ua-plugins/include/ua-plugin.h +++ b/ua-plugins/include/ua-plugin.h @@ -118,6 +118,7 @@ typedef struct { uas_address_info_t *addr_list; /**< Address list (IP, Subnet Mask, Gateway etc) */ int discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */ 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_device_info_t; -- 2.7.4