diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2016-04-23 13:59:20 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2016-04-23 13:59:20 +0200 |
commit | 51c3e0b9ec7ff5720d860168b7a5d60fb69226b8 (patch) | |
tree | 09bda734cf84ba120f9d19e18086c7f9936fa250 /src/core/wee-hook.c | |
parent | ae89d28462f5761bba7ccf647eaa7ed4a51f5fb4 (diff) | |
download | weechat-51c3e0b9ec7ff5720d860168b7a5d60fb69226b8.zip |
api: add support of functions in hook_process
Diffstat (limited to 'src/core/wee-hook.c')
-rw-r--r-- | src/core/wee-hook.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index dd33e4bbb..40396facc 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -76,6 +76,8 @@ int real_delete_pending = 0; /* 1 if some hooks must be deleted */ struct pollfd *hook_fd_pollfd = NULL; /* file descriptors for poll() */ int hook_fd_pollfd_count = 0; /* number of file descriptors */ +int hook_process_pending = 0; /* 1 if there are some process to */ + /* run (via fork) */ void hook_process_run (struct t_hook *hook_process); @@ -1405,6 +1407,8 @@ hook_fd_exec () /* perform the poll() */ timeout = hook_timer_get_time_to_next (); + if (hook_process_pending) + timeout = 0; ready = poll (hook_fd_pollfd, num_fd, timeout); if (ready <= 0) return; @@ -1547,7 +1551,10 @@ hook_process_hashtable (struct t_weechat_plugin *plugin, new_hook_process->timeout); } - hook_process_run (new_hook); + if (strncmp (new_hook_process->command, "func:", 5) == 0) + hook_process_pending = 1; + else + hook_process_run (new_hook); return new_hook; @@ -1656,6 +1663,16 @@ hook_process_child (struct t_hook *hook_process) } rc = weeurl_download (ptr_url, HOOK_PROCESS(hook_process, options)); } + else if (strncmp (HOOK_PROCESS(hook_process, command), "func:", 5) == 0) + { + /* run a function (via the hook callback) */ + rc = (int) (HOOK_PROCESS(hook_process, callback)) + (hook_process->callback_pointer, + hook_process->callback_data, + HOOK_PROCESS(hook_process, command), + WEECHAT_HOOK_PROCESS_CHILD, + NULL, NULL); + } else { /* launch command */ @@ -2143,6 +2160,39 @@ error: } /* + * Executes all process commands pending. + */ + +void +hook_process_exec () +{ + struct t_hook *ptr_hook, *next_hook; + + hook_exec_start (); + + ptr_hook = weechat_hooks[HOOK_TYPE_PROCESS]; + while (ptr_hook) + { + next_hook = ptr_hook->next_hook; + + if (!ptr_hook->deleted + && !ptr_hook->running + && (HOOK_PROCESS(ptr_hook, child_pid) == 0)) + { + ptr_hook->running = 1; + hook_process_run (ptr_hook); + ptr_hook->running = 0; + } + + ptr_hook = next_hook; + } + + hook_exec_end (); + + hook_process_pending = 0; +} + +/* * Hooks a connection to a peer (using fork). * * Returns pointer to new hook, NULL if error. |