Added asynchronous event tasks to SILC Scheduler. Added
[crypto.git] / lib / silcutil / silcschedule_i.h
index 04976c36dbe1e7ee9f1bcd3571cb4b9930ed53db..a88df592c8fb7bad88b4f183e16b50dc7a2d3cc8 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2001 - 2006 Pekka Riikonen
+  Copyright (C) 2001 - 2007 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
 #include "silchashtable.h"
 #include "silclist.h"
 
+/* Task types */
+typedef enum {
+  /* File descriptor task that performs some event over file descriptors.
+     These tasks are for example network connections. */
+  SILC_TASK_FD           = 0,
+
+  /* Timeout tasks are tasks that are executed after the specified
+     time has elapsed. After the task is executed the task is removed
+     automatically from the scheduler. It is safe to re-register the
+     task in task callback. It is also safe to unregister a task in
+     the task callback. */
+  SILC_TASK_TIMEOUT      = 1,
+
+  /* Platform specific process signal task.  On Unix systems this is one of
+     the signals described in signal(7).  On other platforms this may not
+     be available at all.  Only one callback per signal may be added. */
+  SILC_TASK_SIGNAL       = 2,
+
+  /* Asynchronous event task. */
+  SILC_TASK_EVENT        = 3,
+} SilcTaskType;
+
 /* Task header */
 struct SilcTaskStruct {
   struct SilcTaskStruct *next;
   SilcTaskCallback callback;
   void *context;
-  unsigned int type    : 1;    /* 0 = fd, 1 = timeout */
+  unsigned int type    : 2;    /* SilcTaskType */
   unsigned int valid   : 1;    /* Set if task is valid */
 };
 
@@ -47,14 +69,26 @@ typedef struct SilcTaskFdStruct {
   struct SilcTaskStruct header;
   unsigned int scheduled  : 1;
   unsigned int events     : 14;
-  unsigned int revents    : 15;
+  unsigned int revents    : 14;
   SilcUInt32 fd;
 } *SilcTaskFd;
 
+/* Event task */
+typedef struct SilcEventTaskStruct {
+  struct SilcTaskStruct header;
+  char *event;
+  SilcList connections;
+} *SilcEventTask;
+
 /* Scheduler context */
 struct SilcScheduleStruct {
+  SilcSchedule parent;            /* Parent scheduler */
   void *internal;
   void *app_context;              /* Application specific context */
+  SilcTaskNotifyCb notify;        /* Notify callback */
+  void *notify_context;                   /* Notify context */
+  SilcStack stack;                /* Stack */
+  SilcHashTable events;                   /* Event tasks */
   SilcHashTable fd_queue;         /* FD task queue */
   SilcList fd_dispatch;                   /* Dispatched FDs */
   SilcList timeout_queue;         /* Timeout queue */
@@ -86,7 +120,9 @@ typedef struct {
   /* Initializes the platform specific scheduler.  This for example initializes
      the wakeup mechanism of the scheduler.  In multi-threaded environment
      the scheduler needs to be wakenup when tasks are added or removed from
-     the task queues.  Returns context to the platform specific scheduler. */
+     the task queues.  Returns context to the platform specific scheduler.
+     If this returns NULL the scheduler initialization will fail.  Do not
+     add FD tasks inside function.  Timeout tasks can be added. */
   void *(*init)(SilcSchedule schedule, void *app_context);
 
   /* Uninitializes the platform specific scheduler context. */