All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] main: Add D-Bus Daemon.GetInfo method
@ 2021-04-30 22:01 Andrew Zaborowski
  2021-05-05  8:43 ` Marcel Holtmann
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Zaborowski @ 2021-04-30 22:01 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 3462 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.
---
I'm not happy with the name of the interface and the name of the method
but couldn't find better names that would work well and satisfy
everybody.  "net.connman.IWD" or "net.connman.iwd.Control" are other
names I considered, and as for GetInfo the alternative could be using
properties similar to how org.freedesktop.NetworkManager exposes
Version, org.freedesktop.ColorManager exposes DaemonVersion,
org.gnome.DisplayManager exposes Version{Major,Minor,Micro}, etc.
---
 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] 2+ messages in thread

* Re: [PATCH] main: Add D-Bus Daemon.GetInfo method
  2021-04-30 22:01 [PATCH] main: Add D-Bus Daemon.GetInfo method Andrew Zaborowski
@ 2021-05-05  8:43 ` Marcel Holtmann
  0 siblings, 0 replies; 2+ messages in thread
From: Marcel Holtmann @ 2021-05-05  8:43 UTC (permalink / raw)
  To: iwd

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

Hi Andrew,

> 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.
> ---
> I'm not happy with the name of the interface and the name of the method
> but couldn't find better names that would work well and satisfy
> everybody.  "net.connman.IWD" or "net.connman.iwd.Control" are other
> names I considered, and as for GetInfo the alternative could be using
> properties similar to how org.freedesktop.NetworkManager exposes
> Version, org.freedesktop.ColorManager exposes DaemonVersion,
> org.gnome.DisplayManager exposes Version{Major,Minor,Micro}, etc.
> ---

so I am actually fine with the naming. Lets use net.connman.iwd.Daemon.GetInfo() and StateDirectory and Version as you have in this patch. Just also document it in doc/daemon-api.txt as well and then we can merge this.

Regards

Marcel

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

end of thread, other threads:[~2021-05-05  8:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-30 22:01 [PATCH] main: Add D-Bus Daemon.GetInfo method Andrew Zaborowski
2021-05-05  8:43 ` Marcel Holtmann

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.