-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a class to monitor an active connection.
- Loading branch information
Showing
5 changed files
with
103 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "networkmanagerconnection.h" | ||
|
||
#include "leakdetector.h" | ||
#include "logger.h" | ||
|
||
namespace { | ||
Logger logger("NetworkManagerConnection"); | ||
} | ||
|
||
NetworkManagerConnection::NetworkManagerConnection(const QString& path, | ||
QObject* parent) : | ||
QObject(parent), m_interface("org.freedesktop.NetworkManager", path, | ||
"org.freedesktop.NetworkManager.Connection.Active", | ||
QDBusConnection::systemBus(), parent) { | ||
MZ_COUNT_CTOR(NetworkManagerConnection); | ||
|
||
// Get the UUID. | ||
m_uuid = property("Uuid").toString(); | ||
|
||
// Report state changes. | ||
QDBusConnection::systemBus().connect( | ||
"org.freedesktop.NetworkManager", path, | ||
"org.freedesktop.NetworkManager.Connection.Active", "StateChanged", this, | ||
SLOT(dbusStateChanged(uint, uint))); | ||
} | ||
|
||
NetworkManagerConnection::~NetworkManagerConnection() { | ||
MZ_COUNT_DTOR(NetworkManagerConnection); | ||
} | ||
|
||
uint NetworkManagerConnection::state() const { | ||
uint state = property("State").toUInt(); | ||
logger.debug() << "fetching state" << state; | ||
return state; | ||
} | ||
|
||
void NetworkManagerConnection::dbusStateChanged(uint state, uint reason) { | ||
logger.debug() << "state change" << state << "because" << reason; | ||
emit stateChanged(state, reason); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef NETWORKMANAGERCONNECTION_H | ||
#define NETWORKMANAGERCONNECTION_H | ||
|
||
#include <QObject> | ||
#include <QDBusInterface> | ||
|
||
class NetworkManagerConnection final : public QObject { | ||
Q_OBJECT | ||
Q_DISABLE_COPY_MOVE(NetworkManagerConnection) | ||
|
||
public: | ||
NetworkManagerConnection(const QString& path, QObject* parent = nullptr); | ||
~NetworkManagerConnection(); | ||
|
||
const QString& uuid() const { return m_uuid; } | ||
QString path() const { return m_interface.path(); } | ||
uint state() const; | ||
|
||
signals: | ||
void stateChanged(uint state, uint reason); | ||
|
||
private slots: | ||
void dbusStateChanged(uint state, uint reason); | ||
|
||
private: | ||
QDBusInterface m_interface; | ||
QString m_uuid; | ||
}; | ||
|
||
#endif // NETWORKMANAGERCONNECTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters