Add io.nymea DBus interface
This commit is contained in:
parent
ea1781ccb4
commit
7527fd7495
@ -2,6 +2,7 @@
|
||||
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
|
||||
<!-- Deprecated legacy service name kept for backwards compatibility. -->
|
||||
<busconfig>
|
||||
<policy user="root">
|
||||
<allow own="io.guh.nymead"/>
|
||||
@ -11,4 +12,3 @@
|
||||
<allow send_destination="io.guh.nymead"/>
|
||||
</policy>
|
||||
</busconfig>
|
||||
|
||||
|
||||
13
data/dbus-1/io.nymea.nymead.conf
Normal file
13
data/dbus-1/io.nymea.nymead.conf
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE busconfig PUBLIC
|
||||
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
|
||||
<busconfig>
|
||||
<policy user="root">
|
||||
<allow own="io.nymea.nymead"/>
|
||||
<allow send_destination="io.nymea.nymead"/>
|
||||
</policy>
|
||||
<policy context="default">
|
||||
<allow send_destination="io.nymea.nymead"/>
|
||||
</policy>
|
||||
</busconfig>
|
||||
@ -2,5 +2,6 @@ usr/bin/nymead
|
||||
data/systemd/nymead.service /lib/systemd/system/
|
||||
data/systemd/influxdb.service.d/nymea-env.conf /etc/systemd/system/influxdb.service.d/
|
||||
data/logrotate/nymead /etc/logrotate.d/
|
||||
data/dbus-1/io.nymea.nymead.conf /etc/dbus-1/system.d/
|
||||
data/dbus-1/io.guh.nymead.conf /etc/dbus-1/system.d/
|
||||
data/dpkg/nymea-upgrade-helper /usr/libexec/
|
||||
|
||||
@ -27,27 +27,72 @@
|
||||
|
||||
NYMEA_LOGGING_CATEGORY(dcDBus, "DBus")
|
||||
|
||||
namespace {
|
||||
const QString kNymeaInterface = QStringLiteral("io.nymea.nymead");
|
||||
const QString kLegacyInterface = QStringLiteral("io.guh.nymead");
|
||||
const QString kNymeaNamespace = QStringLiteral("/io/nymea/");
|
||||
const QString kLegacyNamespace = QStringLiteral("/io/guh/");
|
||||
bool gLegacyServiceWarningLogged = false;
|
||||
bool gLegacyObjectWarningLogged = false;
|
||||
}
|
||||
|
||||
QDBusConnection::BusType NymeaDBusService::s_busType = QDBusConnection::SystemBus;
|
||||
|
||||
NymeaDBusService::NymeaDBusService(const QString &objectPath, QObject *parent):
|
||||
QObject(parent),
|
||||
m_connection(s_busType == QDBusConnection::SystemBus ? QDBusConnection::systemBus() : QDBusConnection::sessionBus())
|
||||
{
|
||||
bool status = m_connection.registerService("io.guh.nymead");
|
||||
bool status = m_connection.registerService(kNymeaInterface);
|
||||
if (!status) {
|
||||
qCWarning(dcDBus()) << "Failed to register D-Bus service.";
|
||||
qCWarning(dcDBus()) << "Failed to register D-Bus service" << kNymeaInterface;
|
||||
return;
|
||||
}
|
||||
QString finalObjectPath;
|
||||
|
||||
bool legacyServiceStatus = m_connection.registerService(kLegacyInterface);
|
||||
if (!legacyServiceStatus) {
|
||||
qCWarning(dcDBus()) << "Failed to register legacy D-Bus service" << kLegacyInterface << "- older clients might not be able to connect.";
|
||||
} else if (!gLegacyServiceWarningLogged) {
|
||||
qCWarning(dcDBus()) << "The D-Bus service" << kLegacyInterface << "is deprecated and kept only for backwards compatibility. Please migrate to" << kNymeaInterface << ".";
|
||||
gLegacyServiceWarningLogged = true;
|
||||
}
|
||||
|
||||
QString normalizedObjectPath;
|
||||
foreach (const QString &part, objectPath.split(' ')) {
|
||||
finalObjectPath.append(part.at(0).toUpper());
|
||||
finalObjectPath.append(part.right(part.length() - 1));
|
||||
normalizedObjectPath.append(part.at(0).toUpper());
|
||||
normalizedObjectPath.append(part.right(part.length() - 1));
|
||||
}
|
||||
status = m_connection.registerObject(finalObjectPath, "io.guh.nymead", parent, QDBusConnection::ExportScriptableSlots);
|
||||
|
||||
QString nymeaObjectPath = normalizedObjectPath;
|
||||
QString legacyObjectPath;
|
||||
bool registerLegacyObject = false;
|
||||
|
||||
if (normalizedObjectPath.contains(kNymeaNamespace)) {
|
||||
legacyObjectPath = normalizedObjectPath;
|
||||
legacyObjectPath.replace(kNymeaNamespace, kLegacyNamespace);
|
||||
registerLegacyObject = true;
|
||||
} else if (normalizedObjectPath.contains(kLegacyNamespace)) {
|
||||
legacyObjectPath = normalizedObjectPath;
|
||||
nymeaObjectPath = normalizedObjectPath;
|
||||
nymeaObjectPath.replace(kLegacyNamespace, kNymeaNamespace);
|
||||
registerLegacyObject = true;
|
||||
}
|
||||
|
||||
status = m_connection.registerObject(nymeaObjectPath, kNymeaInterface, parent, QDBusConnection::ExportScriptableSlots);
|
||||
if (!status) {
|
||||
qCWarning(dcDBus()) << "Failed to register D-Bus object:" << finalObjectPath;
|
||||
qCWarning(dcDBus()) << "Failed to register D-Bus object:" << nymeaObjectPath;
|
||||
return;
|
||||
}
|
||||
|
||||
if (registerLegacyObject) {
|
||||
bool legacyObjectStatus = m_connection.registerObject(legacyObjectPath, kLegacyInterface, parent, QDBusConnection::ExportScriptableSlots);
|
||||
if (!legacyObjectStatus) {
|
||||
qCWarning(dcDBus()) << "Failed to register deprecated legacy D-Bus object:" << legacyObjectPath;
|
||||
} else if (!gLegacyObjectWarningLogged) {
|
||||
qCWarning(dcDBus()) << "The D-Bus interface" << kLegacyInterface << "is deprecated and only kept for backwards compatibility.";
|
||||
gLegacyObjectWarningLogged = true;
|
||||
}
|
||||
}
|
||||
|
||||
m_isValid = true;
|
||||
}
|
||||
|
||||
@ -68,4 +113,3 @@ void NymeaDBusService::setBusType(QDBusConnection::BusType busType)
|
||||
{
|
||||
s_busType = busType;
|
||||
}
|
||||
|
||||
|
||||
@ -29,10 +29,13 @@
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusContext>
|
||||
|
||||
/*! Helper to expose QObject subclasses on D-Bus under the nymea namespace.
|
||||
* The legacy io.guh.nymead interface remains registered for backwards
|
||||
* compatibility but is deprecated and will be removed in a future release. */
|
||||
class NymeaDBusService : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "io.guh.nymead")
|
||||
Q_CLASSINFO("D-Bus Interface", "io.nymea.nymead")
|
||||
|
||||
public:
|
||||
explicit NymeaDBusService(const QString &objectPath, QObject *parent = nullptr);
|
||||
|
||||
@ -45,7 +45,7 @@ bool PushButtonAgent::init(QDBusConnection::BusType busType)
|
||||
return false;
|
||||
}
|
||||
|
||||
QDBusMessage message = QDBusMessage::createMethodCall("io.guh.nymead", "/io/guh/nymead/UserManager", "io.guh.nymead", "RegisterButtonAgent");
|
||||
QDBusMessage message = QDBusMessage::createMethodCall("io.nymea.nymead", "/io/nymea/nymead/UserManager", "io.nymea.nymead", "RegisterButtonAgent");
|
||||
message << QVariant::fromValue(QDBusObjectPath("/nymea/pushbuttonhandler"));
|
||||
QDBusMessage reply = bus.call(message);
|
||||
if (!reply.errorName().isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user