Omit CVS Id. Update copyright year.
[idzebra-moved-to-github.git] / include / idzebra / api_swig.h
1 /* This file is part of the Zebra server.
2    Copyright (C) 1995-2008 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19 void idzebra_api_init(void);
20
21 char **api_errors(void);
22
23 int api_check_error(void);
24
25 void api_clear_error(void);
26
27
28 IDZebraService idzebra_start (RES_LIST);
29
30 IDZEBRA_RES idzebra_stop(IDZebraService srv);
31
32
33 IDZebraSession idzebra_open (IDZebraService srv, RES_LIST);
34
35 IDZEBRA_RES idzebra_close(IDZebraSession sess);
36
37 IDZEBRA_RES idzebra_samplefunc(IDZebraSession sess, RES_LIST);
38
39
40 /* 
41 -------------------------------------------------------------------------------
42  Utility functions for argument handling
43 -------------------------------------------------------------------------------
44 */
45
46 #if __STDC_VERSION__ < 199901L
47 # if __GNUC__ >= 2
48 #  define __func__ __FUNCTION__
49 # else
50 #  define __func__ "<unknown>"
51 # endif
52 #endif
53
54 #define API_SET_CONTEXT api_error_context = __func__
55
56 void args_parse_res (Res r, 
57                      const char **valid_args, 
58                      Res skip,
59                      char **args);
60
61 void args_use (IDZebraSession sess,
62                Res r,
63                Res rr,
64                int mandatory,
65                const char **args);
66
67 #define ARG_MODE_OPTIONAL 0
68 #define ARG_MODE_MANDATORY 1
69 #define ARG_MODE_FORCE 2
70
71 #define RES_OPEN(var,def,over)                                   \
72   var = res_open(def, over);                                     \
73   res_set(var,"__context__", __func__ );                         \
74
75 #define ARGS_INIT                                                \
76   Res local = 0;                                                 \
77   Res func_res = 0;                                              \
78   Res temp_res = 0;                                              \
79   
80 #define ARGS_PARSE(...)                                          \
81   {                                                              \
82   const char *vargs[] = { __VA_ARGS__ , 0 };                     \
83   RES_OPEN(func_res, 0, 0);                                      \
84   RES_OPEN(local, 0, 0);                                         \
85   args_parse_res(func_res, vargs, local, res_args);              \
86   }                                                              \
87
88 #define ARGS_APPLY                                               \
89   temp_res = res_add_over(sess->res, func_res);                  \
90
91 #define ARGS_PROCESS(mode, ...)                                  \
92   {                                                              \
93   const char *vargs[] = { __VA_ARGS__ , 0 };                     \
94   args_use(sess, local, func_res, mode, vargs);                  \
95   }                                                              \
96
97 #define ARGS_REVOKE                                              \
98   {                                                              \
99   const char **used;                                             \
100   res_remove_over(temp_res);                                     \
101   used = res_get_array(local, "_used");                          \
102   args_use(sess, sess->res, 0, ARG_MODE_FORCE, used);              \
103   free_array(used);                                              \
104   }                                                              \
105
106 #define ARGS_DONE                                                \
107   if (func_res) res_close(func_res);                             \
108   if (temp_res) res_close_over(temp_res);                        \
109   if (local) res_close(local);                                   \
110
111 #endif /* API_SWIG_H */
112 /*
113  * Local variables:
114  * c-basic-offset: 4
115  * indent-tabs-mode: nil
116  * End:
117  * vim: shiftwidth=4 tabstop=8 expandtab
118  */
119