00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __EKG_PLUGINS_H
00021 #define __EKG_PLUGINS_H
00022
00023 #include <sys/types.h>
00024 #include <stdarg.h>
00025
00026 #include "dynstuff.h"
00027 #include "sessions.h"
00028
00029 #define EKG_ABI_VER 4921
00030
00031 #define EXPORT __attribute__ ((visibility("default")))
00032
00033 typedef enum {
00034 PLUGIN_ANY = 0,
00035 PLUGIN_GENERIC,
00036 PLUGIN_PROTOCOL,
00037 PLUGIN_UI,
00038 PLUGIN_LOG,
00039 PLUGIN_SCRIPTING,
00040 PLUGIN_AUDIO,
00041 PLUGIN_CODEC,
00042 PLUGIN_CRYPT
00043 } plugin_class_t;
00044
00045 typedef int (*plugin_destroy_func_t)(void);
00046 typedef int (*plugin_theme_init_func_t)(void);
00047 typedef void (plugin_notify_func_t)(session_t *, const char *);
00048
00049 #define PLUGIN_VAR_ADD(name, type, value, secret, notify) { name, value, secret, type, notify }
00050 #define PLUGIN_VAR_END() { NULL, NULL, 0, -1, NULL }
00051 extern int plugin_abi_version(int plugin_abi_ver, const char * plugin_name);
00052 #define PLUGIN_CHECK_VER(name) { if (!plugin_abi_version(EKG_ABI_VER, name)) return -1; }
00053
00054 typedef struct {
00055 char *key;
00056 char *value;
00057 int secret;
00058 int type;
00059 plugin_notify_func_t *notify;
00060 } plugins_params_t;
00061
00062 typedef struct plugin {
00063 struct plugin *next;
00064
00065 char *name;
00066 int prio;
00067 plugin_class_t pclass;
00068 plugin_destroy_func_t destroy;
00069 void *__dl;
00070 plugins_params_t *params;
00071 plugin_theme_init_func_t theme_init;
00072
00073 const void *priv;
00074 } plugin_t;
00075
00076 void plugin_load(const char *name);
00077 void plugin_unload(plugin_t *p);
00078 plugin_t *remote_plugin_load(const char *name, int prio);
00079 int plugin_register(plugin_t *, int prio);
00080 int plugin_unregister(plugin_t *);
00081 void remote_plugins_destroy();
00082 plugin_t *plugin_find(const char *name);
00083
00084 #define PLUGIN_DEFINE(x, y, z)\
00085 static int x##_plugin_destroy(); \
00086 \
00087 plugin_t x##_plugin = { \
00088 .name = #x, \
00089 .pclass = y, \
00090 .destroy = x##_plugin_destroy, \
00091 .theme_init = z \
00092 }
00093
00094 #define QUERY(x) int x(void *data, va_list ap)
00095 typedef QUERY(query_handler_func_t);
00096
00097 typedef struct queryx {
00098 struct queryx *next;
00099
00100 int id;
00101 plugin_t *plugin;
00102 void *data;
00103 query_handler_func_t *handler;
00104 int __count;
00105 } query_t;
00106
00107 query_t *query_connect_id(plugin_t *plugin, const int id, query_handler_func_t *handler, void *data);
00108 int query_emit_id(plugin_t *, const int, ...);
00109 void queries_destroy();
00110
00111 typedef enum {
00112 WATCH_NONE = 0,
00113 WATCH_WRITE = 1,
00114 WATCH_READ = 2,
00115 WATCH_READ_LINE = 4,
00116 WATCH_WRITE_LINE = 8,
00117 } watch_type_t;
00118
00119 #define WATCHER(x) int x(int type, int fd, watch_type_t watch, void *data)
00120 #define WATCHER_LINE(x) int x(int type, int fd, const char *watch, void *data)
00121
00122 typedef WATCHER(watcher_handler_func_t);
00123
00124 typedef struct watch {
00125 int fd;
00126 watch_type_t type;
00127 plugin_t *plugin;
00128 void *handler;
00129 void *data;
00130 string_t buf;
00131 time_t __timeout;
00132 time_t __started;
00133 int removed;
00134
00135 int transfer_limit;
00136
00137
00138
00139
00140
00141
00142
00143 int __is_session;
00144 } watch_t;
00145
00146 int watch_write(watch_t *w, const char *buf, int len);
00147
00148 void watch_free(watch_t *w);
00149
00150 typedef void *watch_handler_func_t;
00151
00152 watch_t *watch_add(plugin_t *plugin, int fd, watch_type_t type, watcher_handler_func_t *handler, void *data);
00153 #define watch_add_line(p, fd, type, handler, data) watch_add(p, fd, type, (watcher_handler_func_t *) (handler), data)
00154
00155 int watch_remove(plugin_t *plugin, int fd, watch_type_t type);
00156
00157 void watch_handle(watch_t *w);
00158 void watches_destroy();
00159
00160 extern plugin_t *plugins;
00161 extern list_t watches;
00162
00163 extern plugin_t *ui_plugin;
00164
00165 extern int ekg_watches_removed;
00166
00167 #endif
00168
00169
00170
00171
00172
00173
00174
00175
00176