Unset ip_resolved_cb on vine_service_destroy 35/256935/1 submit/tizen/20210415.061314
authorCheoleun Moon <chleun.moon@samsung.com>
Thu, 15 Apr 2021 05:50:57 +0000 (14:50 +0900)
committerCheoleun Moon <chleun.moon@samsung.com>
Thu, 15 Apr 2021 05:51:07 +0000 (14:51 +0900)
Change-Id: I3bea15795b67256e9f646113d64f257714728cc8
Signed-off-by: Cheoleun Moon <chleun.moon@samsung.com>
src/include/vine-service.h
src/vine-disc.cpp
src/vine-service.cpp
src/vine-session.cpp

index d82b6d4..86fc28e 100755 (executable)
@@ -53,7 +53,7 @@ const char *_vine_service_get_iface_name(vine_service_h service);
 
 int _vine_service_get_disc_handle(vine_service_h service,
        vine_discovery_method_e disc_method, void **disc_handle);
-int _vine_service_set_ip_resolved_cb(vine_service_h service,
+int _vine_service_set_ip_resolved_cb(vine_service_h service, vine_session_h session,
        vine_session_ip_resolved_cb callback, void *user_data);
 int _vine_service_unset_ip_resolved_cb(vine_service_h service);
 vine_session_ip_resolved_cb _vine_service_ip_resolved_cb(vine_service_h service);
index 330bcaf..60dc8d5 100755 (executable)
@@ -700,6 +700,10 @@ int vine_disc_cancel_resolve_ip(vine_disc_h disc, vine_service_h service)
                return ret;
        }
 
+       vine_disc_s *disc_handle = (vine_disc_s *)disc;
+       disc_handle->event_fd = NULL;
+       disc_handle->service = NULL;
+
        return VINE_ERROR_NONE;
 }
 
index 4419550..095af9f 100755 (executable)
@@ -41,7 +41,9 @@ typedef struct {
        char iface_name[IF_NAMESIZE + 1];
        vine_service_state_e state;
 
+       // For IP resolving
        void *disc_handle;      // Used to resolve IP address
+       vine_session_h ip_resolving_session;
        vine_session_ip_resolved_cb ip_resolved_cb;
        void *ip_resolved_cb_data;
 } vine_service_s;
@@ -71,13 +73,20 @@ int _vine_service_create(vine_service_h *service, bool published)
        RET_VAL_IF(service == NULL, VINE_ERROR_INVALID_PARAMETER, "service is NULL");
 
        vine_service_s *s = new vine_service_s;
+       s->type = published ? VINE_SERVICE_TYPE_PUBLISHED : VINE_SERVICE_TYPE_DISCOVERED;
        memset(s->service_type, 0, VINE_MAX_SERVICE_TYPE_LEN + 1);
        memset(s->service_name, 0, VINE_MAX_SERVICE_NAME_LEN + 1);
        memset(s->host_name, 0, VINE_MAX_HOST_NAME_LEN + 1);
        memset(s->iface_name, 0, IF_NAMESIZE + 1);
        s->port = -1;
+       s->state = VINE_SERVICE_UNAVAILABLE;
+
+       s->disc_handle = NULL;
+       s->ip_resolving_session = NULL;
+       s->ip_resolved_cb = NULL;
+       s->ip_resolved_cb_data = NULL;
+
        *service = s;
-       s->type = published ? VINE_SERVICE_TYPE_PUBLISHED : VINE_SERVICE_TYPE_DISCOVERED;
 
        return VINE_ERROR_NONE;
 }
@@ -87,6 +96,9 @@ int _vine_service_destroy(vine_service_h service)
        RET_VAL_IF(service == NULL, VINE_ERROR_INVALID_PARAMETER, "service is NULL");
        vine_service_s *s = (vine_service_s *)service;
 
+       if (s->ip_resolving_session != NULL && s->ip_resolved_cb != NULL) {
+               vine_session_unset_ip_resolved_cb(s->ip_resolving_session, service);
+       }
        s->attributes.clear();
        delete s;
        return VINE_ERROR_NONE;
@@ -287,16 +299,18 @@ int _vine_service_get_disc_handle(vine_service_h service,
        return VINE_ERROR_NONE;
 }
 
-int _vine_service_set_ip_resolved_cb(vine_service_h service,
+int _vine_service_set_ip_resolved_cb(vine_service_h service, vine_session_h session,
        vine_session_ip_resolved_cb callback, void *user_data)
 {
        RET_VAL_IF(service == NULL, VINE_ERROR_INVALID_PARAMETER, "service is NULL");
+       RET_VAL_IF(session == NULL, VINE_ERROR_INVALID_PARAMETER, "session is NULL");
        RET_VAL_IF(callback == NULL, VINE_ERROR_INVALID_PARAMETER, "callback is NULL");
 
        RET_VAL_IF(!_is_discovered_service(service), VINE_ERROR_INVALID_OPERATION,
                        "only for discovered service");
 
        vine_service_s *s = (vine_service_s *)service;
+       s->ip_resolving_session = session;
        s->ip_resolved_cb = callback;
        s->ip_resolved_cb_data = user_data;
 
@@ -311,6 +325,7 @@ int _vine_service_unset_ip_resolved_cb(vine_service_h service)
                        "only for discovered service");
 
        vine_service_s *s = (vine_service_s *)service;
+       s->ip_resolving_session = NULL;
        s->ip_resolved_cb = NULL;
        s->ip_resolved_cb_data = NULL;
 
index 5c48b5c..a42933a 100755 (executable)
@@ -399,7 +399,7 @@ int _vine_session_set_ip_resolved_cb(vine_session_h session,
        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);
+       _vine_service_set_ip_resolved_cb(service, session, callback, user_data);
 
        ret = vine_disc_resolve_ip(disc_handle, service,
                        __ip_resolved_cb, session,
@@ -422,7 +422,7 @@ int _vine_session_unset_ip_resolved_cb(vine_session_h session,
        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");
 
-       _vine_service_set_ip_resolved_cb(service, NULL, NULL);
+       _vine_service_unset_ip_resolved_cb(service);
 
        ret = vine_disc_cancel_resolve_ip(disc_handle, service);
        RET_VAL_IF(ret != VINE_ERROR_NONE, ret, "Fail to vine_disc_cancel_resolve_ip");