void NetworkManager::connectToConnman(QString) { disconnectFromConnman(); m_manager = new Manager("net.connman", "/", QDBusConnection::systemBus(), this); if (!m_manager->isValid()) { pr_dbg() << "D-Bus net.connman.Manager object is invalid. Connman may not be running or is invalid."; delete m_manager; m_manager = NULL; // shouldn't happen but in this case service isn't available if(m_available) emit availabilityChanged(m_available = false); } else { QDBusPendingReply<QVariantMap> props_reply = m_manager->GetProperties(); m_getPropertiesWatcher = new QDBusPendingCallWatcher(props_reply, m_manager); connect(m_getPropertiesWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(getPropertiesReply(QDBusPendingCallWatcher*))); QDBusPendingReply<ConnmanObjectList> techs_reply = m_manager->GetTechnologies(); m_getTechnologiesWatcher = new QDBusPendingCallWatcher(techs_reply, m_manager); connect(m_getTechnologiesWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(getTechnologiesReply(QDBusPendingCallWatcher*))); QDBusPendingReply<ConnmanObjectList> services_reply = m_manager->GetServices(); m_getServicesWatcher = new QDBusPendingCallWatcher(services_reply, m_manager); connect(m_getServicesWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(getServicesReply(QDBusPendingCallWatcher*))); if(!m_available) emit availabilityChanged(m_available = true); pr_dbg() << "Connected"; } }
void NetworkManager::getPropertiesReply(QDBusPendingCallWatcher *call) { Q_ASSERT(call); QDBusPendingReply<QVariantMap> reply = *call; if (reply.isError()) { qDebug() << "Error getPropertiesReply: " << reply.error().message(); disconnectFromConnman(); // TODO: set up timer to reconnect in a bit QTimer::singleShot(10000,this,SLOT(connectToConnman())); } else { m_propertiesCache = reply.value(); emit stateChanged(m_propertiesCache[State].toString()); qDebug() << "State: " << m_propertiesCache["State"].toString(); connect(m_manager, SIGNAL(PropertyChanged(const QString&, const QDBusVariant&)), this, SLOT(propertyChanged(const QString&, const QDBusVariant&))); } }
void NetworkManager::getTechnologiesReply(QDBusPendingCallWatcher *call) { Q_ASSERT(call); pr_dbg() << "Got reply with technolgies"; QDBusPendingReply<ConnmanObjectList> reply = *call; if (reply.isError()) { pr_dbg() << "Error getTechnologiesReply:" << reply.error().message(); disconnectFromConnman(); // TODO: set up timer to reconnect in a bit //QTimer::singleShot(10000,this,SLOT(connectToConnman())); } else { ConnmanObjectList lst = reply.value(); ConnmanObject obj; foreach (obj, lst) { // TODO: consider optimizations NetworkTechnology *tech = new NetworkTechnology(obj.objpath.path(), obj.properties, this); m_technologiesCache.insert(tech->type(), tech); pr_dbg() << "Technology: " << tech->type(); pr_dbg() << "\tConnected:" << tech->connected(); pr_dbg() << "\tPowered:" << tech->powered(); } connect(m_manager, SIGNAL(TechnologyAdded(const QDBusObjectPath &, const QVariantMap &)), this, SLOT(technologyAdded(const QDBusObjectPath &, const QVariantMap &))); connect(m_manager, SIGNAL(TechnologyRemoved(const QDBusObjectPath &)), this, SLOT(technologyRemoved(const QDBusObjectPath &))); emit technologiesChanged(); }
void NetworkManager::getTechnologiesReply(QDBusPendingCallWatcher *call) { Q_ASSERT(call); QDBusPendingReply<ConnmanObjectList> reply = *call; if (reply.isError()) { qDebug() << "Error getTechnologiesReply: " << reply.error().message(); disconnectFromConnman(); // TODO: set up timer to reconnect in a bit //QTimer::singleShot(10000,this,SLOT(connectToConnman())); } else { ConnmanObjectList lst = reply.value(); ConnmanObject obj; foreach (obj, lst) { // TODO: consider optimizations NetworkTechnology *tech = new NetworkTechnology(obj.objpath.path(), obj.properties, this); m_technologiesCache.insert(tech->type(), tech); qDebug() << "From NT: " << tech->type() << " " << tech->connected() << " " << tech->powered(); } if (!m_technologiesCache.isEmpty()) { emit technologiesChanged(m_technologiesCache, QStringList()); } }
void NetworkManager::connectToConnman(QString) { disconnectFromConnman(); m_manager = new NetConnmanManagerInterface("net.connman", "/", QDBusConnection::systemBus(), this); if (!m_manager->isValid()) { delete m_manager; m_manager = NULL; // shouldn't happen but in this case service isn't available if(m_available) emit availabilityChanged(m_available = false); } else { QDBusPendingReply<QVariantMap> props_reply = m_manager->GetProperties(); props_reply.waitForFinished(); if (!props_reply.isError()) { m_propertiesCache = props_reply.value(); emit stateChanged(m_propertiesCache[State].toString()); connect(m_manager, SIGNAL(PropertyChanged(const QString&, const QDBusVariant&)), this, SLOT(propertyChanged(const QString&, const QDBusVariant&))); } setupTechnologies(); setupServices(); if(!m_available) emit availabilityChanged(m_available = true); pr_dbg() << "Connected"; }