From: Atul Rai Date: Tue, 11 Jun 2019 10:11:47 +0000 (+0530) Subject: Add read/write operation for service info in UA DB X-Git-Tag: accepted/tizen/unified/20190702.234158~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=286bec8678cee4c2c46ff499e6232133372b78df;p=platform%2Fcore%2Fconnectivity%2Fua-manager.git Add read/write operation for service info in UA DB Change-Id: I3fc1955bab8e93f3e3002df72f6f5a9df720ef55 Signed-off-by: Atul Rai --- diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index fdad64a..4dd32ed 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -184,6 +184,30 @@ static void __remove_service_to_dev_tech_mapping( FUNC_EXIT; } +static char *__get_mac_addr(uam_db_tech_info_t *tech) +{ + FUNC_ENTRY; + GSList *l; + + retv_if(NULL == tech, NULL); + + for (l = tech->addresses; NULL != l; l = g_slist_next(l)) { + uam_db_address_info_t *addr = l->data; + + if (!addr) + continue; + + if (addr->addr_type == UAM_ADDR_TYPE_BT || + addr->addr_type == UAM_ADDR_TYPE_BLE || + addr->addr_type == UAM_ADDR_TYPE_WIFI || + addr->addr_type == UAM_ADDR_TYPE_P2P) + return addr->address; + } + + FUNC_EXIT; + return NULL; +} + static void __remove_user_device(gpointer data) { FUNC_ENTRY; @@ -520,12 +544,30 @@ static GSList *__convert_db_svc_list_to_uam_svc_list(GSList *db_svc_list) retv_if(NULL == db_svc_list, NULL); + /* + * Iterate over the db_svc_list and add each service to the global + * service list "services" if its not already inserted. Also append this + * uam_db_service_info_t to svc_list. + */ for (l = db_svc_list; NULL != l; l = g_slist_next(l)) { - /* - * TODO: Iterate over the db_svc_list and add each service to the global - * service list "services" if its not already inserted. Also append this - * uam_db_service_info_t to svc_list. - * */ + db_service_info_t *db_svc = l->data; + uam_db_service_info_t *service; + GSList *l1; + + if (!db_svc) + continue; + + l1 = g_slist_find_custom(services, + db_svc->service_name, __compare_svc_name); + if (!l1) { + service = g_new0(uam_db_service_info_t, 1); + service->name = g_strdup(db_svc->service_name); + service->cycle = db_svc->cycle; + services = g_slist_append(services, service); + } else + service = l1->data; + + svc_list = g_slist_append(svc_list, service); } FUNC_EXIT; @@ -1293,6 +1335,7 @@ int _uam_core_service_add_user(const char *svc_name, const char *account) for (l1 = device->tech_list; NULL != l1; l1 = g_slist_next(l1)) { uam_db_tech_info_t *tech = l1->data; + char *mac; GSList *l2; if (!tech) @@ -1305,12 +1348,11 @@ int _uam_core_service_add_user(const char *svc_name, const char *account) __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, - * tech->tech_type, ->mac, service->name, service->cycle)) - * UAM_WARN("Device service addition to persistent DB failed"); - */ + mac = __get_mac_addr(tech); + /* Insert device service info to db */ + if (UAM_ERROR_NONE != _uam_db_insert_device_service_info(device->device_id, + tech->tech_type, mac, service->name, service->cycle)) + UAM_WARN("Device service addition to persistent DB failed"); } } @@ -1345,6 +1387,7 @@ int _uam_core_service_remove_user(const char *svc_name, const char *account) for (l1 = device->tech_list; NULL != l1; l1 = g_slist_next(l1)) { uam_db_tech_info_t *tech = l1->data; + char *mac; GSList *l2; if (!tech) @@ -1359,12 +1402,11 @@ int _uam_core_service_remove_user(const char *svc_name, const char *account) __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( - * device->device_id, tech->tech_type, mac, svc_name)) - * UAM_WARN("Device service removal from persistent DB failed"); - */ + mac = __get_mac_addr(tech); + /* Remove service-device from DB */ + if (UAM_ERROR_NONE != _uam_db_delete_device_service_info( + device->device_id, tech->tech_type, mac, svc_name)) + UAM_WARN("Device service removal from persistent DB failed"); } } @@ -1418,6 +1460,7 @@ int _uam_core_service_add_device(const char *svc_name, const char *device_id, in { FUNC_ENTRY; GSList *l; + char *mac; uam_db_tech_info_t *tech_info; uam_db_service_info_t *service; @@ -1444,12 +1487,11 @@ int _uam_core_service_add_device(const char *svc_name, const char *device_id, in __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, - * tech_type, mac, service->name, service->cycle)) - * UAM_WARN("Device service addition to persistent DB failed"); - */ + mac = __get_mac_addr(tech_info); + /* Insert device service info to db */ + if (UAM_ERROR_NONE != _uam_db_insert_device_service_info(device_id, + tech_type, mac, service->name, service->cycle)) + UAM_WARN("Device service addition to persistent DB failed"); FUNC_EXIT; return UAM_ERROR_NONE; @@ -1459,6 +1501,7 @@ int _uam_core_service_remove_device(const char *svc_name, const char *device_id, { FUNC_ENTRY; GSList *l; + char *mac; uam_db_tech_info_t *tech_info; retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAM); @@ -1478,12 +1521,11 @@ int _uam_core_service_remove_device(const char *svc_name, const char *device_id, __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( - * device_id, tech_type, mac, svc_name)) - * UAM_WARN("Device service removal from persistent DB failed"); - */ + mac = __get_mac_addr(tech_info); + /* Remove service-device from DB */ + if (UAM_ERROR_NONE != _uam_db_delete_device_service_info( + device_id, tech_type, mac, svc_name)) + UAM_WARN("Device service removal from persistent DB failed"); FUNC_EXIT; return UAM_ERROR_NONE; @@ -1511,11 +1553,9 @@ int _uam_core_set_service_detection_cycle(const char *svc_name, unsigned int new else service->remaining_time = new_cycle - elapsed_time; - /* - * TODO: Update service detection cycle in DB - * if (UAM_ERROR_NONE != _uam_db_update_service_cycle(svc_name, new_cycle)) - * UAM_WARN("Service cycle updation to persistent DB failed"); - */ + /* Update service detection cycle in DB */ + if (UAM_ERROR_NONE != _uam_db_update_service_cycle(svc_name, new_cycle)) + UAM_WARN("Service cycle updation to persistent DB failed"); FUNC_EXIT; return UAM_ERROR_NONE; @@ -1912,15 +1952,12 @@ int _uam_core_init(void) } user = l1->data; -#if 0 - /* TODO: Fetch device services from DB */ + /* Fetch device services from DB */ l1 = _uam_db_get_device_services( db_info->dev_info.device_id, db_info->dev_info.type, db_info->dev_info.mac); -#else - l1 = NULL; -#endif + svc_list = __convert_db_svc_list_to_uam_svc_list(l1); __uam_core_add_dev_to_list(user, &(db_info->dev_info), db_info->presence_state, db_info->timestamp, svc_list); @@ -2079,13 +2116,11 @@ void _uam_core_handle_device_added(int status, dev_info, UAM_PRESENCE_STATE_PRESENT, timestamp)) UAM_WARN("Device addition to persistent DB failed"); - /* - * TODO: insert device service info to db - * if (UAM_ERROR_NONE != _uam_db_insert_device_service_info( - * dev_info->device_id, dev_info->type, dev_info->mac, - * UAM_SERVICE_DEFAULT, UAM_DETECTION_CYCLE_DEFAULT)) - * UAM_WARN("Device service addition to persistent DB failed"); - */ + /* Insert device service info to db */ + if (UAM_ERROR_NONE != _uam_db_insert_device_service_info( + dev_info->device_id, dev_info->type, dev_info->mac, + UAM_SERVICE_DEFAULT, UAM_DETECTION_CYCLE_DEFAULT)) + UAM_WARN("Device service addition to persistent DB failed"); /* Send device added event to application */ __send_device_event(UAM_EVENT_DEVICE_ADDED, dev_info);