Skip to content

Commit

Permalink
[mdm] Add attribute and signal to express validity. JB#43758
Browse files Browse the repository at this point in the history
Queries servicesAvailable and technologiesAvailable states to determine
whether the current state is valid. For example, validity will be
established once the initial services and technology lists have been
populated from connman.

Combines the following changes:

1. Add missing notification if technologies disconnect.

In case the services/technologies disconnect (e.g. the library is
disconnected from connman) then this needs to re recorded, so
that a signal can be sent once the services/technologies list has been
reestablished.

2. Move internal state into private class to retain ABI compatibility.

3. Ensure validity signals are sent after settings stabilise.

Update all the values before emitting signals so synchronous signal
handlers don't evaluate objects in intermediate states.
  • Loading branch information
llewelld committed Dec 20, 2018
1 parent d5ca9bf commit 761c03d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
66 changes: 65 additions & 1 deletion libconnman-qt/networkmanager.cpp
Expand Up @@ -50,6 +50,8 @@ class NetworkManager::Private : public QObject
static const QString CellularType;

bool m_registered;
bool m_servicesAvailable;
bool m_technologiesAvailable;

QStringList m_availableServicesOrder;
QStringList m_wifiServicesOrder;
Expand All @@ -60,10 +62,13 @@ class NetworkManager::Private : public QObject
static bool selectSaved(NetworkService *service);
static bool selectAvailable(NetworkService *service);
bool updateWifiConnected(NetworkService *service);
void setServicesAvailable(bool servicesAvailable);
void setTechnologiesAvailable(bool technologiesAvailable);

public:
Private(NetworkManager *parent) :
QObject(parent), m_registered(false), m_connectedWifi(NULL) {}
QObject(parent), m_registered(false), m_servicesAvailable(false),
m_technologiesAvailable(false), m_connectedWifi(NULL) {}
NetworkManager* manager()
{ return (NetworkManager*)parent(); }
void maybeCreateInterfaceProxyLater()
Expand Down Expand Up @@ -362,6 +367,10 @@ void NetworkManager::disconnectFromConnman()

void NetworkManager::disconnectTechnologies()
{
// Update availability and check whether validity changed
bool wasValid = isValid();
m_priv->setTechnologiesAvailable(false);

if (m_proxy) {
disconnect(m_proxy, SIGNAL(TechnologyAdded(QDBusObjectPath,QVariantMap)),
this, SLOT(technologyAdded(QDBusObjectPath,QVariantMap)));
Expand All @@ -377,10 +386,18 @@ void NetworkManager::disconnectTechnologies()
m_technologiesCache.clear();
Q_EMIT technologiesChanged();
}

if (wasValid != isValid()) {
Q_EMIT validChanged();
}
}

void NetworkManager::disconnectServices()
{
// Update availability and check whether validity changed
bool wasValid = isValid();
m_priv->setServicesAvailable(false);

if (m_defaultRoute != m_invalidDefaultRoute) {
m_defaultRoute = m_invalidDefaultRoute;
Q_EMIT defaultRouteChanged(m_defaultRoute);
Expand Down Expand Up @@ -447,6 +464,10 @@ void NetworkManager::disconnectServices()
if (emitCellularServicesChanged) {
Q_EMIT cellularServicesChanged();
}

if (wasValid != isValid()) {
Q_EMIT validChanged();
}
}

void NetworkManager::setupTechnologies()
Expand Down Expand Up @@ -607,6 +628,10 @@ void NetworkManager::updateServices(const ConnmanObjectList &changed, const QLis
}
}

// Update availability and check whether validity changed
bool wasValid = isValid();
m_priv->setServicesAvailable(true);

// Emit signals
if (m_priv->m_connectedWifi != prevConnectedWifi) {
Q_EMIT connectedWifiChanged();
Expand Down Expand Up @@ -641,6 +666,9 @@ void NetworkManager::updateServices(const ConnmanObjectList &changed, const QLis
if (cellularServices.changed) {
Q_EMIT cellularServicesChanged();
}
if (wasValid != isValid()) {
Q_EMIT validChanged();
}
}

void NetworkManager::propertyChanged(const QString &name, const QDBusVariant &value)
Expand Down Expand Up @@ -763,7 +791,15 @@ void NetworkManager::getTechnologiesFinished(QDBusPendingCallWatcher *watcher)
m_technologiesCache.insert(tech->type(), tech);
}

// Update availability and check whether validity changed
bool wasValid = isValid();
m_priv->setTechnologiesAvailable(true);

Q_EMIT technologiesChanged();

if (wasValid != isValid()) {
Q_EMIT validChanged();
}
}

void NetworkManager::getServicesFinished(QDBusPendingCallWatcher *watcher)
Expand Down Expand Up @@ -1134,6 +1170,8 @@ void NetworkManager::setServicesEnabled(bool enabled)
return;
}

bool wasValid = isValid();

m_servicesEnabled = enabled;

if (m_servicesEnabled)
Expand All @@ -1142,6 +1180,10 @@ void NetworkManager::setServicesEnabled(bool enabled)
disconnectServices();

Q_EMIT servicesEnabledChanged();

if (wasValid != isValid()) {
Q_EMIT validChanged();
}
}

bool NetworkManager::technologiesEnabled() const
Expand All @@ -1159,6 +1201,8 @@ void NetworkManager::setTechnologiesEnabled(bool enabled)
return;
}

bool wasValid = isValid();

m_technologiesEnabled = enabled;

if (m_technologiesEnabled)
Expand All @@ -1167,6 +1211,26 @@ void NetworkManager::setTechnologiesEnabled(bool enabled)
disconnectTechnologies();

Q_EMIT technologiesEnabledChanged();

if (wasValid != isValid()) {
Q_EMIT validChanged();
}
}

bool NetworkManager::isValid() const
{
return (!m_servicesEnabled || m_priv->m_servicesAvailable)
&& (!m_technologiesEnabled || m_priv->m_technologiesAvailable);
}

void NetworkManager::Private::setServicesAvailable(bool servicesAvailable)
{
m_servicesAvailable = servicesAvailable;
}

void NetworkManager::Private::setTechnologiesAvailable(bool technologiesAvailable)
{
m_technologiesAvailable = technologiesAvailable;
}

void NetworkManager::resetCountersForType(const QString &type)
Expand Down
4 changes: 4 additions & 0 deletions libconnman-qt/networkmanager.h
Expand Up @@ -45,6 +45,7 @@ class NetworkManager : public QObject

Q_PROPERTY(bool servicesEnabled READ servicesEnabled WRITE setServicesEnabled NOTIFY servicesEnabledChanged)
Q_PROPERTY(bool technologiesEnabled READ technologiesEnabled WRITE setTechnologiesEnabled NOTIFY technologiesEnabledChanged)
Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)

Q_PROPERTY(QString WifiTechnology READ wifiTechnologyPath CONSTANT)
Q_PROPERTY(QString CellularTechnology READ cellularTechnologyPath CONSTANT)
Expand Down Expand Up @@ -92,6 +93,8 @@ class NetworkManager : public QObject
bool technologiesEnabled() const;
void setTechnologiesEnabled(bool enabled);

bool isValid() const;

Q_INVOKABLE void resetCountersForType(const QString &type);

QString wifiTechnologyPath() const;
Expand Down Expand Up @@ -142,6 +145,7 @@ public Q_SLOTS:

void servicesEnabledChanged();
void technologiesEnabledChanged();
void validChanged();

private:
typedef bool (*ServiceSelector)(NetworkService*);
Expand Down

0 comments on commit 761c03d

Please sign in to comment.