client: Extend client proxy object's API
PATCH 1/5 client: Extend client proxy object's API
Add Start/Stop operations to the client proxy objects. The framework invokes these operations right after the proxy objects are created or just before the are destroyed, so proxy objects can perform the needed actions like start/stop a service, etc. if they choose to implement these ops.
--- client/dbus-proxy.c | 16 ++++++++++++++++ client/dbus-proxy.h | 2 ++ 2 files changed, 18 insertions(+)
client/dbus-proxy.c +16 -0
@@ -555,6 +555,19 @@ static void proxy_interface_create(const char *path, }l_queue_push_tail (proxy_interfaces, proxy); + +if (!interface_type->ops || !interface_type->ops->start) +continue ; + +if (interface_type->ops->start (proxy)) +continue ; + +if (!command_is_interactive_mode ()) +command_set_exit_status (EXIT_FAILURE ); + +l_main_quit (); + +return ; } }
@@ -562,6 +575,9 @@ static void proxy_interface_destroy(void *data) {struct proxy_interface *proxy = data; +if (proxy->type->ops && proxy->type->ops->stop) + proxy->type->ops->stop (proxy); +l_free (proxy->path);if (proxy->type->ops && proxy->type->ops->destroy)
client/dbus-proxy.h +2 -0
@@ -50,6 +50,8 @@ struct proxy_interface_property {struct proxy_interface_type_ops {void *(*create)(void );void (*destroy)(void *data); +bool (*start)(const struct proxy_interface *proxy); +void (*stop)(const struct proxy_interface *proxy);const char *(*identity)(void *data);void (*display)(const char *margin,const void *data); };
Signature · 1 line
2.13.6
PATCH 2/5 client: Add start/stop ops to agent manager proxy
This guarantees that the agent gets registered only when the agent manager interface is available on dbus.
--- client/agent-manager.c | 51 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-)
client/agent-manager.c +44 -7
@@ -30,6 +30,7 @@#include "agent.h" #include "dbus-proxy.h" #include "agent-manager.h" +#include "command.h" #define IWD_AGENT_MANAGER_PATH "/net/connman/iwd"
@@ -39,6 +40,46 @@ static void check_errors_method_callback(struct l_dbus_message *message,dbus_message_has_error (message); } +static bool agent_manager_start (const struct proxy_interface *proxy) +{ +const char *path; + +if (command_needs_no_agent ()) +return true; + + path =proxy_interface_get_data (proxy); +if (!path) +return false; + +if (!agent_init (path)) +return false; + +proxy_interface_method_call (proxy,"RegisterAgent" ,"o" , + check_errors_method_callback, path); + +return true; +} + +static void agent_manager_stop (const struct proxy_interface *proxy) +{ +const char *path; + +if (command_needs_no_agent ()) +return ; + +if (!proxy) +return ; + + path =proxy_interface_get_data (proxy); +if (!path) +return ; + +proxy_interface_method_call (proxy,"UnregisterAgent" ,"o" , + check_errors_method_callback, path); + +agent_exit (path); +} +bool agent_manager_register_agent (void ) {const char *path;
@@ -81,25 +122,21 @@ bool agent_manager_unregister_agent(void)static void *agent_manager_create (void ) { -char *path =l_strdup_printf ("/agent/%i" ,getpid ()); - -agent_init (path); - -return path; +return l_strdup_printf ("/agent/%i" ,getpid ()); }static void agent_manager_destroy (void *data) {char *path = data; -agent_exit (path); -l_free (path); }static const struct proxy_interface_type_ops agent_manager_ops = { .create = agent_manager_create, .destroy = agent_manager_destroy, + .start = agent_manager_start, + .stop = agent_manager_stop, };static struct proxy_interface_type agent_manager_interface_type = {
Signature · 1 line
2.13.6
PATCH 3/5 client: Remove explicit agent registartion from framework
In reply to Tim KourtThis removes the no longer needed APIs from agent-manager.
--- Makefile.am | 4 ++-- client/agent-manager.c | 41 ----------------------------------------- client/agent-manager.h | 24 ------------------------ client/dbus-proxy.c | 19 ------------------- 4 files changed, 2 insertions(+), 86 deletions(-) delete mode 100644 client/agent-manager.h
Makefile.am +2 -2
@@ -267,7 +267,7 @@ bin_PROGRAMS += client/iwctl client_iwctl_SOURCES = client/main.c \ client/adapter.c \ client/agent.h client/agent.c \ - client/agent-manager.h client/agent-manager.c \ + client/agent-manager.c \ client/ad-hoc.c \ client/ap.c \ client/command.h client/command.c \
@@ -486,7 +486,7 @@ if CLIENT unit_test_client_SOURCES = unit/test-client.c \ client/adapter.c \ client/agent.h client/agent.c \ - client/agent-manager.h client/agent-manager.c \ + client/agent-manager.c \ client/command.h client/command.c \ client/dbus-proxy.h client/dbus-proxy.c \ client/display.h client/display.c \
client/agent-manager.c +0 -41
53 lines not on this page · raw message
client/agent-manager.h deleted +0 -24
@@ -1,24 +0,0 @@ -/* -* -* Wireless daemon for Linux -* -* Copyright (C) 2017-2019 Intel Corporation. All rights reserved. -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 of the License, or (at your option) any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this library; if not, write to the Free Software -* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -* -*/ - -bool agent_manager_register_agent (void ); -bool agent_manager_unregister_agent (void );
client/dbus-proxy.c +0 -19
@@ -27,7 +27,6 @@#include <stdio.h> #include <ell/ell.h> -#include "agent-manager.h" #include "dbus-proxy.h" #include "display.h" #include "command.h"
@@ -732,21 +731,6 @@ static void get_managed_objects_callback(struct l_dbus_message *message,while (l_dbus_message_iter_next_entry (&objects, &path, &object))proxy_interface_create (path, &object); -if (command_needs_no_agent ()) - goto no_agent; - -if (!agent_manager_register_agent ()) { -display_error ("Failed to register Agent.\n" ); - -if (!command_is_interactive_mode ()) -command_set_exit_status (EXIT_FAILURE ); - -l_main_quit (); - -return ; - } - -no_agent:if (!command_is_interactive_mode ()) {command_noninteractive_trigger ();
@@ -861,9 +845,6 @@ bool dbus_proxy_exit(void) {struct interface_type_desc *desc; -if (!command_needs_no_agent ()) -agent_manager_unregister_agent (); -for (desc = __start___interface; desc < __stop___interface; desc++) {if (!desc->exit)continue ;
Signature · 1 line
2.13.6
PATCH 4/5 client: Use full include path for local includes
In reply to Tim Kourt--- client/ad-hoc.c | 8 ++++---- client/adapter.c | 8 ++++---- client/agent-manager.c | 6 +++--- client/agent.c | 8 ++++---- client/ap.c | 8 ++++---- client/command.c | 4 ++-- client/dbus-proxy.c | 8 ++++---- client/device.c | 12 ++++++------ client/display.c | 6 +++--- client/known-networks.c | 10 +++++----- client/main.c | 6 +++--- client/network.c | 6 +++--- client/properties.c | 2 +- client/station.c | 10 +++++----- client/wsc.c | 8 ++++---- 15 files changed, 55 insertions(+), 55 deletions(-)
client/ad-hoc.c +4 -4
@@ -26,10 +26,10 @@#include <ell/ell.h> -#include "command.h" -#include "dbus-proxy.h" -#include "device.h" -#include "display.h" +#include "client/command.h" +#include "client/dbus-proxy.h" +#include "client/device.h" +#include "client/display.h" struct ad_hoc {bool started;
client/adapter.c +4 -4
@@ -26,10 +26,10 @@#include <ell/ell.h> -#include "command.h" -#include "dbus-proxy.h" -#include "display.h" -#include "properties.h" +#include "client/command.h" +#include "client/dbus-proxy.h" +#include "client/display.h" +#include "client/properties.h" struct adapter {bool powered;
client/agent-manager.c +3 -3
@@ -27,9 +27,9 @@#include <ell/ell.h> #include <unistd.h> -#include "agent.h" -#include "dbus-proxy.h" -#include "command.h" +#include "client/agent.h" +#include "client/dbus-proxy.h" +#include "client/command.h" #define IWD_AGENT_MANAGER_PATH "/net/connman/iwd"
client/agent.c +4 -4
@@ -26,10 +26,10 @@#include <ell/ell.h> -#include "agent.h" -#include "dbus-proxy.h" -#include "display.h" -#include "command.h" +#include "client/agent.h" +#include "client/dbus-proxy.h" +#include "client/display.h" +#include "client/command.h" #define IWD_AGENT_INTERFACE "net.connman.iwd.Agent"
client/ap.c +4 -4
@@ -26,10 +26,10 @@#include <ell/ell.h> -#include "command.h" -#include "dbus-proxy.h" -#include "device.h" -#include "display.h" +#include "client/command.h" +#include "client/dbus-proxy.h" +#include "client/device.h" +#include "client/display.h" struct ap {bool started;
client/command.c +2 -2
@@ -31,8 +31,8 @@#include <ell/ell.h> #include <readline/readline.h> -#include "command.h" -#include "display.h" +#include "client/command.h" +#include "client/display.h" static struct l_queue *command_families;static struct l_queue *command_options;
client/dbus-proxy.c +4 -4
@@ -27,10 +27,10 @@#include <stdio.h> #include <ell/ell.h> -#include "dbus-proxy.h" -#include "display.h" -#include "command.h" -#include "properties.h" +#include "client/dbus-proxy.h" +#include "client/display.h" +#include "client/command.h" +#include "client/properties.h" #define IWD_SERVICE "net.connman.iwd"#define IWD_ROOT_PATH "/"
client/device.c +6 -6
@@ -26,12 +26,12 @@#include <ell/ell.h> -#include "command.h" -#include "dbus-proxy.h" -#include "device.h" -#include "display.h" -#include "network.h" -#include "properties.h" +#include "client/command.h" +#include "client/dbus-proxy.h" +#include "client/device.h" +#include "client/display.h" +#include "client/network.h" +#include "client/properties.h" struct device {bool powered;
client/display.c +3 -3
@@ -32,9 +32,9 @@#include <readline/readline.h> #include <ell/ell.h> -#include "agent.h" -#include "command.h" -#include "display.h" +#include "client/agent.h" +#include "client/command.h" +#include "client/display.h" #define IWD_PROMPT COLOR_GREEN "[iwd]" COLOR_OFF "# "#define LINE_LEN 81
client/known-networks.c +5 -5
@@ -29,11 +29,11 @@#include <time.h> #include <ell/ell.h> -#include "command.h" -#include "dbus-proxy.h" -#include "display.h" -#include "properties.h" -#include "network.h" +#include "client/command.h" +#include "client/dbus-proxy.h" +#include "client/display.h" +#include "client/properties.h" +#include "client/network.h" struct known_network {char *identity;
client/main.c +3 -3
@@ -28,9 +28,9 @@#include <signal.h> #include <ell/ell.h> -#include "command.h" -#include "display.h" -#include "dbus-proxy.h" +#include "client/command.h" +#include "client/display.h" +#include "client/dbus-proxy.h" static void signal_handler (uint32_t signo,void *user_data) {
client/network.c +3 -3
@@ -26,9 +26,9 @@#include <ell/ell.h> -#include "dbus-proxy.h" -#include "display.h" -#include "network.h" +#include "client/dbus-proxy.h" +#include "client/display.h" +#include "client/network.h" struct network {bool connected;
client/properties.c +1 -1
@@ -26,7 +26,7 @@#include <ell/ell.h> -#include "properties.h" +#include "client/properties.h" const char *properties_on_off_opts[3 ] = {"on" ,"off" ,NULL };const char *properties_yes_no_opts[3 ] = {"yes" ,"no" ,NULL };
client/station.c +5 -5
@@ -26,11 +26,11 @@#include <ell/ell.h> -#include "command.h" -#include "dbus-proxy.h" -#include "device.h" -#include "network.h" -#include "display.h" +#include "client/command.h" +#include "client/dbus-proxy.h" +#include "client/device.h" +#include "client/network.h" +#include "client/display.h" struct station {bool scanning;
client/wsc.c +4 -4
@@ -26,10 +26,10 @@#include <ell/ell.h> -#include "command.h" -#include "dbus-proxy.h" -#include "device.h" -#include "display.h" +#include "client/command.h" +#include "client/dbus-proxy.h" +#include "client/device.h" +#include "client/display.h" static struct proxy_interface_type wsc_interface_type = { .interface =IWD_WSC_INTERFACE ,
Signature · 1 line
2.13.6
PATCH 5/5 client: Fail in non-interactive mode if iwd service isn’t running
In reply to Tim KourtIn non-interactive mode request the managed object right away and do not wait for the service to appear. This way client can fail right away instead of endlessly waiting in non-interactive mode.
--- client/dbus-proxy.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
client/dbus-proxy.c +16 -10
@@ -740,11 +740,17 @@ static void get_managed_objects_callback(struct l_dbus_message *message,display_enable_cmd_prompt (); } -static void service_appeared_callback (struct l_dbus *dbus,void *user_data) +static void get_managed_objects (void ) { -if (!command_is_interactive_mode ()) - goto get_objects; +l_dbus_method_call (dbus,IWD_SERVICE ,IWD_ROOT_PATH , +L_DBUS_INTERFACE_OBJECT_MANAGER , +"GetManagedObjects" ,NULL , + get_managed_objects_callback, +NULL ,NULL ); +} +static void service_appeared_callback (struct l_dbus *dbus,void *user_data) +{ l_dbus_add_signal_watch(dbus, IWD_SERVICE, IWD_ROOT_PATH, L_DBUS_INTERFACE_OBJECT_MANAGER, "InterfacesAdded", L_DBUS_MATCH_NONE,
@@ -759,12 +765,8 @@ static void service_appeared_callback(struct l_dbus *dbus, void *user_data)L_DBUS_INTERFACE_PROPERTIES ,"PropertiesChanged" ,L_DBUS_MATCH_NONE , properties_changed_callback, NULL); -get_objects: -l_dbus_method_call (dbus,IWD_SERVICE ,IWD_ROOT_PATH , -L_DBUS_INTERFACE_OBJECT_MANAGER , -"GetManagedObjects" ,NULL , - get_managed_objects_callback, -NULL ,NULL ); + +get_managed_objects (); } static void service_disappeared_callback(struct l_dbus *dbus,
@@ -834,9 +836,13 @@ bool dbus_proxy_init(void)l_dbus_set_disconnect_handler (dbus, dbus_disconnect_callback,NULL ,NULL ); -l_dbus_add_service_watch (dbus,IWD_SERVICE , service_appeared_callback, +if (command_is_interactive_mode ()) +l_dbus_add_service_watch (dbus,IWD_SERVICE , + service_appeared_callback, service_disappeared_callback,NULL ,NULL ); +else +get_managed_objects ();return true; }
Signature · 1 line
2.13.6
Re: [PATCH 2/5] client: Add start/stop ops to agent manager proxy
In reply to Tim KourtHi Tim,
Quoted 49 lines · Tim Kourt
This guarantees that the agent gets registered only when the agent manager interface is available on dbus.
--- client/agent-manager.c | 51 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-)client/agent-manager.c +28
-0@@ -30,6 +30,7 @@#include "agent.h" #include "dbus-proxy.h" #include "agent-manager.h" +#include "command.h" #define IWD_AGENT_MANAGER_PATH "/net/connman/iwd"@@ -39,6 +40,46 @@ static void check_errors_method_callback(struct l_dbus_message *message,dbus_message_has_error (message); } +static bool agent_manager_start (const struct proxy_interface *proxy) +{ +const char *path; + +if (command_needs_no_agent ()) +return true; + + path =proxy_interface_get_data (proxy); +if (!path) +return false; + +if (!agent_init (path)) +return false; + +proxy_interface_method_call (proxy,"RegisterAgent" ,"o" , + check_errors_method_callback, path); + +return true; +} + +static void agent_manager_stop (const struct proxy_interface *proxy) +{ +const char *path; + +if (command_needs_no_agent ()) +return ; +
client/agent-manager.c static void check_errors_method_callback(struct l_dbus_message *message, · line 79
Quoted 10 lines
client/agent-manager.c +10
-0+if (!proxy) +return ; + + path =proxy_interface_get_data (proxy); +if (!path) +return ; + +proxy_interface_method_call (proxy,"UnregisterAgent" ,"o" , + check_errors_method_callback, path); +
Trying to unregister the agent when the AgentManager interface goes away is rather pointless, no? Besides, you already have .Release that should have been called by now and no agent should be registered anyway.
Quoted 7 lines
client/agent-manager.c +3
-0+agent_exit (path); +} +bool agent_manager_register_agent (void ) {const char *path;
client/agent-manager.c bool agent_manager_unregister_agent(void) · line 125
Quoted 9 lines
client/agent-manager.c +1
-5@@ -81,25 +122,21 @@ bool agent_manager_unregister_agent(void)static void *agent_manager_create (void ) { -char *path =l_strdup_printf ("/agent/%i" ,getpid ()); - -agent_init (path); - -return path; +return l_strdup_printf ("/agent/%i" ,getpid ());
So why do you need start/stop at all? Can't you just do the ops as part of the create/destroy?
Quoted 10 lines
client/agent-manager.c +0
-2}static void agent_manager_destroy (void *data) {char *path = data; -agent_exit (path); -l_free (path);
client/agent-manager.c bool agent_manager_unregister_agent(void) · line 142
Quoted 10 lines
client/agent-manager.c +2
-0}static const struct proxy_interface_type_ops agent_manager_ops = { .create = agent_manager_create, .destroy = agent_manager_destroy, + .start = agent_manager_start, + .stop = agent_manager_stop, };static struct proxy_interface_type agent_manager_interface_type = {
Regards,
-Denis
Denis Kenzior
AppliedRe: [PATCH 5/5] client: Fail in non-interactive mode if iwd service isn’t running
In reply to Tim KourtHi Tim,
Quoted 7 lines · Tim Kourt
In non-interactive mode request the managed object right away and do not wait for the service to appear. This way client can fail right away instead of endlessly waiting in non-interactive mode.
--- client/dbus-proxy.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
Applied, thanks.
Regards,
-Denis