5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1998 - 2008 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcutil/SILC Schedule Interface
24 * The SILC Scheduler is the heart of any application. The scheduler provides
25 * the application's main loop that can handle incoming data, outgoing data,
26 * timeouts and dispatch different kind of tasks.
28 * The SILC Scheduler supports file descriptor based tasks and timeout tasks.
29 * File descriptor tasks are tasks that perform some operation over the
30 * specified file descriptor. These include network connections, for example.
31 * The timeout tasks are timeouts that are executed after the specified
32 * timeout has elapsed.
34 * The SILC Scheduler is designed to be the sole main loop of the application
35 * so that the application does not need any other main loop. However,
36 * SILC Scheduler does support running the scheduler only one iteration, so
37 * that the scheduler does not block, and thus providing a possiblity that some
38 * external main loop is run over the SILC Scheduler.
40 * Typical application first initializes the scheduler and then register
41 * the very first tasks to the scheduler and then run the scheduler. After
42 * the scheduler's run function returns the application is considered to be
45 * On Windows systems the SILC Scheduler is too designed to work as the main
46 * loop of the GUI application. It can handle all Windows messages and
47 * it dispatches them from the scheduler, and thus makes it possible to
48 * create GUI applications. The scheduler can also handle all kinds of
49 * WIN32 handles, this includes sockets created by the SILC Net API routines,
50 * WSAEVENT handle objects created by Winsock2 routines and arbitrary
51 * WIN32 HANDLE objects.
53 * The SILC Scheduler supports multi-threads as well. The actual scheduler
54 * must be run in single-thread but other threads may register new tasks
55 * and unregister old tasks. However, it is enforced that the actual
56 * task is always run in the main thread. The scheduler is context based
57 * which makes it possible to allocate several schedulers for one application.
58 * Since the scheduler must be run in single-thread, a multi-threaded
59 * application could be created by allocating own scheduler for each of the
60 * worker threads. Each scheduler in worker thread should be a child
61 * scheduler created from the main thread's parent schedule.
65 #ifndef SILCSCHEDULE_H
66 #define SILCSCHEDULE_H
68 /****s* silcutil/SilcScheduleAPI/SilcSchedule
72 * typedef struct SilcScheduleStruct *SilcSchedule;
76 * This context is the actual Scheduler and is allocated by
77 * the silc_schedule_init funtion. The context is given as argument
78 * to all silc_schedule_* functions. It must be freed by the
79 * silc_schedule_uninit function.
82 typedef struct SilcScheduleStruct *SilcSchedule;
84 /****s* silcutil/SilcScheduleAPI/SilcTask
88 * typedef struct SilcTaskStruct *SilcTask;
92 * This object represents one task in the scheduler. It is allocated
93 * by the silc_schedule_task_add function and freed by one of the
94 * silc_schedule_task_del* functions.
97 typedef struct SilcTaskStruct *SilcTask;
99 /****d* silcutil/SilcScheduleAPI/SilcTaskEvent
103 * typedef enum { ... } SilcTaskEvent;
107 * SILC Task event types. The event type indicates the occurred
108 * event of the task. This type will be given as argument to the
109 * SilcTaskCallback function to indicate the event for the caller.
110 * The SILC_TASK_READ and SILC_TASK_WRITE may be set by the caller
111 * of the silc_schedule_set_listen_fd, if the caller needs to control
112 * the events for the task. The SILC_TASK_EXPIRE is set always only
113 * by the scheduler when timeout expires for timeout task. The
114 * SILC_TASK_INTERRUPT is set for signal callback.
119 SILC_TASK_READ = 0x0001, /* Reading */
120 SILC_TASK_WRITE = 0x0002, /* Writing */
121 SILC_TASK_EXPIRE = 0x0004, /* Timeout */
122 SILC_TASK_INTERRUPT = 0x0008, /* Signal */
126 /****f* silcutil/SilcScheduleAPI/SilcTaskCallback
130 * typedef void (*SilcTaskCallback)(SilcSchedule schedule,
132 * SilcTaskEvent type, SilcUInt32 fd,
137 * The task callback function. This function will be called by the
138 * scheduler when some event of the task is performed. For example,
139 * when data is available from the connection this will be called.
141 * The `schedule' is the scheduler context, the `type' is the indicated
142 * event, the `fd' is the file descriptor of the task and the `context'
143 * is a caller specified context. If multiple events occurred this
144 * callback is called separately for all events. The `app_context'
145 * is application specific context that was given as argument to the
146 * silc_schedule_init function. If the task is timeout task then `fd'
149 * To specify task callback function in the application using the
150 * SILC_TASK_CALLBACK macro is recommended.
152 * The callback should not perform lenghty or blocking operations as
153 * this would also block all other waiting tasks. The task callback
154 * should either handle the operation fast or issue an asynchronous
155 * call (like to register 0 timeout task) to handle it later.
158 typedef void (*SilcTaskCallback)(SilcSchedule schedule, void *app_context,
159 SilcTaskEvent type, SilcUInt32 fd,
162 /****f* silcutil/SilcScheduleAPI/SilcTaskEventCallback
166 * typedef void (*SilcTaskEventCallback)(SilcSchedule schedule,
168 * SilcTask task, void *context,
173 * Task callback for event tasks added with silc_schedule_task_add_event.
174 * The callback of this type is called when an event task is signalled.
175 * The signal is delivered to all that have connected to the event.
177 * The `task' is the event task. The `context' is the context given as
178 * argument to silc_schedule_event_connect. The `schedule' is the
179 * scheduler given as argument to silc_schedule_event_connect.
181 * If FALSE is returned in this callback function the signal delivery to
182 * other connected entities is stopped. Normally, TRUE is returned.
183 * If the `task' is deleted in this callback, the signal delivery is also
186 * To specify task event callback function in the application using the
187 * SILC_TASK_EVENT_CALLBACK macro is recommended.
190 typedef SilcBool (*SilcTaskEventCallback)(SilcSchedule schedule,
192 SilcTask task, void *context,
195 /****f* silcutil/SilcScheduleAPI/SilcTaskNotifyCb
199 * typedef void (*SilcTaskNotifyCb)(SilcSchedule schedule,
200 * SilcBool added, SilcTask task,
201 * SilcBool fd_task, SilcUInt32 fd,
202 * SilcTaskEvent event,
203 * long seconds, long useconds,
208 * Task notify callback. Callback of this type can be set to scheduler
209 * by calling silc_schedule_set_notify and will be called whenever new
210 * task is added or old task is removed. If `added' is TRUE then `task'
211 * is added to scheduler. If `added' is FALSE then `task' will be removed
212 * from the scheduler. If `fd_task' is TRUE the `task' is file descriptor
213 * task and has `fd' is its file descriptor. If `fd_task' is FALSE then
214 * the task is timeout task and `seconds' and `useconds' specify the
215 * timeout. The `context' is the context given to silc_schedule_set_notify.
219 * The `schedule' is locked while this callback is called. This means that
220 * new tasks cannot be added or removed inside this callback.
222 * When timeout task expires this callback is not called. This is called
223 * only when task is explicitly deleted from the scheduler. Note that,
224 * when timeout task expires it is removed from the scheduler and `task'
225 * will become invalid.
227 * If fd task changes its events, this will be called as if it was a new
228 * task with different `event' mask.
231 typedef void (*SilcTaskNotifyCb)(SilcSchedule schedule,
232 SilcBool added, SilcTask task,
233 SilcBool fd_task, SilcUInt32 fd,
235 long seconds, long useconds,
240 /****d* silcutil/SilcScheduleAPI/SILC_ALL_TASKS
244 * #define SILC_ALL_TASKS ...
248 * Marks for all tasks in the scheduler. This can be passed to
249 * silc_schedule_task_del function to delete all tasks at once.
253 #define SILC_ALL_TASKS ((SilcTask)1)
256 /****d* silcutil/SilcScheduleAPI/SILC_TASK_CALLBACK
260 * #define SILC_TASK_CALLBACK ...
264 * Generic macro to declare task callback functions. This defines a
265 * function with name `func' as a task callback function.
269 #define SILC_TASK_CALLBACK(func) \
270 void func(SilcSchedule schedule, void *app_context, SilcTaskEvent type, \
271 SilcUInt32 fd, void *context)
274 /****d* silcutil/SilcScheduleAPI/SILC_TASK_EVENT_CALLBACK
278 * #define SILC_TASK_EVENT_CALLBACK ...
282 * Generic macro to declare event task callback functions. This defines a
283 * function with name `func' as a event task callback function.
287 #define SILC_TASK_EVENT_CALLBACK(func) \
288 SilcBool func(SilcSchedule schedule, void *app_context, \
289 SilcTask task, void *context, va_list va)
295 #include "silcschedule_i.h"
297 /****f* silcutil/SilcScheduleAPI/silc_schedule_init
301 * SilcSchedule silc_schedule_init(int max_tasks, void *app_context,
302 * SilcStack stack, SilcSchedule parent);
306 * Initializes the scheduler. This returns the scheduler context or NULL
307 * on error. The `app_context' is application specific context that is
308 * delivered to all task callbacks. The caller must free that context.
310 * The `max_tasks' is the maximum number of file descriptor and socket
311 * tasks in the scheduler. Set value to 0 to use default. Operating
312 * system will enforce the final limit. On some operating systems the
313 * limit can be significantly increased when this function is called in
314 * priviliged mode (as super user).
316 * If `parent' is non-NULL it will be the parent of the new scheduler.
317 * If it is NULL this will create a new parent scheduler. If `parent'
318 * is already a child scheduler, this will create a new child to the
319 * child's parent. Even if `parent' is non-NULL the new child scheduler
320 * is still independent scheduler and will run independently of its
321 * parent. However, each child and parent will share event tasks
322 * added with silc_schedule_task_add_event.
324 * If `stack' is non-NULL all memory allocation for the scheduler is done
325 * from the `stack'. Scheduler's stack may be retrieved by calling
326 * silc_schedule_get_stack. A stack is created for scheduler always even
327 * if `stack' is NULL. If it is non-NULL the created stack is a child
328 * stack using `stack' as its parent. This means that memory allocated
329 * by the scheduler will be returned to the `stack' when scheduler is
333 SilcSchedule silc_schedule_init(int max_tasks, void *app_context,
334 SilcStack stack, SilcSchedule parent);
336 /****f* silcutil/SilcScheduleAPI/silc_schedule_uninit
340 * SilcBool silc_schedule_uninit(SilcSchedule schedule);
344 * Uninitializes the scheduler. This is called when the program is ready
345 * to end. This removes all tasks from the scheduler. Returns FALSE if the
346 * scheduler could not be uninitialized. This happens when the scheduler
347 * is still valid and silc_schedule_stop has not been called.
349 * If SilcStack was given to silc_schedule_init all memory allocated
350 * during the life time of the scheduler will be returned back to the
354 SilcBool silc_schedule_uninit(SilcSchedule schedule);
356 /****f* silcutil/SilcScheduleAPI/silc_schedule_stop
360 * void silc_schedule_stop(SilcSchedule schedule);
364 * Stops the scheduler even if it is not supposed to be stopped yet.
365 * After calling this, one must call silc_schedule_uninit (after the
366 * silc_schedule has returned). After this is called it is guaranteed
367 * that next time the scheduler enters the main loop it will be stopped.
368 * However, untill it enters the main loop it will not detect that
369 * it is stopped for example if this is called from another thread.
372 void silc_schedule_stop(SilcSchedule schedule);
374 /****f* silcutil/SilcScheduleAPI/silc_schedule
378 * void silc_schedule(SilcSchedule schedule);
382 * The SILC scheduler. The program will run inside this function.
383 * When this returns the program is to be ended. Before this function
384 * can be called, one must call silc_schedule_init function.
388 * On Windows this will block the calling thread but will continue
389 * to dispatch window messages, and thus can be used as the main loop
392 * On Symbian this will block the calling thread. The Symbian Active
393 * Scheduler must be running before calling this function.
396 void silc_schedule(SilcSchedule schedule);
398 /****f* silcutil/SilcScheduleAPI/silc_schedule_one
402 * SilcBool silc_schedule_one(SilcSchedule schedule, int timeout_usecs);
406 * Same as the silc_schedule but runs the scheduler only one round
407 * and then returns. This function is handy when the SILC scheduler
408 * is used inside some other external scheduler, for example. If
409 * the `timeout_usecs' is non-negative a timeout will be added to the
410 * scheduler. The function will not return in this timeout unless
411 * some other event occurs.
413 * Typically this would be called from a timeout or idle task
414 * periodically (typically from 5-50 ms) to schedule SILC tasks. In
415 * this case the `timeout_usecs' is usually 0 to make the function
416 * return immediately.
419 SilcBool silc_schedule_one(SilcSchedule schedule, int timeout_usecs);
421 /****f* silcutil/SilcScheduleAPI/silc_schedule_wakeup
425 * void silc_schedule_wakeup(SilcSchedule schedule);
429 * Wakes up the scheduler. This is may be used in multi-threaded
430 * environments where threads may add new tasks or remove old tasks
431 * from the scheduler. This is called to wake up the scheduler in the
432 * main thread so that it detects the changes in the scheduler.
433 * If threads support is not compiled in this function has no effect.
436 void silc_schedule_wakeup(SilcSchedule schedule);
438 /****f* silcutil/SilcScheduleAPI/silc_schedule_get_parent
442 * SilcSchedule silc_schedule_get_parent(SilcSchedule schedule);
446 * Returns the parent scheduler of the `schedule'. Never returns NULL.
449 SilcSchedule silc_schedule_get_parent(SilcSchedule schedule);
451 /****f* silcutil/SilcScheduleAPI/silc_schedule_get_context
455 * void *silc_schedule_get_context(SilcSchedule schedule);
459 * Returns the application specific context that was saved into the
460 * scheduler in silc_schedule_init function. The context is also
461 * returned to application in the SilcTaskCallback, but this function
462 * may be used to get it as well if needed.
465 void *silc_schedule_get_context(SilcSchedule schedule);
467 /****f* silcutil/SilcScheduleAPI/silc_schedule_get_stack
471 * SilcStack silc_schedule_get_stack(SilcSchedule schedule);
475 * Returns the stack of the `schedule'. If it is used to make memory
476 * allocations outside the scheduler, it is recommended that a new
477 * child stack is created by using the returned stack as a parent and
478 * using the child stack to make the memory allocations.
481 SilcStack silc_schedule_get_stack(SilcSchedule schedule);
483 /****f* silcutil/SilcScheduleAPI/silc_schedule_set_notify
487 * void silc_schedule_set_notify(SilcSchedule schedule,
488 * SilcTaskNotifyCb notify, void *context);
492 * Set notify callback to scheduler. The `notify' will be called whenever
493 * task is added to or deleted from scheduler.
496 void silc_schedule_set_notify(SilcSchedule schedule,
497 SilcTaskNotifyCb notify, void *context);
499 /****f* silcutil/SilcScheduleAPI/silc_schedule_set_global
503 * void silc_schedule_set_global(SilcSchedule schedule);
507 * Sets global SilcSchedule `schedule' that can be retrieved at any time
508 * by using silc_schedule_get_global. The global scheduler is global only
509 * to the current thread. Each thread can have their own global scheduler.
510 * If each thread must have global scheduler this must be called in each
511 * thread. If the global scheduler has been set already, new call will
512 * replace the old one.
514 * This routine is provided only as a convenience function to store
515 * program's or thread's scheduler in one global place. It is not mandatory
516 * to call this function in order to use SilcSchedule.
518 * Many routines that require SilcSchedule as an argument will call
519 * silc_schedule_get_global if the scheduler is not provided to try to
520 * get global scheduler. Almost all routines in SilcSchedule API will call
521 * silc_schedule_get_global if the SilcSchedule is not provided as argument.
524 void silc_schedule_set_global(SilcSchedule schedule);
526 /****f* silcutil/SilcScheduleAPI/silc_schedule_get_global
530 * SilcSchedule silc_schedule_get_global(void);
534 * Returns the thread's global scheduler that was set by calling
535 * silc_schedule_set_global or NULL if global scheduler has not been set.
538 SilcSchedule silc_schedule_get_global(void);
540 /****f* silcutil/SilcScheduleAPI/silc_schedule_task_add_fd
545 * silc_schedule_task_add_fd(SilcSchedule schedule, SilcUInt32 fd,
546 * SilcTaskCallback callback, void *context);
550 * Add file descriptor task to scheduler. The `fd' may be either real
551 * file descriptor, socket or on some platforms an opaque file descriptor
552 * handle. To receive events for the file descriptor set the correct
553 * request events with silc_schedule_set_listen_fd function.
555 * The task will be initially set for SILC_TASK_READ events. Setting that
556 * event immediately after this call returns is not necessary.
558 * This returns the new task or NULL on error. If a task with `fd' has
559 * already been added this will return the existing task pointer.
561 * If `schedule' is NULL this will call silc_schedule_get_global to try to
562 * get global scheduler.
565 #define silc_schedule_task_add_fd(schedule, fd, callback, context) \
566 silc_schedule_task_add(schedule, fd, callback, context, 0, 0, SILC_TASK_FD)
568 /****f* silcutil/SilcScheduleAPI/silc_schedule_task_add_timeout
573 * silc_schedule_task_add_timeout(SilcSchedule schedule,
574 * SilcTaskCallback callback, void *context,
575 * long seconds, long useconds);
579 * Add timeout task to scheduler. The `callback' will be called once
580 * the specified timeout has elapsed. The task will be removed from the
581 * scheduler automatically once the task expires. The event returned
582 * to the `callback' is SILC_TASK_EXPIRE. A task added with zero (0)
583 * timeout will be executed immediately next time tasks are scheduled.
585 * If `schedule' is NULL this will call silc_schedule_get_global to try to
586 * get global scheduler.
589 #define silc_schedule_task_add_timeout(schedule, callback, context, s, u) \
590 silc_schedule_task_add(schedule, 0, callback, context, s, u, \
593 /****f* silcutil/SilcScheduleAPI/silc_schedule_task_add_signal
598 * silc_schedule_task_add_signal(SilcSchedule schedule, int signal,
599 * SilcTaskCallback callback, void *context);
603 * Add platform specific process signal handler to scheduler. On Unix
604 * systems the `signal' is one of the signal specified in signal(7). On
605 * other platforms this function may not be available at all, and has no
606 * effect when called. The event delivered to the `callback' is
607 * SILC_TASK_INTERRUPT.
609 * If `schedule' is NULL this will call silc_schedule_get_global to try to
610 * get global scheduler.
614 * One signal may be registered only one callback. Adding second callback
615 * for signal that already has one will fail.
617 * This function always returns NULL. To remove signal from scheduler by
618 * the signal call silc_schedule_task_del_by_fd.
621 #define silc_schedule_task_add_signal(schedule, sig, callback, context) \
622 silc_schedule_task_add(schedule, sig, callback, context, 0, 0, \
625 /****f* silcutil/SilcScheduleAPI/silc_schedule_task_add_event
630 * silc_schedule_task_add_event(SilcSchedule schedule,
631 * const char *event, ...);
635 * Adds an event task to scheduler. These tasks are asynchronous events
636 * that one or more receivers may connect to and receive information or
637 * data when the event is signalled. Event tasks are fast and may be
638 * used to efficiently deliver events and data to multiple receivers. The
639 * `event' is the name of the event, and can be used to connect to the
640 * event and to signal it.
642 * The events are global among the `scheduler', its parent scheduler and
643 * any of its child schedulers. It does not matter to which scheduler
644 * event is added to, connected to or signalled. Signal will reach any
645 * connected entity, as long as it is the parent or one of the fellow
646 * children of `schedule'.
648 * To connect to an event call silc_schedule_event_connect.
649 * To disconnect from event call silc_schedule_event_disconnect.
650 * To signal event call silc_schedule_event_signal.
651 * To delete event task call silc_schedule_task_del or
652 * silc_schedule_task_del_event.
654 * The variable argument list is used to describe the arguments of the
655 * event. The variable arguments are a list of zero or more SilcParam
656 * values. This function returns the event task context or NULL on error.
660 * // Register 'connected' event
661 * silc_schedule_task_add_event(schedule, "connected",
663 * SILC_PARAM_BUFFER);
665 * // Connect to 'connected' event
666 * silc_schedule_event_connect(schedule, "connected", NULL,
667 * connected_cb, ctx);
669 * // Signal 'connected' event
670 * silc_schedule_event_signal(schedule, "connected", NULL, integer, buf);
672 * // 'connected' event handler
673 * SILC_TASK_CALLBACK(connected_cb)
675 * FooCtx ctx = context;
676 * SilcUInt32 integer;
679 * integer = va_arg(va, SilcUInt32);
680 * buf = va_arg(va, SilcBuffer);
685 SilcTask silc_schedule_task_add_event(SilcSchedule schedule,
686 const char *event, ...);
688 /****f* silcutil/SilcScheduleAPI/silc_schedule_task_del
692 * SilcBool silc_schedule_task_del(SilcSchedule schedule, SilcTask task);
696 * Deletes the `task' from the scheduler indicated by the `schedule'.
697 * After deleting the task it is guaranteed that the task callback
698 * will not be called. If the `task' is SILC_ALL_TASKS then all
699 * tasks is removed from the scheduler. Returns always TRUE.
701 * It is safe to call this function in any place. Tasks may be removed
702 * in task callbacks (including in the task's own task callback) and
703 * in multi-threaded environment in other threads as well.
705 * If `schedule' is NULL this will call silc_schedule_get_global to try to
706 * get global scheduler.
709 SilcBool silc_schedule_task_del(SilcSchedule schedule, SilcTask task);
711 /****f* silcutil/SilcScheduleAPI/silc_schedule_task_del_by_fd
715 * SilcBool silc_schedule_task_del_by_fd(SilcSchedule schedule,
720 * Deletes a task from the scheduler by the specified `fd'. Returns
721 * FALSE if such fd task does not exist.
723 * It is safe to call this function in any place. Tasks may be removed
724 * in task callbacks (including in the task's own task callback) and
725 * in multi-threaded environment in other threads as well.
727 * If `schedule' is NULL this will call silc_schedule_get_global to try to
728 * get global scheduler.
731 SilcBool silc_schedule_task_del_by_fd(SilcSchedule schedule, SilcUInt32 fd);
733 /****f* silcutil/SilcScheduleAPI/silc_schedule_task_del_by_callback
737 * SilcBool silc_schedule_task_del_by_callback(SilcSchedule schedule,
738 * SilcTaskCallback callback);
742 * Deletes a task from the scheduler by the specified `callback' task
743 * callback function. Returns FALSE if such task with such callback
746 * It is safe to call this function in any place. Tasks may be removed
747 * in task callbacks (including in the task's own task callback) and
748 * in multi-threaded environment in other threads as well.
750 * If `schedule' is NULL this will call silc_schedule_get_global to try to
751 * get global scheduler.
754 SilcBool silc_schedule_task_del_by_callback(SilcSchedule schedule,
755 SilcTaskCallback callback);
757 /****f* silcutil/SilcScheduleAPI/silc_schedule_task_del_by_context
761 * SilcBool silc_schedule_task_del_by_context(SilcSchedule schedule,
766 * Deletes a task from the scheduler by the specified `context'. Returns
767 * FALSE if such task with such context does not exist.
769 * It is safe to call this function in any place. Tasks may be removed
770 * in task callbacks (including in the task's own task callback) and
771 * in multi-threaded environment in other threads as well.
773 * If `schedule' is NULL this will call silc_schedule_get_global to try to
774 * get global scheduler.
777 SilcBool silc_schedule_task_del_by_context(SilcSchedule schedule,
780 /****f* silcutil/SilcScheduleAPI/silc_schedule_task_del_by_all
784 * SilcBool silc_schedule_task_del_by_all(SilcSchedule schedule, int fd,
785 * SilcTaskCallback callback,
790 * Deletes a task from the scheduler by the specified `fd', `callback'
791 * and `context'. Returns FALSE if such task does not exist.
793 * It is safe to call this function in any place. Tasks may be removed
794 * in task callbacks (including in the task's own task callback) and
795 * in multi-threaded environment in other threads as well.
797 * If `schedule' is NULL this will call silc_schedule_get_global to try to
798 * get global scheduler.
801 SilcBool silc_schedule_task_del_by_all(SilcSchedule schedule, int fd,
802 SilcTaskCallback callback,
805 /****f* silcutil/SilcScheduleAPI/silc_schedule_task_del_event
809 * void silc_schedule_task_del_event(SilcSchedule schedule,
810 * const char *event);
814 * Deletes event task by the event name `event'. Returns FALSE if the
815 * event does not exist. Events can be deleted by calling the
816 * silc_schedule_task_del also.
818 * If `schedule' is NULL this will call silc_schedule_get_global to try to
819 * get global scheduler.
822 SilcBool silc_schedule_task_del_event(SilcSchedule schedule,
825 /****f* silcutil/SilcScheduleAPI/silc_schedule_set_listen_fd
829 * SilcBool silc_schedule_set_listen_fd(SilcSchedule schedule,
831 * SilcTaskEvent mask,
832 * SilcBool send_events);
836 * Sets a file descriptor `fd' to be listened by the scheduler for
837 * `mask' events. To tell scheduler not to listen anymore for this
838 * file descriptor call the silc_schedule_unset_listen_fd function.
839 * When new task is created with silc_schedule_task_add the event
840 * for the task's fd is initially set to SILC_TASK_READ. If you need
841 * to control the task's fd's events you must call this function
842 * whenever you need to change the events. This can be called multiple
843 * times to change the events.
845 * If the `send_events' is TRUE then this function sends the events
846 * in `mask' to the application. If FALSE then they are sent only
847 * after the event occurs in reality. In normal cases the `send_events'
850 * If `schedule' is NULL this will call silc_schedule_get_global to try to
851 * get global scheduler.
853 * Returns FALSE if the operation could not performed and TRUE if it
857 SilcBool silc_schedule_set_listen_fd(SilcSchedule schedule, SilcUInt32 fd,
858 SilcTaskEvent mask, SilcBool send_events);
860 /****f* silcutil/SilcScheduleAPI/silc_schedule_get_fd_events
864 * SilcTaskEvent silc_schedule_get_fd_events(SilcSchedule schedule,
869 * Returns the file descriptor `fd' current requested events mask,
872 * If `schedule' is NULL this will call silc_schedule_get_global to try to
873 * get global scheduler.
876 SilcTaskEvent silc_schedule_get_fd_events(SilcSchedule schedule,
879 /****f* silcutil/SilcScheduleAPI/silc_schedule_unset_listen_fd
883 * void silc_schedule_unset_listen_fd(SilcSchedule schedule, SilcUInt32 fd);
887 * Tells the scheduler not to listen anymore for the specified
888 * file descriptor `fd'. No events will be detected for the `fd'
889 * after calling this function.
891 * If `schedule' is NULL this will call silc_schedule_get_global to try to
892 * get global scheduler.
895 void silc_schedule_unset_listen_fd(SilcSchedule schedule, SilcUInt32 fd);
897 /****f* silcutil/SilcScheduleAPI/silc_schedule_event_connect
901 * SilcBool silc_schedule_event_connect(SilcSchedule schedule,
902 * const char *event, SilcTask task,
903 * SilcTaskEventCallback callback,
908 * Connects to an event task. The `event' or `task' must be non-NULL.
909 * If `event' is non-NULL it is the name of the event to connect to. If
910 * the `task' is non-NULL it is the event task to connect to. The event
911 * SilcTask pointer is returned by silc_schedule_task_add_event when the
912 * even is added to scheduler.
914 * The `callback' with `context' and with `schedule' are called when the
915 * even task is signalled with silc_schedule_event_signal.
917 * Returns FALSE on error or if the `callback' with `context' has already
918 * been connected. Otherwise, returns TRUE.
922 * silc_schedule_event_connect(schedule, "foo event", NULL,
923 * foo_signal_callback, foo_context);
926 SilcBool silc_schedule_event_connect(SilcSchedule schedule,
927 const char *event, SilcTask task,
928 SilcTaskEventCallback callback,
931 /****f* silcutil/SilcScheduleAPI/silc_schedule_event_disconnect
935 * SilcBool silc_schedule_event_disconnect(SilcSchedule schedule,
936 * const char *event, SilcTask task,
937 * SilcTaskEventCallback callback,
942 * Disconnects the `callback' and `context' from an event task. The `event'
943 * or `task' must be non-NULL. If `event' is non-NULL it is the name of
944 * the event. If `task' is non-NULL it is the event task.
946 * Returns FALSE on error or if the `callback' with `context' has not been
947 * connected. Otherwise, returns TRUE.
950 SilcBool silc_schedule_event_disconnect(SilcSchedule schedule,
951 const char *event, SilcTask task,
952 SilcTaskEventCallback callback,
955 /****f* silcutil/SilcScheduleAPI/silc_schedule_event_signal
959 * SilcBool silc_schedule_event_signal(SilcSchedule schedule,
961 * SilcTask task, ...);
965 * Signals an event task. The `event' or `task' must be non-NULL. If
966 * `event' is non-NULL it is the name of the event to signal. If the `task'
967 * is non-NULL it is the task to be signalled. It is marginally faster
968 * to use the `task' pointer directly instead of `event' to send the signal.
970 * The variable arguments are the arguments to be sent in the signal to
971 * the connected entities. The silc_schedule_task_add_event defines what
972 * arguments must be sent to each signal.
974 * Signal delivery is synchronous; the signal is delivered inside this
975 * function. If a receiver was originally in another thread, the signal
976 * is delivered in the thread where this function is called. This means
977 * that concurrency control (locking) is required if the application uses
978 * events in multiple threads.
982 * silc_schedule_event_signal(schedule, "foo event", NULL, intarg, buffer);
985 SilcBool silc_schedule_event_signal(SilcSchedule schedule, const char *event,