diff mbox series

[BlueZ] mesh: Set global bus earlier

Message ID 20220721080331.790277-1-michal.lowas-rzechonek@silvair.com
State Superseded
Headers show
Series [BlueZ] mesh: Set global bus earlier | expand

Commit Message

MichaƂ Lowas-Rzechonek July 21, 2022, 8:03 a.m. UTC
Some io implementations might want to either make calls to other D-Bus
services, or provide additional objects/interfaces that allow
applications to fine-tune their operation, so allow them to use the bus
even before initializing mesh D-Bus interfaces.
---
 mesh/dbus.c | 10 +++++++++-
 mesh/dbus.h |  1 +
 mesh/main.c |  2 ++
 3 files changed, 12 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/mesh/dbus.c b/mesh/dbus.c
index a7abdc428..4ed477256 100644
--- a/mesh/dbus.c
+++ b/mesh/dbus.c
@@ -21,7 +21,7 @@ 
 #include "mesh/error.h"
 #include "mesh/dbus.h"
 
-static struct l_dbus *dbus;
+static struct l_dbus *dbus = NULL;
 
 struct error_entry {
 	const char *dbus_err;
@@ -75,6 +75,11 @@  struct l_dbus_message *dbus_error(struct l_dbus_message *msg, int err,
 				"%s", error_table[err].default_desc);
 }
 
+void dbus_set_bus(struct l_dbus *bus)
+{
+	dbus = bus;
+}
+
 struct l_dbus *dbus_get_bus(void)
 {
 	return dbus;
@@ -82,6 +87,9 @@  struct l_dbus *dbus_get_bus(void)
 
 bool dbus_init(struct l_dbus *bus)
 {
+	if (dbus != bus)
+		return false;
+
 	/* Network interface */
 	if (!mesh_dbus_init(bus))
 		return false;
diff --git a/mesh/dbus.h b/mesh/dbus.h
index 8f00434d6..ab8b0a2cc 100644
--- a/mesh/dbus.h
+++ b/mesh/dbus.h
@@ -14,6 +14,7 @@ 
 #define DEFAULT_DBUS_TIMEOUT	30
 
 bool dbus_init(struct l_dbus *dbus);
+void dbus_set_bus(struct l_dbus *bus);
 struct l_dbus *dbus_get_bus(void);
 void dbus_append_byte_array(struct l_dbus_message_builder *builder,
 						const uint8_t *data, int len);
diff --git a/mesh/main.c b/mesh/main.c
index dd99c3085..0180c3768 100644
--- a/mesh/main.c
+++ b/mesh/main.c
@@ -278,6 +278,8 @@  int main(int argc, char *argv[])
 		goto done;
 	}
 
+	dbus_set_bus(dbus);
+
 	if (dbus_debug)
 		l_dbus_set_debug(dbus, do_debug, "[DBUS] ", NULL);
 	l_dbus_set_ready_handler(dbus, ready_callback, dbus, NULL);