#############################################################################*/
#include <stdlib.h>
-#include <string.h>
#include <systemd/sd-bus.h>
#include <systemd/sd-event.h>
#include "bus.h"
#include "daemon.h"
+#include "daemon-bus.h"
#include "logging.h"
-static int nw_bus_daemon_reload(sd_bus_message* m, void* data, sd_bus_error* error) {
- struct nw_daemon* daemon = (struct nw_daemon*)data;
-
- // Reload the daemon
- nw_daemon_reload(daemon);
-
- // Respond with an empty message
- return sd_bus_reply_method_return(m, NULL);
-}
-
-static const sd_bus_vtable daemon_vtable[] = {
- SD_BUS_VTABLE_START(0),
- SD_BUS_METHOD("Reload", SD_BUS_NO_ARGS, SD_BUS_NO_RESULT,
- nw_bus_daemon_reload, SD_BUS_VTABLE_UNPRIVILEGED),
- SD_BUS_VTABLE_END,
-};
-
-const struct nw_bus_implementation daemon_implementation = {
- .path = "/org/ipfire/network1",
- .interface = "org.ipfire.network1",
- .vtables = BUS_VTABLES(daemon_vtable),
-};
-
static int nw_bus_on_connect(sd_bus_message* m, void* data, sd_bus_error* error) {
- struct nw_daemon* daemon = (struct nw_daemon*)data;
+ nw_daemon* daemon = (nw_daemon*)data;
DEBUG("Connected to D-Bus\n");
return 0;
}
-int nw_bus_connect(sd_bus* bus, sd_event* loop, struct nw_daemon* daemon) {
+int nw_bus_connect(sd_bus* bus, sd_event* loop, nw_daemon* daemon) {
int r;
// Create a bus object
}
// Register the implementation
- r = nw_bus_register_implementation(bus, &daemon_implementation, daemon);
+ r = nw_bus_register_implementation(bus, &daemon_bus_impl, daemon);
if (r)
return r;
DEBUG("Registering bus object implementation for path=%s iface=%s\n",
impl->path, impl->interface);
+ // Register vtables
for (const sd_bus_vtable** vtable = impl->vtables; vtable && *vtable; vtable++) {
r = sd_bus_add_object_vtable(bus, NULL, impl->path, impl->interface, *vtable, data);
if (r < 0) {
}
}
+ // Register fallback vtables
+ for (const struct nw_bus_vtable_pair* p = impl->fallback_vtables; p && p->vtable; p++) {
+ r = sd_bus_add_fallback_vtable(bus, NULL, impl->path, impl->interface,
+ p->vtable, p->object_find, data);
+ if (r < 0) {
+ ERROR("Could not register bus path %s with interface %s: %m\n",
+ impl->path, impl->interface);
+ return 1;
+ }
+ }
+
+ // Register the node enumerator
+ if (impl->node_enumerator) {
+ r = sd_bus_add_node_enumerator(bus, NULL, impl->path, impl->node_enumerator, data);
+ if (r < 0) {
+ ERROR("Could not add the node enumerator for %s: %m\n", impl->path);
+ return 1;
+ }
+ }
+
+ // Register any child implementations
+ for (int i = 0; impl->children && impl->children[i]; i++) {
+ r = nw_bus_register_implementation(bus, impl->children[i], data);
+ if (r)
+ return r;
+ }
+
return 0;
}