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