All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] main: Add D-Bus Daemon.GetInfo method
@ 2021-05-05 22:29 Andrew Zaborowski
  2021-05-05 22:29 ` [PATCH 2/2] doc: Daemon DBus interface documentation Andrew Zaborowski
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Zaborowski @ 2021-05-05 22:29 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2983 bytes --]

Expose the state directory/storage directory path on D-Bus because it
can't be known to clients until IWD runs, and client might need to
occasionally fiddle with the network config files.  While there also
expose the IWD version string, similar to how some other D-Bus services
do.
---
 src/dbus.h |  1 +
 src/main.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/src/dbus.h b/src/dbus.h
index 4936dc6c..b3896108 100644
--- a/src/dbus.h
+++ b/src/dbus.h
@@ -24,6 +24,7 @@
 
 #define IWD_SERVICE "net.connman.iwd"
 
+#define IWD_DAEMON_INTERFACE "net.connman.iwd.Daemon"
 #define IWD_AGENT_MANAGER_INTERFACE "net.connman.iwd.AgentManager"
 #define IWD_WIPHY_INTERFACE "net.connman.iwd.Adapter"
 #define IWD_DEVICE_INTERFACE "net.connman.iwd.Device"
diff --git a/src/main.c b/src/main.c
index 2ee6188c..f65fa7f4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -185,6 +185,16 @@ static void request_name_callback(struct l_dbus *dbus, bool success,
 	if (!l_dbus_object_manager_enable(dbus, "/"))
 		l_warn("Unable to register the ObjectManager");
 
+	if (!l_dbus_object_add_interface(dbus, IWD_BASE_PATH,
+						IWD_DAEMON_INTERFACE,
+						NULL) ||
+			!l_dbus_object_add_interface(dbus, IWD_BASE_PATH,
+						L_DBUS_INTERFACE_PROPERTIES,
+						NULL))
+		l_info("Unable to add %s and/or %s at %s",
+			IWD_DAEMON_INTERFACE, L_DBUS_INTERFACE_PROPERTIES,
+			IWD_BASE_PATH);
+
 	/* TODO: Always request nl80211 for now, ignoring auto-loading */
 	l_genl_request_family(genl, NL80211_GENL_NAME, nl80211_appeared,
 				NULL, NULL);
@@ -194,12 +204,44 @@ fail_exit:
 	l_main_quit();
 }
 
+static struct l_dbus_message *iwd_dbus_get_info(struct l_dbus *dbus,
+						struct l_dbus_message *message,
+						void *user_data)
+{
+	struct l_dbus_message *reply;
+	struct l_dbus_message_builder *builder;
+	L_AUTO_FREE_VAR(char *, storage_dir) = storage_get_path(NULL);
+
+	reply = l_dbus_message_new_method_return(message);
+	builder = l_dbus_message_builder_new(reply);
+	l_dbus_message_builder_enter_array(builder, "{sv}");
+
+	dbus_append_dict_basic(builder, "StateDirectory", 's', storage_dir);
+	dbus_append_dict_basic(builder, "Version", 's', VERSION);
+
+	l_dbus_message_builder_leave_array(builder);
+	l_dbus_message_builder_finalize(builder);
+	l_dbus_message_builder_destroy(builder);
+
+	return reply;
+}
+
+static void iwd_setup_deamon_interface(struct l_dbus_interface *interface)
+{
+	l_dbus_interface_method(interface, "GetInfo", 0, iwd_dbus_get_info,
+				"a{sv}", "", "info");
+}
+
 static void dbus_ready(void *user_data)
 {
 	struct l_dbus *dbus = user_data;
 
 	l_dbus_name_acquire(dbus, "net.connman.iwd", false, false, false,
 				request_name_callback, NULL);
+
+	l_dbus_register_interface(dbus, IWD_DAEMON_INTERFACE,
+					iwd_setup_deamon_interface,
+					NULL, false);
 }
 
 static void dbus_disconnected(void *user_data)
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH 1/2] main: Add D-Bus Daemon.GetInfo method
@ 2021-05-06 21:28 Andrew Zaborowski
  2021-05-06 21:28 ` [PATCH 2/2] doc: Daemon DBus interface documentation Andrew Zaborowski
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Zaborowski @ 2021-05-06 21:28 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2983 bytes --]

