update dbus code to be more generic
This commit is contained in:
parent
0f46245230
commit
59f57c38db
@ -74,23 +74,6 @@ HardwareManagerImplementation::HardwareManagerImplementation(QObject *parent) :
|
|||||||
|
|
||||||
if (m_bluetoothLowEnergyManager->available())
|
if (m_bluetoothLowEnergyManager->available())
|
||||||
setResourceEnabled(m_bluetoothLowEnergyManager, true);
|
setResourceEnabled(m_bluetoothLowEnergyManager, true);
|
||||||
|
|
||||||
// Register D-Bus interface for enable/disable hardware resources
|
|
||||||
|
|
||||||
// FIXME: use HardwareManagerDBusService in the source tree instead of direct implementation
|
|
||||||
bool status = QDBusConnection::systemBus().registerService("io.guh.nymead");
|
|
||||||
if (!status) {
|
|
||||||
qCWarning(dcHardware()) << "Failed to register HardwareManager D-Bus service. HardwareManager D-Bus control will not work.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = QDBusConnection::systemBus().registerObject("/io/guh/nymead/HardwareManager", this, QDBusConnection::ExportScriptableContents);
|
|
||||||
if (!status) {
|
|
||||||
qCWarning(dcHardware()) << "Failed to register HardwareManager D-Bus object. HardwareManager D-Bus control will not work.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
qCDebug(dcHardware()) << "HardwareManager D-Bus service set up.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HardwareManagerImplementation::~HardwareManagerImplementation()
|
HardwareManagerImplementation::~HardwareManagerImplementation()
|
||||||
@ -127,15 +110,4 @@ BluetoothLowEnergyManager *HardwareManagerImplementation::bluetoothLowEnergyMana
|
|||||||
return m_bluetoothLowEnergyManager;
|
return m_bluetoothLowEnergyManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareManagerImplementation::EnableBluetooth(const bool &enabled)
|
|
||||||
{
|
|
||||||
qCDebug(dcHardware()) << "Bluetooth hardware resource" << (enabled ? "enabled" : "disabled");
|
|
||||||
|
|
||||||
if (enabled) {
|
|
||||||
setResourceEnabled(m_bluetoothLowEnergyManager, true);
|
|
||||||
} else {
|
|
||||||
setResourceEnabled(m_bluetoothLowEnergyManager, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,6 @@ namespace nymeaserver {
|
|||||||
class HardwareManagerImplementation : public HardwareManager
|
class HardwareManagerImplementation : public HardwareManager
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_CLASSINFO("D-Bus Interface", "io.guh.nymead")
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit HardwareManagerImplementation(QObject *parent = nullptr);
|
explicit HardwareManagerImplementation(QObject *parent = nullptr);
|
||||||
@ -56,9 +55,6 @@ public:
|
|||||||
QtAvahiServiceBrowser *avahiBrowser() override;
|
QtAvahiServiceBrowser *avahiBrowser() override;
|
||||||
BluetoothLowEnergyManager *bluetoothLowEnergyManager() override;
|
BluetoothLowEnergyManager *bluetoothLowEnergyManager() override;
|
||||||
|
|
||||||
// D-Bus method for enable/disable bluetooth support
|
|
||||||
Q_SCRIPTABLE void EnableBluetooth(const bool &enabled);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *m_networkAccessManager = nullptr;
|
QNetworkAccessManager *m_networkAccessManager = nullptr;
|
||||||
|
|
||||||
|
|||||||
@ -75,7 +75,6 @@ HEADERS += nymeacore.h \
|
|||||||
OpenSSL/OpenSSLConnection.hpp \
|
OpenSSL/OpenSSLConnection.hpp \
|
||||||
janusconnector.h \
|
janusconnector.h \
|
||||||
pushbuttondbusservice.h \
|
pushbuttondbusservice.h \
|
||||||
nymeadbusservice.h \
|
|
||||||
hardwaremanagerimplementation.h \
|
hardwaremanagerimplementation.h \
|
||||||
hardware/plugintimermanagerimplementation.h \
|
hardware/plugintimermanagerimplementation.h \
|
||||||
hardware/radio433/radio433brennenstuhl.h \
|
hardware/radio433/radio433brennenstuhl.h \
|
||||||
@ -154,7 +153,6 @@ SOURCES += nymeacore.cpp \
|
|||||||
OpenSSL/OpenSSLConnection.cpp \
|
OpenSSL/OpenSSLConnection.cpp \
|
||||||
janusconnector.cpp \
|
janusconnector.cpp \
|
||||||
pushbuttondbusservice.cpp \
|
pushbuttondbusservice.cpp \
|
||||||
nymeadbusservice.cpp \
|
|
||||||
hardwaremanagerimplementation.cpp \
|
hardwaremanagerimplementation.cpp \
|
||||||
hardware/plugintimermanagerimplementation.cpp \
|
hardware/plugintimermanagerimplementation.cpp \
|
||||||
hardware/radio433/radio433brennenstuhl.cpp \
|
hardware/radio433/radio433brennenstuhl.cpp \
|
||||||
|
|||||||
@ -27,3 +27,8 @@ BluetoothLowEnergyManager::BluetoothLowEnergyManager(QObject *parent) :
|
|||||||
HardwareResource("Bluetooth LE manager", parent)
|
HardwareResource("Bluetooth LE manager", parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BluetoothLowEnergyManager::EnableBluetooth(bool enabled)
|
||||||
|
{
|
||||||
|
setEnabled(enabled);
|
||||||
|
}
|
||||||
|
|||||||
@ -50,6 +50,8 @@ public:
|
|||||||
// Bluetooth device registration methods
|
// Bluetooth device registration methods
|
||||||
virtual BluetoothLowEnergyDevice *registerDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::RandomAddress) = 0;
|
virtual BluetoothLowEnergyDevice *registerDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::RandomAddress) = 0;
|
||||||
virtual void unregisterDevice(BluetoothLowEnergyDevice *bluetoothDevice) = 0;
|
virtual void unregisterDevice(BluetoothLowEnergyDevice *bluetoothDevice) = 0;
|
||||||
|
|
||||||
|
Q_SCRIPTABLE void EnableBluetooth(bool enabled);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BLUETOOTHLOWENERGYMANAGER_H
|
#endif // BLUETOOTHLOWENERGYMANAGER_H
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
#include "loggingcategories.h"
|
#include "loggingcategories.h"
|
||||||
|
|
||||||
HardwareResource::HardwareResource(const QString &name, QObject *parent) :
|
HardwareResource::HardwareResource(const QString &name, QObject *parent) :
|
||||||
QObject(parent),
|
NymeaDBusService("/io/guh/nymead/HardwareManager/" + name, parent),
|
||||||
m_name(name)
|
m_name(name)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -24,8 +24,9 @@
|
|||||||
#define HARDWARERESOURCE_H
|
#define HARDWARERESOURCE_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include "nymeadbusservice.h"
|
||||||
|
|
||||||
class HardwareResource : public QObject
|
class HardwareResource : public NymeaDBusService
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|||||||
@ -71,6 +71,7 @@ HEADERS += devicemanager.h \
|
|||||||
hardwareresource.h \
|
hardwareresource.h \
|
||||||
plugintimer.h \
|
plugintimer.h \
|
||||||
hardwaremanager.h \
|
hardwaremanager.h \
|
||||||
|
nymeadbusservice.h \
|
||||||
|
|
||||||
SOURCES += devicemanager.cpp \
|
SOURCES += devicemanager.cpp \
|
||||||
loggingcategories.cpp \
|
loggingcategories.cpp \
|
||||||
@ -127,6 +128,8 @@ SOURCES += devicemanager.cpp \
|
|||||||
hardwareresource.cpp \
|
hardwareresource.cpp \
|
||||||
plugintimer.cpp \
|
plugintimer.cpp \
|
||||||
hardwaremanager.cpp \
|
hardwaremanager.cpp \
|
||||||
|
nymeadbusservice.cpp \
|
||||||
|
|
||||||
|
|
||||||
# install plugininfo python script for libnymea-dev
|
# install plugininfo python script for libnymea-dev
|
||||||
generateplugininfo.files = $$top_srcdir/plugins/nymea-generateplugininfo
|
generateplugininfo.files = $$top_srcdir/plugins/nymea-generateplugininfo
|
||||||
|
|||||||
@ -20,23 +20,25 @@
|
|||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "nymeadbusservice.h"
|
#include "nymeadbusservice.h"
|
||||||
#include "usermanager.h"
|
|
||||||
#include "loggingcategories.h"
|
#include "loggingcategories.h"
|
||||||
|
|
||||||
namespace nymeaserver {
|
|
||||||
|
|
||||||
QDBusConnection NymeaDBusService::s_connection = QDBusConnection::systemBus();
|
QDBusConnection NymeaDBusService::s_connection = QDBusConnection::systemBus();
|
||||||
|
|
||||||
NymeaDBusService::NymeaDBusService(const QString &objectPath, UserManager *parent) : QObject(parent)
|
NymeaDBusService::NymeaDBusService(const QString &objectPath, QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
bool status = s_connection.registerService("io.guh.nymead");
|
bool status = s_connection.registerService("io.guh.nymead");
|
||||||
if (!status) {
|
if (!status) {
|
||||||
qCWarning(dcApplication()) << "Failed to register D-Bus service.";
|
qCWarning(dcApplication()) << "Failed to register D-Bus service.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
status = s_connection.registerObject(objectPath, this, QDBusConnection::ExportScriptableContents);
|
QString finalObjectPath;
|
||||||
|
foreach (const QString &part, objectPath.split(' ')) {
|
||||||
|
finalObjectPath.append(part.at(0).toUpper());
|
||||||
|
finalObjectPath.append(part.right(part.length() - 1));
|
||||||
|
}
|
||||||
|
status = s_connection.registerObject(finalObjectPath, this, QDBusConnection::ExportScriptableContents);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
qCWarning(dcApplication()) << "Failed to register D-Bus object.";
|
qCWarning(dcApplication()) << "Failed to register D-Bus object:" << finalObjectPath;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_isValid = true;
|
m_isValid = true;
|
||||||
@ -61,4 +63,3 @@ void NymeaDBusService::setBusType(QDBusConnection::BusType busType)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@ -26,18 +26,13 @@
|
|||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <QDBusContext>
|
#include <QDBusContext>
|
||||||
|
|
||||||
|
|
||||||
namespace nymeaserver {
|
|
||||||
|
|
||||||
class UserManager;
|
|
||||||
|
|
||||||
class NymeaDBusService : public QObject, public QDBusContext
|
class NymeaDBusService : public QObject, public QDBusContext
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_CLASSINFO("D-Bus Interface", "io.guh.nymead")
|
Q_CLASSINFO("D-Bus Interface", "io.guh.nymead")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NymeaDBusService(const QString &objectPath, UserManager *parent = nullptr);
|
explicit NymeaDBusService(const QString &objectPath, QObject *parent = nullptr);
|
||||||
|
|
||||||
static void setBusType(QDBusConnection::BusType busType);
|
static void setBusType(QDBusConnection::BusType busType);
|
||||||
|
|
||||||
@ -52,6 +47,5 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // NYMEADBUSSERVICE_H
|
#endif // NYMEADBUSSERVICE_H
|
||||||
Reference in New Issue
Block a user