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);
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;
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;
}
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;
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;
"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;
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,
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");