Expose the state directory/storage directory path on D-Bus because it
can't be known to clients until IWD runs, and client might need to
occasionally fiddle with the network config files.  While there also
expose the IWD version string, similar to how some other D-Bus services
do.
---
 src/dbus.h |  1 +
 src/main.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/src/dbus.h b/src/dbus.h
index 4936dc6c..b3896108 100644
--- a/src/dbus.h
+++ b/src/dbus.h
@@ -24,6 +24,7 @@
 
 #define IWD_SERVICE "net.connman.iwd"
 
+#define IWD_DAEMON_INTERFACE "net.connman.iwd.Daemon"
 #define IWD_AGENT_MANAGER_INTERFACE "net.connman.iwd.AgentManager"
 #define IWD_WIPHY_INTERFACE "net.connman.iwd.Adapter"
 #define IWD_DEVICE_INTERFACE "net.connman.iwd.Device"
diff --git a/src/main.c b/src/main.c
index 2ee6188c..f65fa7f4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -185,6 +185,16 @@ static void request_name_callback(struct l_dbus *dbus, bool success,
 	if (!l_dbus_object_manager_enable(dbus, "/"))
 		l_warn("Unable to register the ObjectManager");
 
+	if (!l_dbus_object_add_interface(dbus, IWD_BASE_PATH,
+						IWD_DAEMON_INTERFACE,
+						NULL) ||
+			!l_dbus_object_add_interface(dbus, IWD_BASE_PATH,
+						L_DBUS_INTERFACE_PROPERTIES,
+						NULL))
+		l_info("Unable to add %s and/or %s at %s",
+			IWD_DAEMON_INTERFACE, L_DBUS_INTERFACE_PROPERTIES,
+			IWD_BASE_PATH);
+
 	/* TODO: Always request nl80211 for now, ignoring auto-loading */
 	l_genl_request_family(genl, NL80211_GENL_NAME, nl80211_appeared,
 				NULL, NULL);
@@ -194,12 +204,44 @@ fail_exit:
 	l_main_quit();
 }
 
+static struct l_dbus_message *iwd_dbus_get_info(struct l_dbus *dbus,
+						struct l_dbus_message *message,
+						void *user_data)
+{
+	struct l_dbus_message *reply;
+	struct l_dbus_message_builder *builder;
+	L_AUTO_FREE_VAR(char *, storage_dir) = storage_get_path(NULL);
+
+	reply = l_dbus_message_new_method_return(message);
+	builder = l_dbus_message_builder_new(reply);
+	l_dbus_message_builder_enter_array(builder, "{sv}");
+
+	dbus_append_dict_basic(builder, "StateDirectory", 's', storage_dir);
+	dbus_append_dict_basic(builder, "Version", 's', VERSION);
+
+	l_dbus_message_builder_leave_array(builder);
+	l_dbus_message_builder_finalize(builder);
+	l_dbus_message_builder_destroy(builder);
+
+	return reply;
+}
+
+static void iwd_setup_deamon_interface(struct l_dbus_interface *interface)
+{
+	l_dbus_interface_method(interface, "GetInfo", 0, iwd_dbus_get_info,
+				"a{sv}", "", "info");
+}
+
 static void dbus_ready(void *user_data)
 {
 	struct l_dbus *dbus = user_data;
 
 	l_dbus_name_acquire(dbus, "net.connman.iwd", false, false, false,
 				request_name_callback, NULL);
+
+	l_dbus_register_interface(dbus, IWD_DAEMON_INTERFACE,
+					iwd_setup_deamon_interface,
+					NULL, false);
 }
 
 static void dbus_disconnected(void *user_data)
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-06 21:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05 22:29 [PATCH 1/2] main: Add D-Bus Daemon.GetInfo method Andrew Zaborowski
2021-05-05 22:29 ` [PATCH 2/2] doc: Daemon DBus interface documentation Andrew Zaborowski
2021-05-06 16:20   ` Ryan Smith
2021-05-06 20:52     ` Andrew Zaborowski
2021-05-06 21:28 [PATCH 1/2] main: Add D-Bus Daemon.GetInfo method Andrew Zaborowski
2021-05-06 21:28 ` [PATCH 2/2] doc: Daemon DBus interface documentation Andrew Zaborowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.