void QServiceDiscovery::updateServices() { QMap<QString, QList<QServiceDiscoveryItem*> > oldServiceTypeMap; oldServiceTypeMap = m_serviceItemsMap; // Iterate through all services and update all service types foreach (QServiceList *serviceList, m_serviceLists) { for (int i = 0; i < serviceList->serviceCount(); ++i) { QService *service; service = serviceList->service(i); disconnect(service, SIGNAL(queriesChanged()), this, SLOT(updateServices())); connect(service, SIGNAL(queriesChanged()), this, SLOT(updateServices())); for (int j = 0; j < service->queriesCount(); ++j) { QServiceDiscoveryQuery *query; query = service->query(j); if (!query->serviceType().isEmpty()) { addServiceType(query->serviceType(), query->queryType()); oldServiceTypeMap.remove(query->serviceType()); if (m_running && m_networkReady) { startQuery(query->serviceType()); } } } } } // Iterate trough all item that are left and remove them QMapIterator<QString, QList<QServiceDiscoveryItem*> > i(oldServiceTypeMap); while (i.hasNext()) { i.next(); if (m_running && m_networkReady) { stopQuery(i.key()); } removeServiceType(i.key()); } updateAllServiceTypes(); // now we need to refill all queries with fresh data }
void QConnmanEngine::initialize() { QMutexLocker locker(&mutex); connect(ofonoManager,SIGNAL(modemChanged()),this,SLOT(changedModem())); ofonoNetwork = new QOfonoNetworkRegistrationInterface(ofonoManager->currentModem(),this); ofonoContextManager = new QOfonoDataConnectionManagerInterface(ofonoManager->currentModem(),this); connect(ofonoContextManager,SIGNAL(roamingAllowedChanged(bool)),this,SLOT(reEvaluateCellular())); connect(connmanManager,SIGNAL(servicesChanged(ConnmanMapList, QList<QDBusObjectPath>)), this, SLOT(updateServices(ConnmanMapList, QList<QDBusObjectPath>))); connect(connmanManager,SIGNAL(servicesReady(QStringList)),this,SLOT(servicesReady(QStringList))); connect(connmanManager,SIGNAL(scanFinished()),this,SLOT(finishedScan())); foreach (const QString &servPath, connmanManager->getServices()) { addServiceConfiguration(servPath); } Q_EMIT updateCompleted(); QSettings confFile(QStringLiteral("nemomobile"),QStringLiteral("connectionagent")); inotifyFileDescriptor = ::inotify_init(); inotifyWatcher = ::inotify_add_watch(inotifyFileDescriptor, QFile::encodeName(confFile.fileName()), IN_MODIFY); if (inotifyWatcher > 0) { QSocketNotifier *notifier = new QSocketNotifier(inotifyFileDescriptor, QSocketNotifier::Read, this); connect(notifier, SIGNAL(activated(int)), this, SLOT(inotifyActivated())); }
void NetworkManager::disconnectServices() { if (m_manager) { disconnect(m_manager, SIGNAL(ServicesChanged(ConnmanObjectList,QList<QDBusObjectPath>)), this, SLOT(updateServices(ConnmanObjectList,QList<QDBusObjectPath>))); disconnect(m_manager, SIGNAL(SavedServicesChanged(ConnmanObjectList)), this, SLOT(updateSavedServices(ConnmanObjectList))); } Q_FOREACH (NetworkService *service, m_servicesCache) service->deleteLater(); m_servicesCache.clear(); if (m_defaultRoute != m_invalidDefaultRoute) { m_defaultRoute = m_invalidDefaultRoute; Q_EMIT defaultRouteChanged(m_defaultRoute); } if (!m_servicesOrder.isEmpty()) { m_servicesOrder.clear(); Q_EMIT servicesChanged(); } if (!m_savedServicesOrder.isEmpty()) { m_savedServicesOrder.clear(); Q_EMIT savedServicesChanged(); } }
void NetworkManager::setupServices() { if (!m_available) return; connect(m_manager, SIGNAL(ServicesChanged(ConnmanObjectList,QList<QDBusObjectPath>)), this, SLOT(updateServices(ConnmanObjectList,QList<QDBusObjectPath>))); connect(m_manager, SIGNAL(SavedServicesChanged(ConnmanObjectList)), this, SLOT(updateSavedServices(ConnmanObjectList))); QDBusPendingReply<ConnmanObjectList> reply = m_manager->GetServices(); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(getServicesFinished(QDBusPendingCallWatcher*))); reply = m_manager->GetSavedServices(); watcher = new QDBusPendingCallWatcher(reply, this); connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(getSavedServicesFinished(QDBusPendingCallWatcher*))); }
void QConnmanEngine::initialize() { QMutexLocker locker(&mutex); connect(ofonoManager,SIGNAL(modemChanged()),this,SLOT(changedModem())); ofonoNetwork = new QOfonoNetworkRegistrationInterface(ofonoManager->currentModem(),this); ofonoContextManager = new QOfonoDataConnectionManagerInterface(ofonoManager->currentModem(),this); connect(ofonoContextManager,SIGNAL(roamingAllowedChanged(bool)),this,SLOT(reEvaluateCellular())); connect(connmanManager,SIGNAL(servicesChanged(ConnmanMapList,QList<QDBusObjectPath>)), this, SLOT(updateServices(ConnmanMapList,QList<QDBusObjectPath>))); connect(connmanManager,SIGNAL(servicesReady(QStringList)),this,SLOT(servicesReady(QStringList))); connect(connmanManager,SIGNAL(scanFinished()),this,SLOT(finishedScan())); foreach (const QString &servPath, connmanManager->getServices()) { addServiceConfiguration(servPath); } Q_EMIT updateCompleted(); }
void QConnmanEngine::initialize() { connect(connmanManager,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), this,SLOT(propertyChangedContext(QString,QString,QDBusVariant))); connect(connmanManager,SIGNAL(servicesChanged(ConnmanMapList, QList<QDBusObjectPath>)), this, SLOT(updateServices(ConnmanMapList, QList<QDBusObjectPath>))); foreach (const QString &techPath, connmanManager->getTechnologies()) { QConnmanTechnologyInterface *tech; tech = new QConnmanTechnologyInterface(techPath, this); connect(tech,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), this,SLOT(technologyPropertyChangedContext(QString,QString,QDBusVariant))); } foreach (const QString &servPath, connmanManager->getServices()) { addServiceConfiguration(servPath); } // Get current list of access points. getConfigurations(); }
static Boolean __SCNetworkSetEstablishDefaultConfigurationForInterfaces(SCNetworkSetRef set, CFArrayRef interfaces, Boolean excludeHidden) { CFSetRef excluded = NULL; CFIndex i; CFIndex n = 0; Boolean ok = TRUE; CFArrayRef services; SCNetworkSetPrivateRef setPrivate = (SCNetworkSetPrivateRef)set; Boolean updated = FALSE; Boolean updatedIFs = FALSE; #if TARGET_OS_IPHONE CFArrayRef orphans = NULL; CFArrayRef sets; sets = SCNetworkSetCopyAll(setPrivate->prefs); if (sets != NULL) { if (CFArrayGetCount(sets) == 1) { services = SCNetworkSetCopyServices(set); if (services != NULL) { n = CFArrayGetCount(services); CFRelease(services); } if ((n == 0) && CFEqual(set, CFArrayGetValueAtIndex(sets, 0))) { // after a "Reset Network Settings" we need to find (and // add back) any VPN services that were orphaned. orphans = SCNetworkServiceCopyAll(setPrivate->prefs); } } CFRelease(sets); } #endif // TARGET_OS_IPHONE // copy network services services = copyServices(set); // copy network interfaces to be excluded excluded = copyExcludedInterfaces(setPrivate->prefs); #if !TARGET_OS_IPHONE // look for interfaces that should auto-magically be added // to an Ethernet bridge n = (interfaces != NULL) ? CFArrayGetCount(interfaces) : 0; for (i = 0; i < n; i++) { SCBridgeInterfaceRef bridge = NULL; SCNetworkInterfaceRef interface; interface = CFArrayGetValueAtIndex(interfaces, i); if (excludeHidden && skipInterface(interface)) { // if not auto-configure continue; } if ((excluded != NULL) && CFSetContainsValue(excluded, interface)) { // if this interface is a member of a Bond or Bridge continue; } if (__SCNetworkServiceExistsForInterface(services, interface)) { // if this is not a new interface continue; } if (_SCNetworkInterfaceIsBuiltin(interface) && _SCNetworkInterfaceIsThunderbolt(interface) && !isA_SCBridgeInterface(interface)) { // add built-in Thunderbolt interfaces to bridge bridge = copyAutoBridgeInterface(setPrivate->prefs, CFSTR("thunderbolt-bridge")); } if (bridge != NULL) { CFIndex bridgeIndex; CFArrayRef members; CFMutableArrayRef newMembers; CFMutableSetRef newExcluded; CFMutableArrayRef newInterfaces; CFArrayRef newServices; // track the bridge interface (if it's in our list) bridgeIndex = CFArrayGetFirstIndexOfValue(interfaces, CFRangeMake(0, CFArrayGetCount(interfaces)), bridge); // add new member interface members = SCBridgeInterfaceGetMemberInterfaces(bridge); if ((members != NULL) && (CFArrayGetCount(members) > 0)) { newMembers = CFArrayCreateMutableCopy(NULL, 0, members); updated = TRUE; // if we're updating an existing bridge } else { newMembers = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); } CFArrayAppendValue(newMembers, interface); ok = SCBridgeInterfaceSetMemberInterfaces(bridge, newMembers); CFRelease(newMembers); if (!ok) { SC_log(LOG_INFO, "could not update bridge with \"%@\": %s", SCNetworkInterfaceGetLocalizedDisplayName(interface), SCErrorString(SCError())); CFRelease(bridge); continue; } // exclude the new member interface newExcluded = CFSetCreateMutableCopy(NULL, 0, excluded); CFRelease(excluded); CFSetAddValue(newExcluded, interface); excluded = newExcluded; // update the list of interfaces to include the [new or updated] bridge newInterfaces = CFArrayCreateMutableCopy(NULL, 0, interfaces); if (bridgeIndex != kCFNotFound) { CFArraySetValueAtIndex(newInterfaces, bridgeIndex, bridge); } else { CFArrayAppendValue(newInterfaces, bridge); } if (updatedIFs) { CFRelease(interfaces); } interfaces = newInterfaces; updatedIFs = TRUE; // refresh [existing] services newServices = updateServices(services, bridge); if (newServices != NULL) { CFRelease(services); services = newServices; } CFRelease(bridge); } } #endif // !TARGET_OS_IPHONE n = (interfaces != NULL) ? CFArrayGetCount(interfaces) : 0; for (i = 0; i < n; i++) { SCNetworkInterfaceRef interface; CFMutableArrayRef interface_list; interface = CFArrayGetValueAtIndex(interfaces, i); if (excludeHidden && skipInterface(interface)) { // if not auto-configure continue; } if ((excluded != NULL) && CFSetContainsValue(excluded, interface)) { // if this interface is a member of a Bond or Bridge continue; } if (__SCNetworkServiceExistsForInterface(services, interface)) { // if this is not a new interface continue; } interface_list = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); CFArrayAppendValue(interface_list, interface); while (ok && (CFArrayGetCount(interface_list) > 0)) { CFArrayRef protocol_types; interface = CFArrayGetValueAtIndex(interface_list, 0); protocol_types = SCNetworkInterfaceGetSupportedProtocolTypes(interface); if ((protocol_types != NULL) && (CFArrayGetCount(protocol_types) > 0)) { SCNetworkServiceRef service; service = SCNetworkServiceCreate(setPrivate->prefs, interface); if (service == NULL) { SC_log(LOG_INFO, "could not create service for \"%@\": %s", SCNetworkInterfaceGetLocalizedDisplayName(interface), SCErrorString(SCError())); ok = FALSE; goto nextInterface; } ok = SCNetworkServiceEstablishDefaultConfiguration(service); if (!ok) { SC_log(LOG_INFO, "could not estabish default configuration for \"%@\": %s", SCNetworkInterfaceGetLocalizedDisplayName(interface), SCErrorString(SCError())); SCNetworkServiceRemove(service); CFRelease(service); goto nextInterface; } ok = SCNetworkSetAddService(set, service); if (!ok) { SC_log(LOG_INFO, "could not add service for \"%@\": %s", SCNetworkInterfaceGetLocalizedDisplayName(interface), SCErrorString(SCError())); SCNetworkServiceRemove(service); CFRelease(service); goto nextInterface; } CFRelease(service); updated = TRUE; } else { add_supported_interfaces(interface_list, interface); } nextInterface : CFArrayRemoveValueAtIndex(interface_list, 0); } CFRelease(interface_list); } if (updatedIFs) CFRelease(interfaces); if (services != NULL) CFRelease(services); if (excluded != NULL) CFRelease(excluded); #if TARGET_OS_IPHONE if (orphans != NULL) { if (ok && updated) { CFIndex i; CFIndex n = CFArrayGetCount(orphans); for (i = 0; i < n; i++) { SCNetworkServiceRef service; service = CFArrayGetValueAtIndex(orphans, i); if (_SCNetworkServiceIsVPN(service)) { ok = SCNetworkSetAddService(set, service); if (!ok) { break; } } } } CFRelease(orphans); } #endif // TARGET_OS_IPHONE if (ok && !updated) { // if no changes were made _SCErrorSet(kSCStatusOK); } return updated; }
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; }