summaryrefslogtreecommitdiffstats
path: root/src/bus.cpp
blob: 1dadedbd617c132e375bf5d404958623b5922cae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "bus.h"

#include <QtDBus/QtDBus>

static const QString SERVICE_NAME("de.bwlehrpool.beamergui");

Bus* Bus::_instance = nullptr;

Bus::Bus(QObject *parent) : QObject(parent), _hasListener(false)
{

}

bool Bus::registerListener()
{
	if (!QDBusConnection::systemBus().isConnected()) {
		qDebug() << "Cannot connect to system bus";
		return false;
	}
	QDBusServiceWatcher *w = new QDBusServiceWatcher("de.bwlehrpool.beamergui", QDBusConnection::systemBus());
	w->setParent(this);
	connect(w, &QDBusServiceWatcher::serviceRegistered, [=](const QString &service) {
		qDebug() << "Registered Service" << service;
		emit serviceConnected();
	});
	return true;
}

bool Bus::registerService()
{
	if (!QDBusConnection::systemBus().isConnected()) {
		qDebug() << "Cannot connect to system bus";
		return false;
	}
	if (!QDBusConnection::systemBus().registerService(SERVICE_NAME)) {
		qDebug() << QDBusConnection::systemBus().lastError().message();
		return false;
	}
	return true;
}