[PATCH BlueZ] mesh: Allow mesh-io to use dbus when initializing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
---
 mesh/main.c            |  9 ++++-----
 mesh/mesh-io-api.h     |  3 ++-
 mesh/mesh-io-generic.c |  4 +++-
 mesh/mesh-io-unit.c    |  2 +-
 mesh/mesh-io.c         |  5 +++--
 mesh/mesh-io.h         |  3 ++-
 mesh/mesh.c            | 12 +++++++-----
 mesh/mesh.h            |  9 +++++----
 8 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/mesh/main.c b/mesh/main.c
index dd99c3085..74b0f884e 100644
--- a/mesh/main.c
+++ b/mesh/main.c
@@ -76,10 +76,9 @@ static void do_debug(const char *str, void *user_data)
 	l_info("%s%s", prefix, str);
 }
 
-static void mesh_ready_callback(void *user_data, bool success)
+static void mesh_ready_callback(bool success, struct l_dbus *dbus,
+								void *user_data)
 {
-	struct l_dbus *dbus = user_data;
-
 	l_info("mesh_ready_callback");
 	if (!success) {
 		l_error("Failed to start mesh");
@@ -102,8 +101,8 @@ static void request_name_callback(struct l_dbus *dbus, bool success,
 		return;
 	}
 
-	if (!mesh_init(storage_dir, mesh_conf_fname, io_type, io_opts,
-					mesh_ready_callback, dbus)) {
+	if (!mesh_init(dbus, storage_dir, mesh_conf_fname, io_type, io_opts,
+					mesh_ready_callback, NULL)) {
 		l_error("Failed to initialize mesh");
 		l_main_quit();
 	}
diff --git a/mesh/mesh-io-api.h b/mesh/mesh-io-api.h
index 61f79f224..7a50937da 100644
--- a/mesh/mesh-io-api.h
+++ b/mesh/mesh-io-api.h
@@ -11,7 +11,8 @@
 struct mesh_io_private;
 
 typedef bool (*mesh_io_init_t)(struct mesh_io *io, void *opts,
-				mesh_io_ready_func_t cb, void *user_data);
+				struct l_dbus *dbus, mesh_io_ready_func_t cb,
+				void *user_data);
 typedef bool (*mesh_io_destroy_t)(struct mesh_io *io);
 typedef bool (*mesh_io_caps_t)(struct mesh_io *io, struct mesh_io_caps *caps);
 typedef bool (*mesh_io_send_t)(struct mesh_io *io,
diff --git a/mesh/mesh-io-generic.c b/mesh/mesh-io-generic.c
index 6c0b8f0fd..27cb4cf5f 100644
--- a/mesh/mesh-io-generic.c
+++ b/mesh/mesh-io-generic.c
@@ -27,6 +27,7 @@
 #include "mesh/mesh-io.h"
 #include "mesh/mesh-io-api.h"
 #include "mesh/mesh-io-generic.h"
+#include "mesh/dbus.h"
 
 struct mesh_io_private {
 	struct bt_hci *hci;
@@ -40,6 +41,7 @@ struct mesh_io_private {
 	uint16_t interval;
 	bool sending;
 	bool active;
+	struct l_dbus *dbus;
 };
 
 struct pvt_rx_reg {
@@ -429,7 +431,7 @@ static void read_info(int index, void *user_data)
 	hci_init(io);
 }
 
-static bool dev_init(struct mesh_io *io, void *opts,
+static bool dev_init(struct mesh_io *io, void *opts, struct l_dbus *dbus,
 				mesh_io_ready_func_t cb, void *user_data)
 {
 	if (!io || io->pvt)
diff --git a/mesh/mesh-io-unit.c b/mesh/mesh-io-unit.c
index f4b615ac8..a3cba747e 100644
--- a/mesh/mesh-io-unit.c
+++ b/mesh/mesh-io-unit.c
@@ -209,7 +209,7 @@ static void unit_up(void *user_data)
 	l_timeout_create_ms(1, get_name, pvt, NULL);
 }
 
-static bool unit_init(struct mesh_io *io, void *opt,
+static bool unit_init(struct mesh_io *io, void *opt, struct l_dbus *dbus,
 				mesh_io_ready_func_t cb, void *user_data)
 {
 	struct mesh_io_private *pvt;
diff --git a/mesh/mesh-io.c b/mesh/mesh-io.c
index 96891313a..dfd9e43d9 100644
--- a/mesh/mesh-io.c
+++ b/mesh/mesh-io.c
@@ -46,7 +46,8 @@ static bool match_by_type(const void *a, const void *b)
 }
 
 struct mesh_io *mesh_io_new(enum mesh_io_type type, void *opts,
-				mesh_io_ready_func_t cb, void *user_data)
+				struct l_dbus *dbus, mesh_io_ready_func_t cb,
+				void *user_data)
 {
 	const struct mesh_io_api *api = NULL;
 	struct mesh_io *io;
@@ -69,7 +70,7 @@ struct mesh_io *mesh_io_new(enum mesh_io_type type, void *opts,
 	io->type = type;
 	io->api = api;
 
-	if (!api->init(io, opts, cb, user_data))
+	if (!api->init(io, opts, dbus, cb, user_data))
 		goto fail;
 
 	if (!io_list)
diff --git a/mesh/mesh-io.h b/mesh/mesh-io.h
index 80ef3fa3e..8a4b2e8ee 100644
--- a/mesh/mesh-io.h
+++ b/mesh/mesh-io.h
@@ -74,7 +74,8 @@ typedef void (*mesh_io_recv_ext_func_t)(void *user_data,
 typedef void (*mesh_io_ready_func_t)(void *user_data, bool result);
 
 struct mesh_io *mesh_io_new(enum mesh_io_type type, void *opts,
-				mesh_io_ready_func_t cb, void *user_data);
+				struct l_dbus *dbus, mesh_io_ready_func_t cb,
+				void *user_data);
 void mesh_io_destroy(struct mesh_io *io);
 
 bool mesh_io_get_caps(struct mesh_io *io, struct mesh_io_caps *caps);
diff --git a/mesh/mesh.c b/mesh/mesh.c
index 62d650328..1d3451cf4 100644
--- a/mesh/mesh.c
+++ b/mesh/mesh.c
@@ -71,6 +71,7 @@ struct join_data{
 
 struct mesh_init_request {
 	mesh_ready_func_t cb;
+	struct l_dbus *dbus;
 	void *user_data;
 };
 
@@ -173,7 +174,7 @@ static void io_ready_callback(void *user_data, bool result)
 	if (result)
 		node_attach_io_all(mesh.io);
 
-	req->cb(req->user_data, result);
+	req->cb(result, req->dbus, req->user_data);
 
 	l_free(req);
 }
@@ -249,9 +250,9 @@ done:
 	l_settings_free(settings);
 }
 
-bool mesh_init(const char *config_dir, const char *mesh_conf_fname,
-					enum mesh_io_type type, void *opts,
-					mesh_ready_func_t cb, void *user_data)
+bool mesh_init(struct l_dbus *dbus, const char *config_dir,
+		const char *mesh_conf_fname, enum mesh_io_type type, void *opts,
+		mesh_ready_func_t cb, void *user_data)
 {
 	struct mesh_io_caps caps;
 	struct mesh_init_request *req;
@@ -280,9 +281,10 @@ bool mesh_init(const char *config_dir, const char *mesh_conf_fname,
 
 	req = l_new(struct mesh_init_request, 1);
 	req->cb = cb;
+	req->dbus = dbus;
 	req->user_data = user_data;
 
-	mesh.io = mesh_io_new(type, opts, io_ready_callback, req);
+	mesh.io = mesh_io_new(type, opts, dbus, io_ready_callback, req);
 	if (!mesh.io) {
 		l_free(req);
 		return false;
diff --git a/mesh/mesh.h b/mesh/mesh.h
index 0f77ebc58..6050cfa06 100644
--- a/mesh/mesh.h
+++ b/mesh/mesh.h
@@ -21,13 +21,14 @@
 
 enum mesh_io_type;
 
-typedef void (*mesh_ready_func_t)(void *user_data, bool success);
+typedef void (*mesh_ready_func_t)(bool success, struct l_dbus *dbus,
+							void *user_data);
 typedef void (*prov_rx_cb_t)(void *user_data, const uint8_t *data,
 								uint16_t len);
 
-bool mesh_init(const char *config_dir, const char *mesh_conf_fname,
-					enum mesh_io_type type, void *opts,
-					mesh_ready_func_t cb, void *user_data);
+bool mesh_init(struct l_dbus *dus, const char *config_dir,
+		const char *mesh_conf_fname, enum mesh_io_type type, void *opts,
+		mesh_ready_func_t cb, void *user_data);
 void mesh_cleanup(void);
 bool mesh_dbus_init(struct l_dbus *dbus);
 
-- 
2.25.1




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux