1 /* $Id: rsisamb.c,v 1.37 2006-08-14 10:40:21 adam Exp $
2 Copyright (C) 1995-2006
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <idzebra/util.h>
29 static RSFD r_open(RSET ct, int flag);
30 static void r_close(RSFD rfd);
31 static void r_delete(RSET ct);
32 static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf);
33 static void r_pos(RSFD rfd, double *current, double *total);
34 static int r_read(RSFD rfd, void *buf, TERMID *term);
35 static int r_read_filter(RSFD rfd, void *buf, TERMID *term);
36 static int r_write(RSFD rfd, const void *buf);
38 static const struct rset_control control =
51 static const struct rset_control control_filter =
74 static int log_level = 0;
75 static int log_level_initialized = 0;
77 RSET rsisamb_create(NMEM nmem, struct rset_key_control *kcontrol,
79 ISAMB is, ISAM_P pos, TERMID term)
81 RSET rnew = rset_create_base(
82 kcontrol->filter_func ? &control_filter : &control,
83 nmem, kcontrol, scope, term, 0, 0);
84 struct rset_private *info;
86 if (!log_level_initialized)
88 log_level = yaz_log_module_level("rsisamb");
89 log_level_initialized = 1;
91 info = (struct rset_private *) nmem_malloc(rnew->nmem, sizeof(*info));
95 yaz_log(log_level, "rsisamb_create");
99 static void r_delete(RSET ct)
101 yaz_log(log_level, "rsisamb_delete");
104 RSFD r_open(RSET ct, int flag)
106 struct rset_private *info = (struct rset_private *) ct->priv;
108 struct rfd_private *ptinfo;
110 if (flag & RSETF_WRITE)
112 yaz_log(YLOG_FATAL, "ISAMB set type is read-only");
115 rfd = rfd_create_base(ct);
117 ptinfo = (struct rfd_private *) (rfd->priv);
119 ptinfo = (struct rfd_private *) nmem_malloc(ct->nmem,sizeof(*ptinfo));
120 ptinfo->buf = nmem_malloc(ct->nmem,ct->keycontrol->key_size);
123 ptinfo->pt = isamb_pp_open(info->is, info->pos, ct->scope );
124 yaz_log(log_level, "rsisamb_open");
128 static void r_close(RSFD rfd)
130 struct rfd_private *ptinfo = (struct rfd_private *)(rfd->priv);
131 isamb_pp_close (ptinfo->pt);
132 yaz_log(log_level, "rsisamb_close");
136 static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
138 struct rfd_private *pinfo = (struct rfd_private *)(rfd->priv);
140 rc = isamb_pp_forward(pinfo->pt, buf, untilbuf);
142 *term = rfd->rset->term;
143 yaz_log(log_level, "rsisamb_forward");
147 static void r_pos(RSFD rfd, double *current, double *total)
149 struct rfd_private *pinfo = (struct rfd_private *)(rfd->priv);
151 isamb_pp_pos(pinfo->pt, current, total);
152 yaz_log(log_level, "isamb.r_pos returning %0.1f/%0.1f",
156 static int r_read(RSFD rfd, void *buf, TERMID *term)
158 struct rfd_private *pinfo = (struct rfd_private *)(rfd->priv);
160 rc = isamb_pp_read(pinfo->pt, buf);
162 *term = rfd->rset->term;
163 yaz_log(log_level, "isamb.r_read ");
167 static int r_read_filter(RSFD rfd, void *buf, TERMID *term)
169 struct rfd_private *pinfo = (struct rfd_private *)rfd->priv;
170 const struct rset_key_control *kctrl = rfd->rset->keycontrol;
172 while((rc = isamb_pp_read(pinfo->pt, buf)))
174 int incl = (*kctrl->filter_func)(buf, kctrl->filter_data);
179 *term = rfd->rset->term;
180 yaz_log(log_level, "isamb.r_read_filter");
184 static int r_write(RSFD rfd, const void *buf)
186 yaz_log(YLOG_FATAL, "ISAMB set type is read-only");
192 * indent-tabs-mode: nil
194 * vim: shiftwidth=4 tabstop=8 expandtab