/*! * Attempts to resolve the service in order to determine the host and port necessary to establish a connection. * * If forceMulticast is set to true, QxtDiscoverableService will use a multicast request to resolve the service, * even if the host name appears to be a unicast address (that is, outside the local network). * * \sa resolved * \sa resolveError */ void QxtDiscoverableService::resolve(bool forceMulticast) { if(state() != Unknown && state() != Found) { qWarning() << "QxtDiscoverableService: Cannot resolve service while not in Unknown or Found state"; emit resolveError(0); return; } DNSServiceErrorType err; err = DNSServiceResolve(&(qxt_d().service), (forceMulticast ? kDNSServiceFlagsForceMulticast : 0), qxt_d().iface, serviceName().toUtf8().constData(), fullServiceType().constData(), domain().toUtf8().constData(), QxtDiscoverableServicePrivate::resolveServiceCallback, &qxt_d()); if(err != kDNSServiceErr_NoError) { qxt_d().state = Unknown; emit resolveError(err); } else { qxt_d().state = Resolving; qxt_d().notifier = new QSocketNotifier(DNSServiceRefSockFD(qxt_d().service), QSocketNotifier::Read, this); QObject::connect(qxt_d().notifier, SIGNAL(activated(int)), &qxt_d(), SLOT(socketData())); } }
/*! * Attempts to register the service on the local network. * * If noAutoRename is set to true, registration will fail if another service of the same service type * is already registered with the same service name. Otherwise, the service name will be updated with * a number to make it unique. * * \sa registered * \sa registrationError */ void QxtDiscoverableService::registerService(bool noAutoRename) { if(state() != Unknown) { qWarning() << "QxtDiscoverableService: Cannot register service while not in Unknown state"; emit registrationError(0); return; } QStringList subtypes = qxt_d().serviceSubTypes; subtypes.prepend(fullServiceType()); DNSServiceErrorType err; err = DNSServiceRegister(&(qxt_d().service), noAutoRename ? kDNSServiceFlagsNoAutoRename : 0, qxt_d().iface, serviceName().isEmpty() ? 0 : serviceName().toUtf8().constData(), subtypes.join(",_").toUtf8().constData(), domain().isEmpty() ? 0 : domain().toUtf8().constData(), host().isEmpty() ? 0 : host().toUtf8().constData(), qxt_d().port, 1, // must include null terminator "", QxtDiscoverableServicePrivate::registerServiceCallback, &qxt_d()); if(err != kDNSServiceErr_NoError) { qxt_d().state = Unknown; emit registrationError(err); } else { qxt_d().state = Registering; qxt_d().notifier = new QSocketNotifier(DNSServiceRefSockFD(qxt_d().service), QSocketNotifier::Read, this); QObject::connect(qxt_d().notifier, SIGNAL(activated(int)), &qxt_d(), SLOT(socketData())); } }
void QxtServiceBrowser::browse(/* int iface */) { QStringList subtypes = qxt_d().serviceSubTypes; subtypes.prepend(fullServiceType()); DNSServiceErrorType err; err = DNSServiceBrowse(&(qxt_d().service), 0, qxt_d().iface, subtypes.join(",_").toUtf8().constData(), domain().isEmpty() ? 0 : domain().toUtf8().constData(), QxtServiceBrowserPrivate::browseServiceCallback, &qxt_d()); if(err) { emit browsingFailed(err); } else { qxt_d().notifier = new QSocketNotifier(DNSServiceRefSockFD(qxt_d().service), QSocketNotifier::Read, this); QObject::connect(qxt_d().notifier, SIGNAL(activated(int)), &qxt_d(), SLOT(socketData())); } }