28bb5e5e7257a9aa0b3d1bd197133fb964f4173f
[idzebra-moved-to-github.git] / rset / rsisams.c
1 /* $Id: rsisams.c,v 1.19 2005-03-30 09:25:24 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
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
10 version.
11
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
15 for more details.
16
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
20 02111-1307, USA.
21 */
22
23
24
25 #include <stdio.h>
26 #include <assert.h>
27 #include <idzebra/util.h>
28 #include <rset.h>
29
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_read (RSFD rfd, void *buf, TERMID *term);
34 static int r_write (RSFD rfd, const void *buf);
35 static void r_pos (RSFD rfd, double *current, double *total);
36
37 static const struct rset_control control = 
38 {
39     "isams",
40     r_delete,
41     rset_get_one_term,
42     r_open,
43     r_close,
44     rset_default_forward,
45     r_pos,
46     r_read,
47     r_write,
48 };
49
50 const struct rset_control *rset_kind_isams = &control;
51
52 struct rset_pp_info {
53     ISAMS_PP pt;
54 };
55
56 struct rset_isams_info {
57     ISAMS   is;
58     ISAMS_P pos;
59 };
60
61
62 RSET rsisams_create( NMEM nmem, const struct key_control *kcontrol, int scope,
63             ISAMS is, ISAMS_P pos, TERMID term)
64 {
65     RSET rnew=rset_create_base(&control, nmem, kcontrol, scope, term);
66     struct rset_isams_info *info;
67     info = (struct rset_isams_info *) nmem_malloc(rnew->nmem,sizeof(*info));
68     rnew->priv=info;
69     info->is=is;
70     info->pos=pos;
71     return rnew;
72 }
73
74 static void r_delete (RSET ct)
75 {
76     yaz_log (YLOG_DEBUG, "rsisams_delete");
77     rset_delete(ct);
78 }
79
80
81 RSFD r_open (RSET ct, int flag)
82 {
83     struct rset_isams_info *info = (struct rset_isams_info *) ct->priv;
84     RSFD rfd;
85     struct rset_pp_info *ptinfo;
86
87     yaz_log (YLOG_DEBUG, "risams_open");
88     if (flag & RSETF_WRITE)
89     {
90         yaz_log (YLOG_FATAL, "ISAMS set type is read-only");
91         return NULL;
92     }
93     rfd=rfd_create_base(ct);
94     if (rfd->priv)
95         ptinfo=(struct rset_pp_info *)(rfd->priv);
96     else {
97         ptinfo = (struct rset_pp_info *) nmem_malloc(ct->nmem,sizeof(*ptinfo));
98         ptinfo->pt = isams_pp_open (info->is, info->pos);
99         rfd->priv=ptinfo;
100     }
101     return rfd;
102 }
103
104 static void r_close (RSFD rfd)
105 {
106     struct rset_pp_info *ptinfo=(struct rset_pp_info *)(rfd->priv);
107
108     isams_pp_close (ptinfo->pt);
109     rfd_delete_base(rfd);
110 }
111
112
113 static int r_read (RSFD rfd, void *buf, TERMID *term)
114 {
115     struct rset_pp_info *ptinfo=(struct rset_pp_info *)(rfd->priv);
116     int rc;
117     rc=isams_pp_read(ptinfo->pt, buf);
118     if (rc && term)
119         *term=rfd->rset->term;
120     return rc;
121 }
122
123 static int r_write (RSFD rfd, const void *buf)
124 {
125     yaz_log (YLOG_FATAL, "ISAMS set type is read-only");
126     return -1;
127 }
128
129 static void r_pos (RSFD rfd, double *current, double *total)
130 {
131     *current=-1;  /* sorry, not implemented yet */
132     *total=-1;
133 }
134
135