some bugfixes about plugins.
[vde.git] / vde-2 / include / vdeplugin.h
blob9da2567d398f4962df09bdd12b918ce1c3d6ddbe
1 #ifndef _VDEPLUGIN_H
2 #define _VDEPLUGIN_H
3 #include <stdarg.h>
4 #include <stdio.h>
6 /* command type constants */
7 /* doit signature:
8 * int doit (
9 * FILE *f, *** only when WITHFILE
10 * int fd, *** only when WITHFD
11 * int|char *arg) *** when INTARG or STRARG */
12 /* if type==NOARG int doit(void)
13 * if type==INTARG int doit(int arg)
14 * if type==WITHFILE|WITHFD|STRARG int doit(FILE *f,int fd,char *arg)
15 * doit returns 0 on success otherwise it returns a valid errno code */
16 #define NOARG 0 /*the command require no args */
17 #define INTARG 1 /* arg is an integer */
18 #define STRARG 2 /* arg is a string */
19 #define WITHFILE 0x40 /* command needs to return text output.
20 (the output will be sent to the user using
21 "0000 DATA END WITH '.'") */
22 #define WITHFD 0x80 /* fd is the identifier of the mgmt connection issuing
23 the command. fd== -1 when the command is executed by
24 an rc file. Fd should not be considered a file
25 descriptor, */
27 typedef int (*intfun)();
29 /* command structure */
30 struct comlist {
31 char *path; /*pathname of the command: pathname structured */
32 char *syntax; /*description of the syntax */
33 char *help; /*description of the command for help listings */
34 int (*doit)(); /* the call back to the command code */
35 unsigned char type; /* types of command: see constants above */
36 /* the following field is for management. never set or change it*/
37 struct comlist *next;
40 /* pre-defined TAGs */
41 #define D_PACKET 01000
42 #define D_MGMT 02000
43 #define D_IN 01
44 #define D_OUT 02
45 #define D_PLUS 01
46 #define D_MINUS 02
47 #define D_DESCR 03
48 #define D_STATUS 04
49 #define D_ROOT 05
50 #define D_HASH 010
51 #define D_PORT 020
52 #define D_EP 030
53 #define D_FSTP 040
54 /* debug/event structure */
55 struct dbgcl {
56 char *path; /* pathname structured debug/event request */
57 char *help; /* description for debug options listing
58 if help==NULL the entry will be used only for
59 plugin event publish/subscribe not directly accessible
60 from the user interface */
61 int tag; /* numerical tag of the debug/event */
62 /* the following fields are for management. never set or change them*/
63 int *fds;
64 intfun (*fun);
65 void **funarg;
66 unsigned short nfds;
67 unsigned short nfun;
68 unsigned short maxfds;
69 unsigned short maxfun;
70 struct dbgcl *next;
73 /* plugin element: one element named "vde_plugin_data" must
74 * be defined otherwise the dynamic library will not be recognized
75 * as a vde plugin module */
76 struct plugin {
77 /* name of the plugin, it should be unique, maybe pathname structured.
78 * it identifies the plugin for listing and unloading plugins */
79 char *name;
80 /* description of the plugin for listings */
81 char *help;
82 /* the following fields should never be set or changed by
83 * plugin modules */
84 void *handle;
85 struct plugin *next;
88 /* this adds a new management fd */
89 void mgmtnewfd(int new);
91 #define ADDCL(CL) addcl(sizeof(CL)/sizeof(struct comlist),(CL))
92 #define ADDDBGCL(CL) adddbgcl(sizeof(CL)/sizeof(struct dbgcl),(CL))
93 #define DELCL(CL) delcl(sizeof(CL)/sizeof(struct comlist),(CL))
94 #define DELDBGCL(CL) deldbgcl(sizeof(CL)/sizeof(struct dbgcl),(CL))
95 #define DBGOUT(CL, FORMAT, ...) \
96 if (__builtin_expect(((CL)->nfds) > 0, 0)) debugout((CL), (FORMAT), __VA_ARGS__)
97 #define EVENTOUT(CL, ...) \
98 if (__builtin_expect(((CL)->nfun) > 0, 0)) eventout((CL), __VA_ARGS__)
101 int eventadd(int (*fun)(struct dbgcl *event,void *arg,va_list v),char *path,void *arg);
102 int eventdel(int (*fun)(struct dbgcl *event,void *arg,va_list v),char *path,void *arg);
104 void debugout(struct dbgcl* cl, const char *format, ...);
106 void addcl(int ncl,struct comlist *cl);
107 void delcl(int ncl,struct comlist *cl);
109 #ifdef DEBUGOPT
110 void adddbgcl(int ncl,struct dbgcl *cl);
111 void deldbgcl(int ncl,struct dbgcl *cl);
112 #endif
114 void printoutc(FILE *f, const char *format, ...);
117 #endif