dbus: Use new bus name, object and interface
The new interface is a more typical use of DBus, exposing multiple
methods for the functions that are available on the object. The legacy
interface by comparison exposed only one method whose arguments selected
sub-commands to be executed. The legacy approach is not terribly
discoverable and leads to a lack of clarity in the client code. The
legacy approach also obscured the implementation with its use of `struct
mbox_dbus_msg`. The new interface wraps around the existing helpers and
so also deals with `struct mbox_dbus_msg`, but this can at least be
removed in the future.
Change-Id: I7113ed8fd2324bf3fb049d8d20acb3fd7fba6de3
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/mboxd_dbus.c b/mboxd_dbus.c
index 1f47026..2200bed 100644
--- a/mboxd_dbus.c
+++ b/mboxd_dbus.c
@@ -7,7 +7,7 @@
#include "common.h"
#include "dbus.h"
#include "mbox.h"
-#include "mboxd_dbus.h"
+#include "control_dbus.h"
int mboxd_dbus_init(struct mbox_context *context)
{
@@ -27,6 +27,21 @@
return rc;
}
+ rc = control_dbus_init(context);
+ if (rc < 0) {
+ MSG_ERR("Failed to initialise DBus control interface: %s\n",
+ strerror(-rc));
+ return rc;
+ }
+
+ rc = sd_bus_request_name(context->bus, MBOX_DBUS_NAME,
+ SD_BUS_NAME_ALLOW_REPLACEMENT |
+ SD_BUS_NAME_REPLACE_EXISTING);
+ if (rc < 0) {
+ MSG_ERR("Failed to request bus name: %s\n", strerror(-rc));
+ return rc;
+ }
+
rc = sd_bus_get_fd(context->bus);
if (rc < 0) {
MSG_ERR("Failed to get bus fd: %s\n", strerror(-rc));
@@ -40,6 +55,7 @@
void mboxd_dbus_free(struct mbox_context *context)
{
+ control_dbus_free(context);
control_legacy_free(context);
sd_bus_unref(context->bus);
}