1 /* $Id: rsisamb.c,v 1.28 2004-11-19 10:27:14 heikki Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
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 Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 static RSFD r_open (RSET ct, int flag);
31 static void r_close (RSFD rfd);
32 static void r_delete (RSET ct);
33 static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf);
34 static void r_pos (RSFD rfd, double *current, double *total);
35 static int r_read (RSFD rfd, void *buf, TERMID *term);
36 static int r_write (RSFD rfd, const void *buf);
38 static const struct rset_control control =
51 const struct rset_control *rset_kind_isamb = &control;
58 struct rset_isamb_info {
63 static int log_level = 0;
64 static int log_level_initialized = 0;
66 RSET rsisamb_create( NMEM nmem, const struct key_control *kcontrol, int scope,
67 ISAMB is, ISAMB_P pos, TERMID term)
69 RSET rnew = rset_create_base(&control, nmem, kcontrol, scope, term);
70 struct rset_isamb_info *info;
71 if (!log_level_initialized)
73 log_level = yaz_log_module_level("rsisamb");
74 log_level_initialized = 1;
76 info = (struct rset_isamb_info *) nmem_malloc(rnew->nmem,sizeof(*info));
80 yaz_log(log_level,"rsisamb_create");
84 static void r_delete (RSET ct)
86 yaz_log(log_level, "rsisamb_delete");
89 RSFD r_open (RSET ct, int flag)
91 struct rset_isamb_info *info = (struct rset_isamb_info *) ct->priv;
93 struct rset_pp_info *ptinfo;
95 if (flag & RSETF_WRITE)
97 yaz_log(YLOG_FATAL, "ISAMB set type is read-only");
100 rfd = rfd_create_base(ct);
102 ptinfo = (struct rset_pp_info *) (rfd->priv);
104 ptinfo = (struct rset_pp_info *)nmem_malloc(ct->nmem,sizeof(*ptinfo));
105 ptinfo->buf = nmem_malloc (ct->nmem,ct->keycontrol->key_size);
108 ptinfo->pt = isamb_pp_open (info->is, info->pos, ct->scope );
109 yaz_log(log_level,"rsisamb_open");
113 static void r_close (RSFD rfd)
115 struct rset_pp_info *ptinfo = (struct rset_pp_info *)(rfd->priv);
116 isamb_pp_close (ptinfo->pt);
117 rfd_delete_base(rfd);
118 yaz_log(log_level,"rsisamb_close");
122 static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
124 struct rset_pp_info *pinfo = (struct rset_pp_info *)(rfd->priv);
126 rc = isamb_pp_forward(pinfo->pt, buf, untilbuf);
128 *term = rfd->rset->term;
129 yaz_log(log_level,"rsisamb_forward");
133 static void r_pos (RSFD rfd, double *current, double *total)
135 struct rset_pp_info *pinfo = (struct rset_pp_info *)(rfd->priv);
137 isamb_pp_pos(pinfo->pt, current, total);
138 yaz_log(log_level,"isamb.r_pos returning %0.1f/%0.1f",
142 static int r_read (RSFD rfd, void *buf, TERMID *term)
144 struct rset_pp_info *pinfo = (struct rset_pp_info *)(rfd->priv);
146 rc = isamb_pp_read(pinfo->pt, buf);
148 *term = rfd->rset->term;
149 yaz_log(log_level,"isamb.r_read ");
153 static int r_write (RSFD rfd, const void *buf)
155 yaz_log(YLOG_FATAL, "ISAMB set type is read-only");