daemon: create some objects in dbus

This commit is contained in:
Jussi Kuokkanen 2020-04-04 20:31:17 +03:00
parent 4247583c57
commit eb027a6e2e
2 changed files with 40 additions and 21 deletions

View File

@ -1,42 +1,58 @@
#include <iostream>
#include <QCoreApplication>
#include <QDBusConnection>
#include <QDBusError>
#include <QDBusMetaType>
#include <QDebug>
#include <patterns.hpp>
#include <Plugin.hpp>
#include <Tree.hpp>
#include "AssignableAdaptorFactory.h"
#include "EnumData.h"
#include "Result.h"
#include "ReadableAdaptorFactory.h"
#include "AdaptorFactory.hpp"
//#include "DummyAdaptor.hpp"
using namespace TuxClocker;
using namespace TuxClocker::Device;
using namespace TuxClocker::Plugin;
using namespace mpark::patterns;
int main(int argc, char **argv) {
QCoreApplication a(argc, argv);
auto plugins = Plugin::DevicePlugin::loadPlugins();
auto connection = QDBusConnection::systemBus();
auto plugins = DevicePlugin::loadPlugins();
QVector<QDBusAbstractAdaptor*> adaptors;
QObject root;
if (plugins.has_value()) {
qDebug() << "found " << plugins.value().size() << " plugins";
for (auto &plugin : plugins.value()) {
plugin->foo();
plugin->deviceRootNode();
auto n = plugin->deviceRootNode();
TreeNode<DeviceNode>::preorder(plugin->deviceRootNode(), [](auto val) {std::cout << val.name << "\n";});
TreeNode<DeviceNode>::preorder(plugin->deviceRootNode(), [&](auto nodeVal) {
auto obj = new QObject(&root); // Is destroyed when root goes out of scope
auto objName = QString::fromStdString(nodeVal.name).replace(" ", "");
if_let(pattern(some(arg)) = nodeVal.interface) = [&](auto iface) {
adaptors.append(AdaptorFactory::adaptor(obj, iface).value());
};
connection.registerObject("/" + objName, obj);
});
}
}
/*registerMetatypes();
QObject root;
auto connection = QDBusConnection::systemBus();
registerReadables(&root, connection);
registerAssignables(&root, connection);
//registerReadables(&root, connection);
//registerAssignables(&root, connection);
DummyAdaptor ad(&root);
connection.registerObject("/", &root);
if (!connection.registerService("org.tuxclocker")) {
qDebug() << "unable to register:" << connection.lastError().message();
}*/
}
return a.exec();
}

View File

@ -4,17 +4,19 @@ qt5_dep = dependency('qt5',
boost_dep = dependency('boost', modules : ['system'])
#moc_files = qt5.preprocess(moc_headers : #['ReadableDynamicVariantAdaptor.h',
# 'AssignableEnumAdaptor.h',
# 'AssignableVariantRangeAdaptor.h'],
# dependencies : qt5_dep)
patterns_inc = include_directories('../include/deps/patterns/include/mpark')
moc_files = qt5.preprocess(moc_headers : ['Adaptors.hpp',
'DummyAdaptor.hpp'],
dependencies : qt5_dep)
sources = ['main.cpp']
executable('tuxclockerd',
sources,
moc_files,
override_options : ['cpp_std=c++17'],
include_directories : incdir,
include_directories : [incdir, patterns_inc],
dependencies : [qt5_dep, boost_dep, dl],
link_with : libtuxclocker,
install : true)
@ -22,7 +24,8 @@ executable('tuxclockerd',
# DBus data directory
dbus_data_dir = join_paths(get_option('prefix'), get_option('datadir'), 'dbus-1')
dbus_system_services_dir = join_paths(dbus_data_dir, 'system.d')
install_data('org.tuxclocker.conf', install_dir : dbus_system_services_dir)
dbus_service_dir = join_paths(dbus_data_dir, 'system-services')
install_data('org.tuxclocker.service', install_dir : dbus_service_dir)