Zebra api extension tuned for SWIG
[idzebra-moved-to-github.git] / include / idzebra / api_swig.h
1 #ifndef API_SWIG_H
2 #define API_SWIG_H
3
4 #include <idzebra/res.h>
5 #include <idzebra/api.h>
6
7 typedef short IDZEBRA_RES;
8 #define RES_LIST char** res_args                                 
9
10 /* 
11 -------------------------------------------------------------------------------
12  API Calls
13 -------------------------------------------------------------------------------
14 */
15 void idzebra_api_init(void);
16
17 char **api_errors(void);
18
19 int api_check_error(void);
20
21 void api_clear_error(void);
22
23
24 ZebraService idzebra_start (RES_LIST);
25
26 IDZEBRA_RES idzebra_stop(ZebraService zs);
27
28
29 ZebraHandle idzebra_open (ZebraService zs, RES_LIST);
30
31 IDZEBRA_RES idzebra_close(ZebraHandle zh);
32
33 IDZEBRA_RES idzebra_samplefunc(ZebraHandle zh, RES_LIST);
34
35
36 /* 
37 -------------------------------------------------------------------------------
38  Utility functions for argument handling
39 -------------------------------------------------------------------------------
40 */
41
42 #if __STDC_VERSION__ < 199901L
43 # if __GNUC__ >= 2
44 #  define __func__ __FUNCTION__
45 # else
46 #  define __func__ "<unknown>"
47 # endif
48 #endif
49
50 #define API_SET_CONTEXT api_error_context = __func__
51
52 void args_parse_res (Res r, 
53                      const char **valid_args, 
54                      Res skip,
55                      char **args);
56
57 void args_use (ZebraHandle zh,
58                Res r,
59                Res rr,
60                int mandatory,
61                const char **args);
62
63 #define ARG_MODE_OPTIONAL 0
64 #define ARG_MODE_MANDATORY 1
65 #define ARG_MODE_FORCE 2
66
67 #define RES_OPEN(var,def,over)                                   \
68   var = res_open(def, over);                                     \
69   res_set(var,"__context__", __func__ );                         \
70
71 #define ARGS_INIT                                                \
72   Res local = 0;                                                 \
73   Res func_res = 0;                                              \
74   Res temp_res = 0;                                              \
75   
76 #define ARGS_PARSE(...)                                          \
77   {                                                              \
78   const char *vargs[] = { __VA_ARGS__ , 0 };                     \
79   RES_OPEN(func_res, 0, 0);                                      \
80   RES_OPEN(local, 0, 0);                                         \
81   args_parse_res(func_res, vargs, local, res_args);              \
82   }                                                              \
83
84 #define ARGS_APPLY                                               \
85   temp_res = res_add_over(zh->session_res, func_res);            \
86
87 #define ARGS_PROCESS(mode, ...)                                  \
88   {                                                              \
89   const char *vargs[] = { __VA_ARGS__ , 0 };                     \
90   args_use(zh, local, func_res, mode, vargs);                    \
91   }                                                              \
92
93 #define ARGS_REVOKE                                              \
94   {                                                              \
95   const char **used;                                             \
96   res_remove_over(temp_res);                                     \
97   used = res_get_array(local, "_used");                          \
98   args_use(zh, zh->session_res, 0, ARG_MODE_FORCE, used);        \
99   free_array(used);                                              \
100   }                                                              \
101
102 #define ARGS_DONE                                                \
103   if (func_res) res_close(func_res);                             \
104   if (local) res_close(local);                                   \
105
106 #endif /* API_SWIG_H */