client: Extend client proxy object's API
PATCH 1/4 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/4 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/4 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 ();
@@ -867,9 +851,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/4 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