Skip to content

Commit

Permalink
Get DBus to work
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jan 17, 2024
1 parent b325793 commit 92c576c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
24 changes: 10 additions & 14 deletions applications/display-server/dbusinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include <unistd.h>
#include <liboxide/debug.h>

DbusInterface::DbusInterface(QObject* parent) : QObject(parent) {}
DbusInterface::DbusInterface(QObject* parent) : QObject(parent){
// Needed to trick QtDBus into exposing the object
setProperty("__init__", true);
}

void DbusInterface::registerService(){
#ifdef EPAPER
Expand All @@ -17,31 +20,24 @@ void DbusInterface::registerService(){
qFatal("Failed to connect to system bus.");
}
QDBusConnectionInterface* interface = bus.interface();
auto reply = interface->registerService(BLIGHT_SERVICE);
bus.registerService(BLIGHT_SERVICE);
if(!reply.isValid()){
QDBusError ex = reply.error();
qFatal("Unable to register service: %s", ex.message().toStdString().c_str());
}
if(!bus.registerObject("/", this, QDBusConnection::ExportAllContents)){
qFatal("Unable to register interface: %s", bus.lastError().message().toStdString().c_str());
}
if(!bus.objectRegisteredAt("/")){
qFatal("Object not appearing!");
}
if(!bus.registerObject(BLIGHT_SERVICE_PATH, this, QDBusConnection::ExportAllContents)){
qFatal("Unable to register interface: %s", bus.lastError().message().toStdString().c_str());
}
if(!bus.objectRegisteredAt(BLIGHT_SERVICE_PATH)){
qFatal("Object not appearing!");
auto reply = interface->registerService(BLIGHT_SERVICE);
bus.registerService(BLIGHT_SERVICE);
if(!reply.isValid()){
QDBusError ex = reply.error();
qFatal("Unable to register service: %s", ex.message().toStdString().c_str());
}
O_DEBUG("Object registered to " BLIGHT_SERVICE_PATH);
connect(
interface,
&QDBusConnectionInterface::serviceOwnerChanged,
this,
&DbusInterface::serviceOwnerChanged
);
);
O_DEBUG("Connected service to bus");
}

Expand Down
2 changes: 1 addition & 1 deletion applications/display-server/dbusinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "../../shared/liboxide/meta.h"

class DbusInterface : public QObject, public QDBusContext {
class DbusInterface : public QObject, protected QDBusContext {
Q_OBJECT
Q_CLASSINFO("Version", OXIDE_INTERFACE_VERSION)
Q_CLASSINFO("D-Bus Interface", BLIGHT_INTERFACE)
Expand Down
3 changes: 2 additions & 1 deletion applications/display-server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ int main(int argc, char* argv[]){
if(engine.rootObjects().isEmpty()){
qFatal("Failed to load main layout");
}
DbusInterface(qApp).registerService();
DbusInterface interface(qApp);
interface.registerService();
return app.exec();
}
3 changes: 0 additions & 3 deletions applications/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ int main(int argc, char *argv[]){
if(res.isError()){
qFatal("Failed to get connection: %s", res.error().message().toStdString().c_str());
}
if(!res.isValid()){
qFatal("Failed to get connection: Invalid DBus response");
}
auto qfd = res.value();
if(!qfd.isValid()){
qFatal("Failed to get connection: Invalid file descriptor");
Expand Down
1 change: 0 additions & 1 deletion shared/liboxide/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,5 @@
#define OXIDE_SCREENSHOT_INTERFACE OXIDE_SERVICE ".Screenshot"

#define BLIGHT_SERVICE "codes.eeems.blight1"
#define BLIGHT_SERVICE_PATH "/codes/eeems/blight1"
#define BLIGHT_INTERFACE BLIGHT_SERVICE ".Compositor"
/*! @} */

0 comments on commit 92c576c

Please sign in to comment.