Lay off the ground of our very efficient event loop.
[apps/madmutt.git] / lib-sys / evtloop.h
diff --git a/lib-sys/evtloop.h b/lib-sys/evtloop.h
new file mode 100644 (file)
index 0000000..f08f1e7
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ *  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
+ *  the Free Software Foundation; either version 2 of the License, or (at
+ *  your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ */
+/*
+ *  Copyright © 2006 Pierre Habouzit
+ */
+
+#ifndef MUTT_LIB_SYS_EVTLOOP_H
+#define MUTT_LIB_SYS_EVTLOOP_H
+
+#include <lib-lib/lib-lib.h>
+
+typedef enum el_state {
+    EL_LLP_INIT,
+    EL_LLP_READY,
+    EL_LLP_FINI,
+} el_state;
+
+typedef enum el_mode {
+    EL_IDLE    = 0,
+    EL_READING = 1,
+    EL_WRITING = 2,
+    EL_RDWR    = 3,
+} el_mode;
+
+typedef enum el_status {
+    EL_SUCCESS,
+    EL_ERROR,
+    EL_KILLED,
+    EL_RDHUP,
+} el_status;
+
+typedef enum el_event {
+    EL_EVT_IN      = EL_READING,
+    EL_EVT_OUT     = EL_WRITING,
+    EL_EVT_INOUT   = EL_RDWR,
+    EL_EVT_RUNNING = 4,
+    EL_EVT_WAKEUP  = 5,
+} el_event;
+
+typedef struct job_t {
+    int fd;
+
+    el_state state : 2;
+    el_mode  mode  : 2;
+    el_mode  emode : 2;
+
+    int (*llp)(struct job_t *);
+    struct machine_t *m;
+    void *ptr;
+} job_t;
+
+typedef struct machine_t {
+    const char *name;
+    __must_check__ int (*setup)(job_t *w, void *);
+    int (*on_event)(job_t *w, el_event);
+    void (*finalize)(job_t *w, el_status);
+} machine_t;
+
+__must_check__ int el_job_release(job_t *j, el_status);
+int el_dispatch(int timeout);
+
+#endif