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