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