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);
int nw_bus_connect(sd_bus* bus, sd_event* loop, struct nw_daemon* daemon);
+struct nw_bus_vtable_pair {
+ const sd_bus_vtable* vtable;
+ sd_bus_object_find_t object_find;
+};
+
struct nw_bus_implementation {
const char* path;
const char* interface;
-
const sd_bus_vtable** vtables;
+ const struct nw_bus_vtable_pair* fallback_vtables;
sd_bus_node_enumerator_t node_enumerator;
const struct nw_bus_implementation** children;
};
+#define BUS_FALLBACK_VTABLES(...) ((const struct nw_bus_vtable_pair[]) { __VA_ARGS__, {} })
#define BUS_IMPLEMENTATIONS(...) ((const struct nw_bus_implementation* []) { __VA_ARGS__, NULL })
#define BUS_VTABLES(...) ((const sd_bus_vtable* []){ __VA_ARGS__, NULL })
return 0;
}
+/*
+ Zones
+*/
+
struct nw_zones* nw_daemon_zones(struct nw_daemon* daemon) {
return nw_zones_ref(daemon->zones);
}
+
+struct nw_zone* nw_daemon_get_zone_by_name(struct nw_daemon* daemon, const char* name) {
+ if (!daemon->zones)
+ return NULL;
+
+ return nw_zones_get_by_name(daemon->zones, name);
+}
int nw_daemon_reload(struct nw_daemon* daemon);
+/*
+ Zones
+*/
struct nw_zones* nw_daemon_zones(struct nw_daemon* daemon);
+struct nw_zone* nw_daemon_get_zone_by_name(struct nw_daemon* daemon, const char* name);
#endif /* NETWORKD_DAEMON_H */
return r;
}
+static int nw_zone_object_find(sd_bus* bus, const char* path, const char* interface,
+ void* data, void** found, sd_bus_error* error) {
+ char* name = NULL;
+ int r;
+
+ // Fetch a reference to the daemon
+ struct nw_daemon* daemon = (struct nw_daemon*)data;
+
+ // Decode the path of the requested object
+ r = sd_bus_path_decode(path, "/org/ipfire/network1/zone", &name);
+ if (r <= 0)
+ return 0;
+
+ // Find the zone
+ struct nw_zone* zone = nw_daemon_get_zone_by_name(daemon, name);
+ if (!zone)
+ return 0;
+
+ // Match!
+ *found = zone;
+
+ nw_zone_unref(zone);
+
+ return 1;
+}
+
+static const sd_bus_vtable zone_vtable[] = {
+ SD_BUS_VTABLE_START(0),
+
+ SD_BUS_VTABLE_END
+};
+
const struct nw_bus_implementation zone_bus_impl = {
"/org/ipfire/network1/zone",
"org.ipfire.network1.Zone",
- //.fallback_vtables = BUS_FALLBACK_VTABLES({zone_bus_vtable, nw_zone_object_find}),
+ .fallback_vtables = BUS_FALLBACK_VTABLES({zone_vtable, nw_zone_object_find}),
.node_enumerator = nw_zone_node_enumerator,
};