Hi Tim,
On 11/8/19 1:32 PM, Tim Kourt wrote:
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(-)
diff --git a/client/agent-manager.c b/client/agent-manager.c
index b7d4271b..fb371ea2 100644
--- a/client/agent-manager.c
+++ b/client/agent-manager.c
@@ -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);
+
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.
+ 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());
So why do you need start/stop at all? Can't you just do the ops as part
of the create/destroy?
}
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 = {
Regards,
-Denis