From: saerome.kim Date: Thu, 11 Jan 2018 12:04:45 +0000 (+0900) Subject: d2d-subowner: fix a bug when execute mot and remove_mo twice, then MOT always fails X-Git-Tag: submit/tizen/20190131.065036~241 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=40cc3ddfc759c055f7df41e6174be6470e492608;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git d2d-subowner: fix a bug when execute mot and remove_mo twice, then MOT always fails Signed-off-by: saerome.kim --- diff --git a/packaging/d2d-manager.spec b/packaging/d2d-manager.spec index c00e721..754f5f8 100644 --- a/packaging/d2d-manager.spec +++ b/packaging/d2d-manager.spec @@ -119,7 +119,7 @@ cp test/oic_svr_db_client.dat oic_svr_db_subowner_client.dat %postun rm -rf %{NETWORK_FW_DATADIR}/oic_pdm_d2ds.db -rm -rf %{NETWORK_FW_DATADIR}/oic_pdm_subowner.db-journal +rm -rf %{NETWORK_FW_DATADIR}/oic_pdm_d2ds.db-journal %files %manifest %{name}.manifest diff --git a/src/d2d-subowner/d2ds-subowner.c b/src/d2d-subowner/d2ds-subowner.c index f88b993..942cbaa 100644 --- a/src/d2d-subowner/d2ds-subowner.c +++ b/src/d2d-subowner/d2ds-subowner.c @@ -855,7 +855,7 @@ static gpointer _disc_owned_devs_func(gpointer data) /* delete un/owned device lists before updating them */ _remove_owned_client(); - D2DS_LOGD("Discovering Multiple Owned Devices on Network."); + D2DS_LOGD("Discovering Multiple Owned Devices"); ret = OCDiscoverMultipleOwnedDevices(DISCOVERY_TIMEOUT, &g_client->g_mowned_list); if (OC_STACK_OK != ret) { D2DS_LOGE( "OCDiscoverMultipleOwnerEnabledDevices API error"); @@ -896,15 +896,31 @@ static int _disc_owned_devs(d2ds_service *service) return D2DS_ERROR_NONE; } -static void _mot_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error) +static void _mot_cb(void* ctx, int num, OCProvisionResult_t* arr, bool has_error) { + int i = 0; + int ret = OC_STACK_OK; d2ds_subowner_s *client = (d2ds_subowner_s *)ctx; if (!has_error) { D2DS_LOGD("Multiple Ownership Transfer SUCCEEDED"); } else { D2DS_LOGD( "Multiple Ownership Transfer FAILED "); - _print_result_list((const OCProvisionResult_t*) arr, nOfRes); + + _print_result_list((const OCProvisionResult_t*) arr, num); + + ret = openDB(); + if (OC_STACK_OK != ret) + D2DS_LOGE( "openDB: ret = %d (%s)", ret, _error_to_string(ret)); + + for ( ; num > i; ++i) { + if (OC_STACK_OK !=arr[i].res) { + ret = delete_mowned_device_db((const OicUuid_t*) &arr[i].deviceId); + } + } + ret = closeDB(); + if (OC_STACK_OK != ret) + D2DS_LOGE( "closeDB: ret = %d (%s)", ret, _error_to_string(ret)); } client->g_doneCB = true; } @@ -1053,10 +1069,14 @@ static gpointer _remove_mo_func(gpointer data) } ret = openDB(); - if (OC_STACK_OK == ret) { - delete_mowned_device_db((const OicUuid_t*) uuid_target); - closeDB(); - } + if (OC_STACK_OK != ret) + D2DS_LOGE( "openDB: ret = %d (%s)", ret, _error_to_string(ret)); + ret = delete_mowned_device_db((const OicUuid_t*) uuid_target); + if (OC_STACK_OK != ret) + D2DS_LOGE( "delete_mowned_device_db: ret = %d (%s)", ret, _error_to_string(ret)); + ret = closeDB(); + if (OC_STACK_OK != ret) + D2DS_LOGE( "closeDB: ret = %d (%s)", ret, _error_to_string(ret)); ret = OCRemoveSubOwner(g_client, src_dev, &uuid_mowner, _remove_mo_cb); if (OC_STACK_OK != ret ) { @@ -1859,7 +1879,7 @@ int d2ds_request_disc_owned_devs(d2ds_service *service) d2ds_check_null_ret_error("service", service, FALSE); - D2DS_LOGD("[IPC] Discovery Owned devices using MOT"); + D2DS_LOGD("[IPC] Discovery Owned devices"); /* If we are working now? */ if (g_atomic_int_get(&service->pending)) @@ -1905,7 +1925,7 @@ int d2ds_request_remove_mo(d2ds_service *service, gchar* uuid_str) d2ds_check_null_ret_error("service", service, FALSE); - D2DS_LOGD("[IPC] Remove Mullti Ownership"); + D2DS_LOGD("[IPC] Remove Mulltiple Ownership"); /* If we are working now? */ if (g_atomic_int_get(&service->pending))