]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/networkd/bus.c
networkd: Use typedef to keep type names shorter
[people/ms/network.git] / src / networkd / bus.c
index e854f7ba95dc6f6f53609ab3de71ba56c01b53b5..1daa0352604c7af5aecb8bee32ed2f70dd77cf44 100644 (file)
 #############################################################################*/
 
 #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
@@ -124,7 +101,7 @@ int nw_bus_connect(sd_bus* bus, sd_event* loop, struct nw_daemon* daemon) {
        }
 
        // 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;
 
@@ -160,6 +137,7 @@ int nw_bus_register_implementation(sd_bus* bus,
        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) {
@@ -169,5 +147,32 @@ int nw_bus_register_implementation(sd_bus* bus,
                }
        }
 
+       // 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;
 }