void QServiceDiscovery::deinitializeMdns() { if (m_jdns == NULL) { return; } #ifdef QT_DEBUG DEBUG_TAG(1, "SD", "Deinitializing JDNS"); #endif if (m_running) { if (m_lookupMode == UnicastDNS) { m_unicastLookupTimer->stop(); } removeAllServiceTypes(); m_queryIdItemMap.clear(); m_queryIdServiceMap.clear(); m_queryIdTypeMap.clear(); } m_jdns->deleteLater(); m_jdns = NULL; #if defined(Q_OS_ANDROID) QAndroidJniObject::callStaticMethod<void>("io/machinekit/service/MulticastActivator", "disable"); #endif m_lookupReady = false; // lookup no ready anymore emit lookupReadyChanged(m_lookupReady); }
void ServiceDiscovery::deinitializeMdns(bool cleanup) { if (m_jdns.isNull()) { return; } DEBUG_TAG(1, "SD", "Deinitializing JDNS"); if (m_running && cleanup) { if (m_lookupMode == UnicastDNS) { m_unicastLookupTimer.stop(); } removeAllServiceTypes(); m_queryIdItemMap.clear(); m_queryIdServiceMap.clear(); m_queryIdTypeMap.clear(); } m_jdns->deleteLater(); m_jdns.clear(); #if defined(Q_OS_ANDROID) if (m_lookupMode == MulticastDNS) { QtAndroid::runOnAndroidThreadSync([](){ QAndroidJniObject::callStaticMethod<void>("io/machinekit/service/MulticastActivator", "disable"); }); } #endif if (cleanup) { m_lookupReady = false; // lookup not ready anymore emit lookupReadyChanged(m_lookupReady); } }
bool QServiceDiscovery::initializeMdns() { bool initialized; if (m_jdns != NULL) // already initialized { return true; } #ifdef QT_DEBUG QString mode; if (m_lookupMode == MulticastDNS) { mode = "multicast"; } else { mode = "unicast"; } DEBUG_TAG(1, "SD", "Initializing JDNS " + mode); #endif m_jdns = new QJDns(this); connect(m_jdns, SIGNAL(resultsReady(int,QJDns::Response)), this, SLOT(resultsReady(int,QJDns::Response))); connect(m_jdns, SIGNAL(error(int,QJDns::Error)), this, SLOT(error(int,QJDns::Error))); if (m_lookupMode == MulticastDNS) { #if defined(Q_OS_ANDROID) QAndroidJniObject::callStaticMethod<void>("io/machinekit/service/MulticastActivator", "enable"); #endif initialized = m_jdns->init(QJDns::Multicast, QHostAddress::Any); } else { initialized = m_jdns->init(QJDns::Unicast, QHostAddress::Any); } if (!initialized) // something went wrong { #ifdef QT_DEBUG DEBUG_TAG(1, "SD", "Initializing JDNS failed"); DEBUG_TAG(1, "SD", m_jdns->debugLines()); #endif m_jdns->deleteLater(); m_jdns = NULL; return false; } else { m_lookupReady = true; if (m_lookupMode == UnicastDNS) { updateNameServers(); } if (m_running == true) { updateServices(); if (m_lookupMode == UnicastDNS) { m_unicastLookupTimer->start(); } } emit lookupReadyChanged(m_lookupReady); } return true; }
bool ServiceDiscovery::initializeMdns() { bool initialized; if (!m_jdns.isNull()) // already initialized { return true; } DEBUG_TAG(1, "SD", "Initializing JDNS " << ((m_lookupMode == MulticastDNS) ? "multicast" : "unicast")); m_jdns = new QJDns(this); connect(m_jdns, &QJDns::resultsReady, this, &ServiceDiscovery::resultsReady); connect(m_jdns, &QJDns::error, this, &ServiceDiscovery::error); if (m_lookupMode == MulticastDNS) { #if defined(Q_OS_ANDROID) QtAndroid::runOnAndroidThreadSync([](){ QAndroidJniObject::callStaticMethod<void>("io/machinekit/service/MulticastActivator", "enable", "(Landroid/content/Context;)V", QtAndroid::androidActivity().object<jobject>()); }); #endif initialized = m_jdns->init(QJDns::Multicast, QHostAddress::Any); } else { initialized = m_jdns->init(QJDns::Unicast, QHostAddress::Any); } if (!initialized) // something went wrong { DEBUG_TAG(1, "SD", "Initializing JDNS failed"); DEBUG_TAG(1, "SD", m_jdns->debugLines()); m_jdns->deleteLater(); m_jdns.clear(); return false; } else { m_lookupReady = true; if (m_lookupMode == UnicastDNS) { updateNameServers(); } if (m_running == true) { updateServices(); if (m_lookupMode == UnicastDNS) { m_unicastLookupTimer.start(); } } emit lookupReadyChanged(m_lookupReady); } return true; }