-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix PackageKit not emitting network state changed signal when stopped #30
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* This file is part of the QPackageKit project | ||
* Copyright (C) 2019 Daniel Nicoletti <[email protected]> | ||
* Copyright (C) 2019 Antonio Larrosa <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Library General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Library General Public License | ||
* along with this library; see the file COPYING.LIB. If not, write to | ||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#include "networkmanagermonitor.h" | ||
|
||
#include <QDBusConnection> | ||
#include <QDBusMessage> | ||
#include <QList> | ||
#include <QVariant> | ||
#include <QString> | ||
|
||
static QString NM_DBUS_SERVICE = QStringLiteral("org.freedesktop.NetworkManager"); | ||
static QString NM_DBUS_PATH = QStringLiteral("/org/freedesktop/NetworkManager"); | ||
static QString NM_DBUS_INTERFACE = QStringLiteral("org.freedesktop.NetworkManager"); | ||
|
||
using namespace PackageKit; | ||
|
||
NetworkManagerMonitor::NetworkManagerMonitor(QObject *parent) | ||
: QObject(parent) | ||
{ | ||
QDBusConnection::systemBus().connect(NM_DBUS_SERVICE, | ||
NM_DBUS_PATH, | ||
NM_DBUS_INTERFACE, | ||
QLatin1String("StateChanged"), | ||
this, SIGNAL(networkStateChanged(uint))); | ||
} | ||
|
||
NetworkManagerMonitor::~NetworkManagerMonitor() | ||
{ | ||
QDBusConnection::systemBus().disconnect(NM_DBUS_SERVICE, | ||
NM_DBUS_PATH, | ||
NM_DBUS_INTERFACE, | ||
QLatin1String("StateChanged"), | ||
this, SIGNAL(networkStateChanged(uint))); | ||
} | ||
|
||
NetworkManagerMonitor::NMState NetworkManagerMonitor::state() | ||
{ | ||
QDBusMessage message = QDBusMessage::createMethodCall(NM_DBUS_SERVICE, | ||
NM_DBUS_PATH, | ||
NM_DBUS_INTERFACE, | ||
QLatin1String("state")); | ||
|
||
QDBusMessage reply = QDBusConnection::systemBus().call(message); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a blocking call. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, if you check the commit, NetworkManagerMonitor::state is not really used. I just added it for completeness (and for debug purposes). If it bothers you that someone might change the code in the future and call it, we can remove the method without any problem |
||
if (reply.arguments().isEmpty()) return NM_STATE_UNKNOWN; | ||
|
||
return static_cast<NMState>(reply.arguments()[0].toUInt()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* This file is part of the QPackageKit project | ||
* Copyright (C) 2019 Daniel Nicoletti <[email protected]> | ||
* Copyright (C) 2019 Antonio Larrosa <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Library General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Library General Public License | ||
* along with this library; see the file COPYING.LIB. If not, write to | ||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef NETWORKMANAGERMONITOR_H | ||
#define NETWORKMANAGERMONITOR_H | ||
|
||
#include <QObject> | ||
|
||
namespace PackageKit { | ||
|
||
class NetworkManagerMonitor : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
enum NMState { | ||
NM_STATE_UNKNOWN = 0, | ||
NM_STATE_ASLEEP = 10, | ||
NM_STATE_DISCONNECTED = 20, | ||
NM_STATE_DISCONNECTING = 30, | ||
NM_STATE_CONNECTING = 40, | ||
NM_STATE_CONNECTED_LOCAL = 50, | ||
NM_STATE_CONNECTED_SITE = 60, | ||
NM_STATE_CONNECTED_GLOBAL = 70 | ||
}; | ||
|
||
NetworkManagerMonitor(QObject *parent = nullptr); | ||
~NetworkManagerMonitor(); | ||
|
||
NMState state(); | ||
|
||
Q_SIGNALS: | ||
void networkStateChanged(uint state); | ||
}; | ||
|
||
}; | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If PK is not running I believe getAllProperties() is likely to wake it up again, thus, talking to NM useless if you don't let it stop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that's the whole point of this PR. We talk to NM because, when PK is not running, it doesn't emit the propertiesChanged signal when the network state changes, so we use NM to have an alternate way to find out we need to update PK properties while PK is not running. Once we got notified the network is up, we call getAllPropertiesIfPackageKitNotRunning, which, as you said, wakes PK so it can give us the updated properties through the usual channels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the check for
!running
is important since that controls that we only do something different than without this PR when PK is stopped. Apart from that, the PR is just signal connections