--- a/cadMousePro-daemon/src/cadMousePro.cpp Tue Aug 20 18:59:39 2019 +0200
+++ b/cadMousePro-daemon/src/cadMousePro.cpp Thu Aug 29 17:57:30 2019 +0200
@@ -17,10 +17,15 @@
*/
#include <iostream>
+#include <QCoreApplication>
+#include <QtDBus/QDBusConnection>
+
#include "CadMouseConfig.h"
#include "CLI.h"
#include "CLIParser.h"
#include "HID.h"
+#include "Daemon.h"
+#include "generated-sources/DBusAdaptor.h" // to generate this file run: d-bus/generate.sh adaptor
int main(int argc, char** argv) {
try {
@@ -34,13 +39,29 @@
if (configuration.daemon) {
// TODO: run D-Bus service
std::wcout << L"will start daemon" << std::endl;
+ std::wcout << L"uid = " << getuid() << std::endl;
+ QCoreApplication qtApplication(argc, argv);
+
+ Daemon* daemon = new Daemon(&qtApplication);
+ DBusAdaptor* dbusAdaptor = new DBusAdaptor(daemon);
+
+ QDBusConnection connection = getuid() ? QDBusConnection::sessionBus() : QDBusConnection::systemBus();
+ //QDBusConnection connection = QDBusConnection::sessionBus();
+ std::wcout << (connection.isConnected() ? L"připojeno" : L"nepřipojeno") << std::endl;
+ std::wcout << connection.name().toStdWString() << std::endl;
+ std::wcout << connection.lastError().message().toStdWString() << std::endl;
+ connection.registerObject("/info/globalcode/mouse/cadMousePro", daemon);
+ connection.registerService("info.globalcode.mouse.cadMousePro");
+
+ return qtApplication.exec();
+
} else {
- HIDDevice mouse(0x256f, 0xc652, nullptr);
+ HIDDevice mouse(Daemon::VENDOR_ID, Daemon::PRODUCT_ID, nullptr);
std::wcout << L"mouse opened" << std::endl;
std::wcout << L"manufacturer: " << mouse.getManufacturerName() << std::endl;
std::wcout << L"product: " << mouse.getProductName() << std::endl;
// std::wcout << L"serial number: " << mouse.getSerialNumber() << std::endl; // throws exception
-
+
mouse.sendFeatureReport(configuration.cadMouseConfig.serialize());
}
@@ -49,7 +70,7 @@
std::wcout << L"HIDException: " << e.getMessage() << std::endl;
return CLI::EXIT_CODE_UNEXPECTED_ERROR;
} catch (const CLIException& e) {
- std::wcout << L"CLIException: " << e.getMessge() << std::endl;
+ std::wcout << L"CLIException: " << e.getMessage() << std::endl;
return e.getExitCode();
}