*/
VINE_ERROR_NO_READ_DATA = VINE_ERROR|0x06,
/**
+ * Service deregistered by a name conflict or similar problem
+ */
+ VINE_ERROR_SERVICE_DEREGISTERED = VINE_ERROR|0x07,
+ /**
* Rejected by peer
*/
//VINE_ERROR_REJECTED_BY_PEER = VINE_ERROR|0x05,
/**
* @brief Called when service is registered.
+ * @remarks If @a error is VINE_ERROR_SERVICE_DEREGISTERED, It means that
+ * @a service_name is conflicted. The callback will be invoked again
+ * with renamed @a service_name.
* @since_tizen 6.5
* @param[in] session The session handle
* @param[in] service_name The registered service name
DNSServiceErrorType errorCode, const char *name,
const char *regtype, const char *domain, void *context)
{
- VINE_LOGD("Service Registerd. service name[%s] error[%d]", name, errorCode);
+ VINE_LOGD("Service Registerd. service name[%s] error[%d] flags[%d]", name, errorCode, flags);
vine_dns_sd_s *dns_sd_handle = (vine_dns_sd_s *)context;
vine_disc_error error = __convert_dns_sd_error_to_vine_disc_error(errorCode);
+ if (flags == 0)
+ error = VINE_DISC_ERROR_SERVICE_DEREGISTERED;
+
if (event_callbacks.published_cb)
event_callbacks.published_cb(dns_sd_handle,
name, error, dns_sd_handle->user_data);
VINE_DISC_ERROR_OUT_OF_MEMORY,
VINE_DISC_ERROR_NAME_CONFLICT,
VINE_DISC_ERROR_SERVICE_NOT_RUNNING,
+ VINE_DISC_ERROR_SERVICE_DEREGISTERED,
} vine_disc_error;
typedef enum {
VINE_DP_PUBSUB_SD_STATE_SUBSCRIBE = 1 << 2,
};
+#define VINE_DP_PUBSUB_SERVICE_NAME_PREFIX "vine-pubsub"
#define VINE_DP_PUBSUB_RANK_KEY "rank"
#define VINE_DP_PUBSUB_RANK_MAX 53123
#define VINE_DP_PUBSUB_RANK_LEN 6
case VINE_DISC_ERROR_NAME_CONFLICT: // DNS-SD changed the service name
return VINE_ERROR_NAME_CONFLICT;
// TODO: To be determined if which vine error will be returned
+ case VINE_DISC_ERROR_SERVICE_DEREGISTERED:
+ return VINE_ERROR_SERVICE_DEREGISTERED;
case VINE_DISC_ERROR_SERVICE_NOT_RUNNING:
default:
return VINE_ERROR_OPERATION_FAILED;
vine_service_h service;
int ret;
char rank_str[VINE_DP_PUBSUB_RANK_LEN] = {0 , };
+ char service_name[VINE_MAX_SERVICE_NAME_LEN + 1] = {0 , };
ret = vine_service_create(&service);
if (ret != VINE_ERROR_NONE)
mRank = create_rank();
sprintf(rank_str, "%d", mRank);
+ snprintf(service_name, VINE_MAX_SERVICE_NAME_LEN,
+ "%s-%d", VINE_DP_PUBSUB_SERVICE_NAME_PREFIX, mRank);
+
+ vine_service_set_name(service, service_name);
vine_service_add_attribute(service, VINE_DP_PUBSUB_RANK_KEY, (const char *)rank_str);
if (mSdPub == NULL) {
static void __registered_cb(vine_session_h session,
const char *service_name, vine_error_e error, void *user_data)
{
- printf("Service[%s] %s.\n", service_name,
- error == VINE_ERROR_NONE ? "registered" : "registration failure");
+ printf("Service[%s] ", service_name);
+ if (error == VINE_ERROR_NONE)
+ printf("registered. \n");
+ else if (error == VINE_ERROR_SERVICE_DEREGISTERED)
+ printf("deregistered by a name conflict. Service name will be renamed.\n");
+ else
+ printf("registration failure.\n");
}
static bool __print_attr(const char *key, const char *value, void *user_data)