#ifndef API_SWIG_H
#define API_SWIG_H
+#include <yaz/xmalloc.h>
#include <idzebra/res.h>
#include <idzebra/api.h>
-typedef short IDZEBRA_RES;
+typedef short IDZEBRA_RES;
#define RES_LIST char** res_args
+typedef struct idzebra_swig_service *IDZebraService;
+
+typedef struct idzebra_swig_session *IDZebraSession;
+
/*
-------------------------------------------------------------------------------
API Calls
void api_clear_error(void);
-ZebraService idzebra_start (RES_LIST);
+IDZebraService idzebra_start (RES_LIST);
-IDZEBRA_RES idzebra_stop(ZebraService zs);
+IDZEBRA_RES idzebra_stop(IDZebraService srv);
-ZebraHandle idzebra_open (ZebraService zs, RES_LIST);
+IDZebraSession idzebra_open (IDZebraService srv, RES_LIST);
-IDZEBRA_RES idzebra_close(ZebraHandle zh);
+IDZEBRA_RES idzebra_close(IDZebraSession sess);
-IDZEBRA_RES idzebra_samplefunc(ZebraHandle zh, RES_LIST);
+IDZEBRA_RES idzebra_samplefunc(IDZebraSession sess, RES_LIST);
/*
Res skip,
char **args);
-void args_use (ZebraHandle zh,
+void args_use (IDZebraSession sess,
Res r,
Res rr,
int mandatory,
} \
#define ARGS_APPLY \
- temp_res = res_add_over(zh->session_res, func_res); \
+ temp_res = res_add_over(sess->res, func_res); \
#define ARGS_PROCESS(mode, ...) \
{ \
const char *vargs[] = { __VA_ARGS__ , 0 }; \
- args_use(zh, local, func_res, mode, vargs); \
+ args_use(sess, local, func_res, mode, vargs); \
} \
#define ARGS_REVOKE \
const char **used; \
res_remove_over(temp_res); \
used = res_get_array(local, "_used"); \
- args_use(zh, zh->session_res, 0, ARG_MODE_FORCE, used); \
+ args_use(sess, sess->res, 0, ARG_MODE_FORCE, used); \
free_array(used); \
} \
#define ARGS_DONE \
if (func_res) res_close(func_res); \
+ if (temp_res) res_close_over(temp_res); \
if (local) res_close(local); \
#endif /* API_SWIG_H */
#include <idzebra/api_swig.h>
-#include <idzebra/res.h>
-#include <idzebra/api.h>
#include <stdarg.h>
-#include "index.h"
#define DEFAULT_APPROX_LIMIT 2000000000
+/* == Internal structures ================================================== */
+
+struct idzebra_swig_service {
+ ZebraService zs;
+ Res res;
+};
+
+struct idzebra_swig_session {
+ ZebraHandle zh;
+ Res res;
+};
+
/* == API errors, debug ==================================================== */
static Res api_error = 0;
const char* api_error_context = 0;
void api_add_error(const char *fmt, ...);
-void api_clear_error(void);
+void api_clear_error(void);
void free_array(const char **args);
-ZebraHandle zebra_get_handle (ZebraService zs);
/* == API init, destroy =================================================== */
/* == Service start/stop =================================================== */
-ZebraService idzebra_start(RES_LIST)
+IDZebraService idzebra_start (RES_LIST)
{
- ZebraService zs = 0;
+ IDZebraService srv = xmalloc(sizeof(*srv));
ARGS_INIT;
API_SET_CONTEXT;
"setTmpDir",
"lockDir");
- zs = zebra_start_res(res_get(func_res,"configName"), NULL, func_res);
+ srv->res = func_res;
+ srv->zs = zebra_start_res(res_get(func_res,"configName"), NULL, srv->res);
- /* Function resources are kept for service (zs->global_res); */
func_res = 0;
ARGS_DONE;
- return (zs);
+ return (srv);
}
-IDZEBRA_RES idzebra_stop(ZebraService zs)
+IDZEBRA_RES idzebra_stop(IDZebraService srv)
{
- /* Global res have an over part here */
- res_close_over(zs->global_res);
- return (zebra_stop(zs));
+ ZEBRA_RES rv = zebra_stop(srv->zs);
+ res_close (srv->res);
+ xfree (srv);
+ return (rv);
}
/* == Session open/close =================================================== */
-ZebraHandle idzebra_open (ZebraService zs, RES_LIST)
+IDZebraSession idzebra_open (IDZebraService srv, RES_LIST)
{
-
- ZebraHandle zh;
+ IDZebraSession sess = xmalloc(sizeof(*sess));
ARGS_INIT;
API_SET_CONTEXT;
"estimatehits",
"staticrank");
- zh = zebra_open(zs, func_res);
+ sess->res = func_res;
+ sess->zh = zebra_open(srv->zs, sess->res);
/* Function resources are kept for session (zh->res->over_res); */
func_res = 0;
ARGS_DONE;
- yaz_log (YLOG_DEBUG, "zebra_open zs=%p returns %p", zs, zh);
-
- return (zh);
+ return (sess);
}
-IDZEBRA_RES idzebra_close(ZebraHandle zh)
+IDZEBRA_RES idzebra_close(IDZebraSession sess)
{
- res_close_over(zh->session_res);
- return (zebra_close(zh));
+ ZEBRA_RES rv = zebra_close (sess->zh);
+ res_close (sess->res);
+ xfree (sess);
+ return (rv);
}
/* == Sample function == =================================================== */
-IDZEBRA_RES idzebra_samplefunc(ZebraHandle zh, RES_LIST)
+IDZEBRA_RES idzebra_samplefunc(IDZebraSession sess, RES_LIST)
{
ARGS_INIT;
API_SET_CONTEXT;
ARGS_PROCESS(ARG_MODE_OPTIONAL,"encoding");
ARGS_APPLY;
- yaz_log (YLOG_DEBUG, "Got strucc:%s\n",res_get(zh->res,"strucc"));
- res_dump (zh->res,0);
+ res_dump (sess->res,0);
- ARGS_REVOKE;
+ // ARGS_REVOKE;
+ {
+ const char **used;
+ res_remove_over(temp_res);
+ used = (const char **) res_get_array(local, "_used"); args_use(sess, sess->res, 0, ARG_MODE_FORCE, used);
+ free_array(used);
+ }
ARGS_DONE;
return (ZEBRA_OK);
}
zebra_set_approx_limit(zh, val);
}
+/*
void idzebra_res_staticrank (ZebraHandle zh, const char *value)
{
int val = 0;
if (! (sscanf(value, "%d", &val) == 1))
api_add_error( "Expected integer value for 'estimatehits'");
- zh->m_staticrank = val;
+ sess->zh->m_staticrank = val;
}
+*/
/* == applying and revoking call-scope resources =========================== */
}
/* staticrank */
+ /*
else if (!strcmp(name,"staticrank")) {
idzebra_res_staticrank(zh, value);
gotit = 1;
}
+ */
/* collects provided arguments in order to revoke them
at the end of the function */
}
}
-void args_use (ZebraHandle zh,
+void args_use (IDZebraSession sess,
Res r,
Res rr,
int mode,
int i = 0;
if (args) {
while (args[i]) {
- arg_use (zh, r, rr, mode, args[i++]);
+ arg_use (sess->zh, r, rr, mode, args[i++]);
}
}
}
-/* $Id: zebraapi.c,v 1.187 2005-09-15 12:48:42 adam Exp $
+/* $Id: zebraapi.c,v 1.188 2005-09-16 17:00:41 pop Exp $
Copyright (C) 1995-2005
Index Data ApS
#define ASSERTZHRES assert(zh && zh->service && zh->res)
#define ASSERTZS assert(zs)
-static int log_level = 0;
-static int log_level_initialized = 0;
+static int log_level = YLOG_LOG;
+static int log_level_initialized = 1;
static void zebra_open_res(ZebraHandle zh);
static void zebra_close_res(ZebraHandle zh);
if (!passwd_plain && !passwd_encrypt)
zh->passwd_db = NULL;
- else
+ else
{
zh->passwd_db = passwd_db_open();
if (!zh->passwd_db)
{
ASSERTZH;
assert(encoding);
- yaz_log(log_level, "zebra_octet_term_encoding");
+ yaz_log(log_level, "zebra_octet_term_encoding %s", encoding);
zebra_clearError(zh);
if (zh->iconv_to_utf8 != 0)