agent: utilize IWD_MODULE

Converts agent into an IWD module. This removes the dbus dependency
on agent. Since dbus is initialized very early we can assume
dbus_get_bus is going to return a valid object.
This commit is contained in:
James Prestwood 2019-10-11 10:24:11 -07:00 committed by Denis Kenzior
parent 1382c4724a
commit 046fe96537
3 changed files with 13 additions and 11 deletions

View File

@ -29,6 +29,7 @@
#include <ell/ell.h>
#include "src/dbus.h"
#include "src/agent.h"
#include "src/iwd.h"
static unsigned int next_request_id = 0;
@ -619,8 +620,10 @@ static bool release_agent(void *data, void *user_data)
return true;
}
bool agent_init(struct l_dbus *dbus)
static int agent_init(void)
{
struct l_dbus *dbus = dbus_get_bus();
agents = l_queue_new();
if (!l_dbus_register_interface(dbus, IWD_AGENT_MANAGER_INTERFACE,
@ -628,7 +631,7 @@ bool agent_init(struct l_dbus *dbus)
NULL, false)) {
l_info("Unable to register %s interface",
IWD_AGENT_MANAGER_INTERFACE);
return false;
return -EIO;
}
if (!l_dbus_object_add_interface(dbus, IWD_AGENT_MANAGER_PATH,
@ -637,24 +640,26 @@ bool agent_init(struct l_dbus *dbus)
l_info("Unable to register the agent manager object on '%s'",
IWD_AGENT_MANAGER_PATH);
l_dbus_unregister_interface(dbus, IWD_AGENT_MANAGER_INTERFACE);
return false;
return -EIO;
}
return true;
return 0;
}
bool agent_exit(struct l_dbus *dbus)
static void agent_exit(void)
{
struct l_dbus *dbus = dbus_get_bus();
l_dbus_unregister_object(dbus, IWD_AGENT_MANAGER_PATH);
l_dbus_unregister_interface(dbus, IWD_AGENT_MANAGER_INTERFACE);
l_queue_destroy(agents, agent_free);
agents = NULL;
return true;
}
void agent_shutdown(void)
{
l_queue_foreach_remove(agents, release_agent, NULL);
}
IWD_MODULE(agent, agent_init, agent_exit);

View File

@ -37,8 +37,6 @@ typedef void (*agent_request_user_name_passwd_func_t) (enum agent_result result,
void *user_data);
typedef void (*agent_request_destroy_func_t)(void *user_data);
bool agent_init(struct l_dbus *dbus);
bool agent_exit(struct l_dbus *dbus);
void agent_shutdown(void);
unsigned int agent_request_passphrase(const char *path,

View File

@ -210,12 +210,11 @@ struct l_dbus *dbus_get_bus(void)
bool dbus_init(struct l_dbus *dbus)
{
g_dbus = dbus;
return agent_init(dbus);
return true;
}
void dbus_exit(void)
{
agent_exit(g_dbus);
g_dbus = NULL;
}