ekg2  GIT master
 All Struktury Danych Pliki Funkcje Zmienne Definicje typów Wyliczenia Wartości wyliczeń Definicje Grupay Strony
plugins.h
Idź do dokumentacji tego pliku.
1 /* $Id$ */
2 
3 /*
4  * (C) Copyright 2003 Wojtek Kaniewski <wojtekka@irc.pl>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License Version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef __EKG_PLUGINS_H
21 #define __EKG_PLUGINS_H
22 
23 #include <glib.h>
24 #include <gmodule.h>
25 
26 #include <sys/types.h>
27 #include <stdarg.h>
28 
29 #include "dynstuff.h"
30 #include "sessions.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #define EKG_ABI_VER 5798 /* git rev-list master | wc -l */
37 
38 #define EXPORT __attribute__ ((visibility("default"))) G_MODULE_EXPORT
39 
40 typedef enum {
51 
52 typedef int (*plugin_destroy_func_t)(void);
53 typedef int (*plugin_theme_init_func_t)(void);
54 typedef void (plugin_notify_func_t)(session_t *, const char *);
55 
56 #define PLUGIN_VAR_ADD(name, type, value, secret, notify) { name, value, secret, type, notify, NULL }
57 #define PLUGIN_VAR_ADD_MAP(name, type, value, secret, notify, map) { name, value, secret, type, notify, map }
58 #define PLUGIN_VAR_END() { NULL, NULL, 0, -1, NULL }
59 extern int plugin_abi_version(int plugin_abi_ver, const char * plugin_name);
60 #define PLUGIN_CHECK_VER(name) { if (!plugin_abi_version(EKG_ABI_VER, name)) return -1; }
61 
62 typedef struct {
63  char *key; /* name */
64  char *value; /* value */
65  int secret; /* should it be hidden ? */
66  int type; /* type */
68  struct variable_map_t *map; /* values and labels map */
70 
72  const char **protocols; /* NULL-terminated list of supported protocols, replacing GET_PLUGIN_PROTOCOLS */
73  const status_t *statuses; /* EKG_STATUS_NULL-terminated list of supported statuses */
74 };
75 
76 typedef struct plugin {
77  char *name;
78  int prio;
81  /* lt_dlhandle */ void *dl;
84 
85  const void *priv;
86 } plugin_t;
87 
88 /* Note about plugin_t.statuses:
89  * we currently put every supported status there, including unsettable by user,
90  * we assume that user cannot set states <= EKG_STATUS_NA
91  * [XXX]
92  */
93 
94 #ifndef EKG2_WIN32_NOFUNCTION
95 
96 int plugin_load(const char *name, int prio, int quiet);
97 int plugin_unload(plugin_t *);
98 int plugin_register(plugin_t *, int prio);
100 plugin_t *plugin_find(const char *name);
101 plugin_t *plugin_find_uid(const char *uid);
103 int plugin_var_add(plugin_t *pl, const char *name, int type, const char *value, int secret, plugin_notify_func_t *notify);
104 int plugin_var_find(plugin_t *pl, const char *name);
105 
106 void plugins_unlink(plugin_t *pl);
107 #endif
108 
109 #ifdef USINGANANTIQUECOMPILER
110 #define PLUGIN_DEFINE(x, y, z)\
111  static int x##_plugin_destroy(); \
112  \
113  plugin_t x##_plugin = { \
114  NULL, \
115  #x, \
116  0, \
117  y, \
118  x##_plugin_destroy, \
119  NULL, NULL, \
120  z \
121  }
122 #else
123 #define PLUGIN_DEFINE(x, y, z)\
124  static int x##_plugin_destroy(); \
125  \
126  plugin_t x##_plugin = { \
127  .name = #x, \
128  .pclass = y, \
129  .destroy = x##_plugin_destroy, \
130  .theme_init = z \
131  }
132 #endif /* USINGANANTIQUECOMPILER */
133 
134 #define QUERY(x) int x(void *data, va_list ap)
136 
137 /* must be power of 2 ;p */
138 #define QUERIES_BUCKETS 64
139 
140 typedef struct query_node {
141  struct query_node* next;
142  char *name;
145  void *data;
147  int count;
148 } query_t;
149 
150 int query_register(const char *name, ...);
152 int query_emit(plugin_t *, const char *, ...);
153 int query_free(query_t* g);
154 
155 void queries_reconnect();
156 
157 void queries_list_destroy(query_t** kk);
158 
160 
161 #ifndef EKG2_WIN32_NOFUNCTION
162 extern GSList *plugins;
163 extern query_t *queries[];
164 #endif
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 
170 #endif /* __EKG_PLUGINS_H */
171 
172 /*
173  * Local Variables:
174  * mode: c
175  * c-file-style: "k&r"
176  * c-basic-offset: 8
177  * indent-tabs-mode: t
178  * End:
179  */