1 /* $Id: rsisamb.c,v 1.32 2005-04-26 10:09:38 adam Exp $
2 Copyright (C) 1995-2005
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
25 #include <idzebra/util.h>
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 =
56 struct rset_isamb_info {
61 static int log_level = 0;
62 static int log_level_initialized = 0;
64 RSET rsisamb_create(NMEM nmem, const struct key_control *kcontrol, int scope,
65 ISAMB is, ISAM_P pos, TERMID term)
67 RSET rnew = rset_create_base(&control, nmem, kcontrol, scope, term);
68 struct rset_isamb_info *info;
69 if (!log_level_initialized)
71 log_level = yaz_log_module_level("rsisamb");
72 log_level_initialized = 1;
74 info = (struct rset_isamb_info *) nmem_malloc(rnew->nmem,sizeof(*info));
78 yaz_log(log_level,"rsisamb_create");
82 static void r_delete (RSET ct)
84 yaz_log(log_level, "rsisamb_delete");
87 RSFD r_open (RSET ct, int flag)
89 struct rset_isamb_info *info = (struct rset_isamb_info *) ct->priv;
91 struct rset_pp_info *ptinfo;
93 if (flag & RSETF_WRITE)
95 yaz_log(YLOG_FATAL, "ISAMB set type is read-only");
98 rfd = rfd_create_base(ct);
100 ptinfo = (struct rset_pp_info *) (rfd->priv);
102 ptinfo = (struct rset_pp_info *)nmem_malloc(ct->nmem,sizeof(*ptinfo));
103 ptinfo->buf = nmem_malloc (ct->nmem,ct->keycontrol->key_size);
106 ptinfo->pt = isamb_pp_open (info->is, info->pos, ct->scope );
107 yaz_log(log_level,"rsisamb_open");
111 static void r_close (RSFD rfd)
113 struct rset_pp_info *ptinfo = (struct rset_pp_info *)(rfd->priv);
114 isamb_pp_close (ptinfo->pt);
115 rfd_delete_base(rfd);
116 yaz_log(log_level,"rsisamb_close");
120 static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
122 struct rset_pp_info *pinfo = (struct rset_pp_info *)(rfd->priv);
124 rc = isamb_pp_forward(pinfo->pt, buf, untilbuf);
126 *term = rfd->rset->term;
127 yaz_log(log_level,"rsisamb_forward");
131 static void r_pos (RSFD rfd, double *current, double *total)
133 struct rset_pp_info *pinfo = (struct rset_pp_info *)(rfd->priv);
135 isamb_pp_pos(pinfo->pt, current, total);
136 yaz_log(log_level,"isamb.r_pos returning %0.1f/%0.1f",
140 static int r_read (RSFD rfd, void *buf, TERMID *term)
142 struct rset_pp_info *pinfo = (struct rset_pp_info *)(rfd->priv);
144 rc = isamb_pp_read(pinfo->pt, buf);
146 *term = rfd->rset->term;
147 yaz_log(log_level,"isamb.r_read ");
151 static int r_write (RSFD rfd, const void *buf)
153 yaz_log(YLOG_FATAL, "ISAMB set type is read-only");