mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-29 21:33:35 -05:00
[commands] Added functionality to break the event loop of a command base
This commit is contained in:
@@ -46,6 +46,8 @@ struct command
|
||||
|
||||
struct commands_base
|
||||
{
|
||||
struct event_base *evbase;
|
||||
command_exit_cb exit_cb;
|
||||
int command_pipe[2];
|
||||
struct event *command_event;
|
||||
struct command *current_cmd;
|
||||
@@ -169,7 +171,7 @@ send_command(struct commands_base *cmdbase, struct command *cmd)
|
||||
* Creates a new command base, needs to be freed by commands_base_free.
|
||||
*/
|
||||
struct commands_base *
|
||||
commands_base_new(struct event_base *evbase)
|
||||
commands_base_new(struct event_base *evbase, command_exit_cb exit_cb)
|
||||
{
|
||||
struct commands_base *cmdbase;
|
||||
int ret;
|
||||
@@ -213,6 +215,9 @@ commands_base_new(struct event_base *evbase)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cmdbase->evbase = evbase;
|
||||
cmdbase->exit_cb = exit_cb;
|
||||
|
||||
return cmdbase;
|
||||
}
|
||||
|
||||
@@ -359,3 +364,23 @@ commands_exec_async(struct commands_base *cmdbase, command_function func, void *
|
||||
return 0;
|
||||
}
|
||||
|
||||
static enum command_state
|
||||
cmdloop_exit(void *arg, int *retval)
|
||||
{
|
||||
struct commands_base *cmdbase = arg;
|
||||
*retval = 0;
|
||||
|
||||
if (cmdbase->exit_cb)
|
||||
cmdbase->exit_cb();
|
||||
|
||||
event_base_loopbreak(cmdbase->evbase);
|
||||
|
||||
return COMMAND_END;
|
||||
}
|
||||
|
||||
void
|
||||
commands_cmdloop_exit(struct commands_base *cmdbase)
|
||||
{
|
||||
commands_exec_sync(cmdbase, cmdloop_exit, NULL, cmdbase);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user