diff options
author | nicm <nicm> | 2016-10-16 17:55:14 +0000 |
---|---|---|
committer | nicm <nicm> | 2016-10-16 17:55:14 +0000 |
commit | ddc4512d2e0eda6c705e002cb5dbf80719d709e1 (patch) | |
tree | cd9ff99f4b1ccb3e76ab99633d59772ae07c3092 /hooks.c | |
parent | bfe14b531267f3762a518f98b72a3148a134396a (diff) | |
download | rtmux-ddc4512d2e0eda6c705e002cb5dbf80719d709e1.tar.gz rtmux-ddc4512d2e0eda6c705e002cb5dbf80719d709e1.tar.bz2 rtmux-ddc4512d2e0eda6c705e002cb5dbf80719d709e1.zip |
Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.
This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.
A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.
Diffstat (limited to 'hooks.c')
-rw-r--r-- | hooks.c | 64 |
1 files changed, 20 insertions, 44 deletions
@@ -33,7 +33,6 @@ RB_GENERATE_STATIC(hooks_tree, hook, entry, hooks_cmp); static struct hook *hooks_find1(struct hooks *, const char *); static void hooks_free1(struct hooks *, struct hook *); -static void hooks_emptyfn(struct cmd_q *); static int hooks_cmp(struct hook *hook1, struct hook *hook2) @@ -140,28 +139,14 @@ hooks_find(struct hooks *hooks, const char *name) return (hook); } -static void -hooks_emptyfn(struct cmd_q *hooks_cmdq) -{ - struct cmd_q *cmdq = hooks_cmdq->data; - - if (cmdq != NULL) { - if (hooks_cmdq->client_exit >= 0) - cmdq->client_exit = hooks_cmdq->client_exit; - if (!cmdq_free(cmdq)) - cmdq_continue(cmdq); - } - cmdq_free(hooks_cmdq); -} - -int +void hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs, const char *fmt, ...) { struct hook *hook; - struct cmd_q *hooks_cmdq; va_list ap; char *name; + struct cmd_q *new_cmdq, *loop; va_start(ap, fmt); xvasprintf(&name, fmt, ap); @@ -170,34 +155,30 @@ hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs, hook = hooks_find(hooks, name); if (hook == NULL) { free(name); - return (-1); + return; } log_debug("running hook %s", name); - free(name); - hooks_cmdq = cmdq_new(c); - hooks_cmdq->flags |= CMD_Q_NOHOOKS; + new_cmdq = cmdq_get_command(hook->cmdlist, fs, NULL, CMD_Q_NOHOOKS); - if (fs != NULL) - cmd_find_copy_state(&hooks_cmdq->current, fs); - hooks_cmdq->parent = NULL; + for (loop = new_cmdq; loop != NULL; loop = loop->next) + loop->hook = xstrdup(name); + free(name); - cmdq_run(hooks_cmdq, hook->cmdlist, NULL); - cmdq_free(hooks_cmdq); - return (0); + cmdq_append(c, new_cmdq); } -int -hooks_wait(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs, +void +hooks_insert(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs, const char *fmt, ...) { struct hook *hook; - struct cmd_q *hooks_cmdq; va_list ap; char *name; + struct cmd_q *new_cmdq, *loop; if (cmdq->flags & CMD_Q_NOHOOKS) - return (-1); + return; va_start(ap, fmt); xvasprintf(&name, fmt, ap); @@ -206,23 +187,18 @@ hooks_wait(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs, hook = hooks_find(hooks, name); if (hook == NULL) { free(name); - return (-1); + return; } log_debug("running hook %s (parent %p)", name, cmdq); - free(name); - - hooks_cmdq = cmdq_new(cmdq->client); - hooks_cmdq->flags |= CMD_Q_NOHOOKS; - if (fs != NULL) - cmd_find_copy_state(&hooks_cmdq->current, fs); - hooks_cmdq->parent = cmdq; + new_cmdq = cmdq_get_command(hook->cmdlist, fs, NULL, CMD_Q_NOHOOKS); - hooks_cmdq->emptyfn = hooks_emptyfn; - hooks_cmdq->data = cmdq; + for (loop = new_cmdq; loop != NULL; loop = loop->next) + loop->hook = xstrdup(name); + free(name); if (cmdq != NULL) - cmdq->references++; - cmdq_run(hooks_cmdq, hook->cmdlist, NULL); - return (0); + cmdq_insert_after(cmdq, new_cmdq); + else + cmdq_append(NULL, new_cmdq); } |