summaryrefslogtreecommitdiff
path: root/client/input.c
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2013-06-12 16:54:27 +0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-06-13 10:35:06 +0300
commit2e43802f8196be75f14890567076da6663654bf3 (patch)
treee6c6e319cafb6398f3afa884658c4e6e63cb8b63 /client/input.c
parentba7f46b82bbe45f9fe14b4999305bc44be2b25ad (diff)
downloadconnman-2e43802f8196be75f14890567076da6663654bf3.tar.gz
connman-2e43802f8196be75f14890567076da6663654bf3.tar.bz2
connman-2e43802f8196be75f14890567076da6663654bf3.zip
client: Create agent data structure and pass it in function callbacks
Collect the agent variables into a data structure and update the agent functionality to pass this data structure around as function callback user data. Update the agent mode input functionality to store both the callback function and user data pointers. Notice that only only one input callback can be handled at any one time due to the input handling itself and the simple storing of callback and user data pointers.
Diffstat (limited to 'client/input.c')
-rw-r--r--client/input.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/client/input.c b/client/input.c
index 78f68a91..8d6ecca7 100644
--- a/client/input.c
+++ b/client/input.c
@@ -43,8 +43,6 @@ static bool save_input;
static char *saved_line;
static int saved_point;
-static connmanctl_input_func_t *readline_input_handler;
-
void __connmanctl_quit(void)
{
if (main_loop != NULL)
@@ -126,8 +124,7 @@ static gboolean input_handler(GIOChannel *channel, GIOCondition condition,
return FALSE;
}
- if (readline_input_handler != NULL)
- rl_callback_read_char();
+ rl_callback_read_char();
return TRUE;
}
@@ -151,13 +148,24 @@ static char **complete_command(const char *text, int start, int end)
return command;
}
+static struct {
+ connmanctl_input_func_t cb;
+ void *user_data;
+} agent_handler;
+
+static void rl_agent_handler(char *input)
+{
+ agent_handler.cb(input, agent_handler.user_data);
+}
+
void __connmanctl_agent_mode(const char *prompt,
- connmanctl_input_func_t input_handler)
+ connmanctl_input_func_t input_handler, void *user_data)
{
- readline_input_handler = input_handler;
+ agent_handler.cb = input_handler;
+ agent_handler.user_data = user_data;
if (input_handler != NULL)
- rl_callback_handler_install(prompt, input_handler);
+ rl_callback_handler_install(prompt, rl_agent_handler);
else {
rl_set_prompt(prompt);
rl_callback_handler_remove();
@@ -168,8 +176,6 @@ void __connmanctl_agent_mode(const char *prompt,
void __connmanctl_command_mode(void)
{
- readline_input_handler = rl_handler;
-
rl_callback_handler_install("connmanctl> ", rl_handler);
rl_attempted_completion_function = complete_command;
}