From db73cbcab3df766ff134ffa4dcaff3fe689cfdaa Mon Sep 17 00:00:00 2001 From: Cheoleun Moon Date: Tue, 13 Apr 2021 13:41:03 +0900 Subject: [PATCH] Create disc_handle for each ip_resolving operation Change-Id: I5bb1995d2be217b5f2aa4c291387c2a5bdd29240 Signed-off-by: Cheoleun Moon --- src/vine-disc.cpp | 29 ++++++++++++++++++++++++++--- src/vine-session.cpp | 10 +++++----- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/vine-disc.cpp b/src/vine-disc.cpp index 53d4d4a..31d3f4a 100755 --- a/src/vine-disc.cpp +++ b/src/vine-disc.cpp @@ -356,6 +356,10 @@ int vine_disc_create(vine_discovery_method_e disc_method, vine_disc_h *disc) void vine_disc_destroy(vine_disc_h disc) { + vine_disc_s *disc_handle = (vine_disc_s *)disc; + if (disc_handle && disc_handle->plugin_fn && + disc_handle->plugin_fn->deinit && disc_handle->plugin_handle) + disc_handle->plugin_fn->deinit(disc_handle->plugin_handle); free(disc); } @@ -392,6 +396,7 @@ vine_error_e __vine_disc_plugin_publish(vine_disc_h disc, vine_service_h service vine_disc_s *disc_handle = (vine_disc_s *)disc; void *plugin_handle = NULL; + RET_VAL_IF(disc_handle->plugin_fn == NULL, VINE_ERROR_INVALID_OPERATION, "plugin_fn is NULL"); if (disc_handle->plugin_fn->init == NULL) { VINE_LOGE("No init() defined"); return VINE_ERROR_OPERATION_FAILED; @@ -407,6 +412,8 @@ vine_error_e __vine_disc_plugin_publish(vine_disc_h disc, vine_service_h service if (disc_handle->plugin_fn->publish == NULL) { VINE_LOGE("No publish() defined"); + disc_handle->plugin_fn->deinit(plugin_handle); + disc_handle->plugin_handle = NULL; return VINE_ERROR_OPERATION_FAILED; } @@ -417,6 +424,7 @@ vine_error_e __vine_disc_plugin_publish(vine_disc_h disc, vine_service_h service if (error != VINE_DISC_ERROR_NONE) { VINE_LOGE("Fail to publish %d", error); disc_handle->plugin_fn->deinit(plugin_handle); + disc_handle->plugin_handle = NULL; return __convert_disc_error_to_vine_error(error); } @@ -454,6 +462,7 @@ vine_error_e __vine_disc_plugin_stop_publish(vine_disc_h disc) vine_disc_error error = VINE_DISC_ERROR_NONE; vine_disc_s *disc_handle = (vine_disc_s *)disc; + RET_VAL_IF(disc_handle->plugin_fn == NULL, VINE_ERROR_INVALID_OPERATION, "plugin_fn is NULL"); if (disc_handle->plugin_fn->init == NULL) { VINE_LOGE("No init() defined"); return VINE_ERROR_OPERATION_FAILED; @@ -495,6 +504,7 @@ vine_error_e __vine_disc_plugin_subscribe(vine_disc_h disc, vine_disc_s *disc_handle = (vine_disc_s *)disc; void *plugin_handle = NULL; + RET_VAL_IF(disc_handle->plugin_fn == NULL, VINE_ERROR_INVALID_OPERATION, "plugin_fn is NULL"); if (disc_handle->plugin_fn->init == NULL) { VINE_LOGE("No init() defined"); return VINE_ERROR_OPERATION_FAILED; @@ -509,6 +519,8 @@ vine_error_e __vine_disc_plugin_subscribe(vine_disc_h disc, if (disc_handle->plugin_fn->subscribe == NULL) { VINE_LOGE("No subscribe() defined"); + disc_handle->plugin_fn->deinit(plugin_handle); + disc_handle->plugin_handle = NULL; return VINE_ERROR_OPERATION_FAILED; } error = disc_handle->plugin_fn->subscribe(plugin_handle, service_type, iface_name); @@ -553,6 +565,7 @@ vine_error_e __vine_disc_plugin_stop_subscribe(vine_disc_h disc) vine_disc_error error = VINE_DISC_ERROR_NONE; vine_disc_s *disc_handle = (vine_disc_s *)disc; + RET_VAL_IF(disc_handle->plugin_fn == NULL, VINE_ERROR_INVALID_OPERATION, "plugin_fn is NULL"); if (disc_handle->plugin_fn->init == NULL) { VINE_LOGE("No init() defined"); return VINE_ERROR_OPERATION_FAILED; @@ -591,19 +604,28 @@ vine_error_e __vine_disc_plugin_resolve_ip(vine_disc_h disc, vine_service_h serv VINE_LOGD("service[%p], disc handle[%p]", service, disc); vine_disc_s *disc_handle = (vine_disc_s *)disc; - void *plugin_handle = disc_handle->plugin_handle; - if (disc_handle->plugin_fn == NULL || disc_handle->plugin_fn->init == NULL) { + void *plugin_handle = NULL; + + RET_VAL_IF(disc_handle->plugin_fn == NULL, VINE_ERROR_INVALID_OPERATION, "plugin_fn is NULL"); + if (disc_handle->plugin_fn->init == NULL) { VINE_LOGE("No init() defined"); return VINE_ERROR_OPERATION_FAILED; } + vine_disc_error error = disc_handle->plugin_fn->init(&plugin_handle, disc); + RET_VAL_IF(error != VINE_DISC_ERROR_NONE, + __convert_disc_error_to_vine_error(error), + "Fail to init %d", error); + disc_handle->plugin_handle = plugin_handle; VINE_LOGD("plugin handle[%p]", plugin_handle); if (disc_handle->plugin_fn->resolve_ip == NULL) { VINE_LOGE("No resolve_ip() defined"); + disc_handle->plugin_fn->deinit(plugin_handle); + disc_handle->plugin_handle = NULL; return VINE_ERROR_OPERATION_FAILED; } - vine_disc_error error = disc_handle->plugin_fn->resolve_ip(plugin_handle, + error = disc_handle->plugin_fn->resolve_ip(plugin_handle, _vine_service_get_type(service), _vine_service_get_name(service), _vine_service_get_host_name(service), _vine_service_get_iface_name(service)); if (error != VINE_DISC_ERROR_NONE) { @@ -650,6 +672,7 @@ vine_error_e __vine_disc_plugin_cancel_resolve_ip(vine_disc_h disc, vine_service void *plugin_handle = disc_handle->plugin_handle; VINE_LOGD("plugin handle[%p]", plugin_handle); + RET_VAL_IF(disc_handle->plugin_fn == NULL, VINE_ERROR_INVALID_OPERATION, "plugin_fn is NULL"); if (disc_handle->plugin_fn->cancel_resolve_ip == NULL) { VINE_LOGE("No resolve_ip() defined"); return VINE_ERROR_OPERATION_FAILED; diff --git a/src/vine-session.cpp b/src/vine-session.cpp index 20528bd..5c48b5c 100755 --- a/src/vine-session.cpp +++ b/src/vine-session.cpp @@ -293,9 +293,6 @@ static void __discovered_cb(vine_disc_h disc, bool available, ret = _vine_service_create(&discovered_service, false); RET_IF(ret != VINE_ERROR_NONE, "Fail to create a service"); - ret = _vine_service_set_disc_handle(discovered_service, disc); - RET_IF(ret != VINE_ERROR_NONE, "Fail to set disc_handle"); - ret = __vine_set_discovered_service(discovered_service, service_type, service_name, host_name, port, attr, iface_name); if (ret != VINE_ERROR_NONE) { @@ -396,8 +393,11 @@ int _vine_session_set_ip_resolved_cb(vine_session_h session, vine_session_s *s = (vine_session_s *)session; vine_disc_h disc_handle; - ret = _vine_service_get_disc_handle(service, VINE_DISCOVERY_METHOD_DNS_SD, &disc_handle); - RET_VAL_IF(ret != VINE_ERROR_NONE, ret, "Fail to _vine_service_get_disc_handle"); + ret = vine_disc_create(s->disc_method, &disc_handle); + RET_VAL_IF(ret != VINE_ERROR_NONE, ret, "Fail to vine_disc_create"); + + ret = _vine_service_set_disc_handle(service, disc_handle); + RET_VAL_IF(ret != VINE_ERROR_NONE, ret, "Fail to set disc_handle"); _vine_service_set_ip_resolved_cb(service, callback, user_data); -- 2.7.4