From 22851818d50bb92ec91e9ec6f2bf484bd09307f6 Mon Sep 17 00:00:00 2001 From: pop Date: Fri, 16 Sep 2005 17:00:41 +0000 Subject: [PATCH] SWIG API has separated structures for service and session now. index.h not included anymore. --- include/idzebra/api_swig.h | 26 ++++++++------ index/api_swig.c | 80 +++++++++++++++++++++++++++----------------- index/zebraapi.c | 10 +++--- 3 files changed, 70 insertions(+), 46 deletions(-) diff --git a/include/idzebra/api_swig.h b/include/idzebra/api_swig.h index 5d24224..edd3e09 100644 --- a/include/idzebra/api_swig.h +++ b/include/idzebra/api_swig.h @@ -1,12 +1,17 @@ #ifndef API_SWIG_H #define API_SWIG_H +#include #include #include -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 @@ -21,16 +26,16 @@ int api_check_error(void); 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); /* @@ -54,7 +59,7 @@ void args_parse_res (Res r, Res skip, char **args); -void args_use (ZebraHandle zh, +void args_use (IDZebraSession sess, Res r, Res rr, int mandatory, @@ -82,12 +87,12 @@ void args_use (ZebraHandle zh, } \ #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 \ @@ -95,12 +100,13 @@ void args_use (ZebraHandle zh, 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 */ diff --git a/index/api_swig.c b/index/api_swig.c index 1abcb64..4bb9ab3 100644 --- a/index/api_swig.c +++ b/index/api_swig.c @@ -1,18 +1,26 @@ #include -#include -#include #include -#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 =================================================== */ @@ -24,9 +32,9 @@ void idzebra_api_init(void) /* == 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; @@ -42,27 +50,27 @@ ZebraService idzebra_start(RES_LIST) "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; @@ -74,24 +82,25 @@ ZebraHandle idzebra_open (ZebraService zs, RES_LIST) "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; @@ -99,10 +108,15 @@ IDZEBRA_RES idzebra_samplefunc(ZebraHandle zh, RES_LIST) 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); } @@ -173,6 +187,7 @@ void idzebra_res_estimatehits (ZebraHandle zh, const char *value) zebra_set_approx_limit(zh, val); } +/* void idzebra_res_staticrank (ZebraHandle zh, const char *value) { int val = 0; @@ -180,8 +195,9 @@ void idzebra_res_staticrank (ZebraHandle zh, const char *value) 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 =========================== */ @@ -211,10 +227,12 @@ void arg_use (ZebraHandle zh, } /* 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 */ @@ -230,7 +248,7 @@ void arg_use (ZebraHandle zh, } } -void args_use (ZebraHandle zh, +void args_use (IDZebraSession sess, Res r, Res rr, int mode, @@ -239,7 +257,7 @@ void args_use (ZebraHandle zh, 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++]); } } } diff --git a/index/zebraapi.c b/index/zebraapi.c index e10326f..b92e0b4 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $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 @@ -46,8 +46,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #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); @@ -198,7 +198,7 @@ ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res) if (!passwd_plain && !passwd_encrypt) zh->passwd_db = NULL; - else + else { zh->passwd_db = passwd_db_open(); if (!zh->passwd_db) @@ -1994,7 +1994,7 @@ ZEBRA_RES zebra_octet_term_encoding(ZebraHandle zh, const char *encoding) { 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) -- 1.7.10.4