Omit CVS Id. Update copyright year.
[idzebra-moved-to-github.git] / rset / rsisams.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1995-2008 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #include <stdio.h>
21 #include <assert.h>
22 #include <idzebra/util.h>
23 #include <rset.h>
24
25 static RSFD r_open (RSET ct, int flag);
26 static void r_close (RSFD rfd);
27 static void r_delete (RSET ct);
28 static int r_read (RSFD rfd, void *buf, TERMID *term);
29 static int r_write (RSFD rfd, const void *buf);
30 static void r_pos (RSFD rfd, double *current, double *total);
31
32 static const struct rset_control control = 
33 {
34     "isams",
35     r_delete,
36     rset_get_one_term,
37     r_open,
38     r_close,
39     0, /* no forward */
40     r_pos,
41     r_read,
42     r_write,
43 };
44
45 struct rfd_private {
46     ISAMS_PP pt;
47 };
48
49 struct rset_private {
50     ISAMS   is;
51     ISAM_P pos;
52 };
53
54
55 RSET rsisams_create(NMEM nmem, struct rset_key_control *kcontrol,
56                     int scope,
57                     ISAMS is, ISAM_P pos, TERMID term)
58 {
59     RSET rnew = rset_create_base(&control, nmem, kcontrol, scope, term, 0, 0);
60     struct rset_private *info;
61     info = (struct rset_private *) nmem_malloc(rnew->nmem, sizeof(*info));
62     rnew->priv = info;
63     info->is = is;
64     info->pos = pos;
65     return rnew;
66 }
67
68 static void r_delete (RSET ct)
69 {
70     yaz_log (YLOG_DEBUG, "rsisams_delete");
71 }
72
73 RSFD r_open (RSET ct, int flag)
74 {
75     struct rset_private *info = (struct rset_private *) ct->priv;
76     RSFD rfd;
77     struct rfd_private *ptinfo;
78
79     yaz_log (YLOG_DEBUG, "risams_open");
80     if (flag & RSETF_WRITE)
81     {
82         yaz_log (YLOG_FATAL, "ISAMS set type is read-only");
83         return NULL;
84     }
85     rfd = rfd_create_base(ct);
86     if (rfd->priv)
87         ptinfo = (struct rfd_private *)(rfd->priv);
88     else {
89         ptinfo = (struct rfd_private *) nmem_malloc(ct->nmem,sizeof(*ptinfo));
90         rfd->priv = ptinfo;
91     }
92     ptinfo->pt = isams_pp_open (info->is, info->pos);
93     return rfd;
94 }
95
96 static void r_close (RSFD rfd)
97 {
98     struct rfd_private *ptinfo = (struct rfd_private *)(rfd->priv);
99
100     isams_pp_close (ptinfo->pt);
101 }
102
103
104 static int r_read (RSFD rfd, void *buf, TERMID *term)
105 {
106     struct rfd_private *ptinfo = (struct rfd_private *)(rfd->priv);
107     int rc = isams_pp_read(ptinfo->pt, buf);
108     if (rc && term)
109         *term = rfd->rset->term;
110     return rc;
111 }
112
113 static int r_write (RSFD rfd, const void *buf)
114 {
115     yaz_log (YLOG_FATAL, "ISAMS set type is read-only");
116     return -1;
117 }
118
119 static void r_pos (RSFD rfd, double *current, double *total)
120 {
121     *current=-1;  /* sorry, not implemented yet */
122     *total=-1;
123 }
124
125
126 /*
127  * Local variables:
128  * c-basic-offset: 4
129  * indent-tabs-mode: nil
130  * End:
131  * vim: shiftwidth=4 tabstop=8 expandtab
132  */
133