1 /* This file is part of the Zebra server.
2 Copyright (C) 2004-2013 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 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
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 0, /* no forward */
43 r_pos,
44 r_read,
45 r_write,
46 };
47
48 struct rfd_private {
49 ISAMS_PP pt;
50 };
51
52 struct rset_private {
53 ISAMS is;
54 ISAM_P pos;
55 };
56
57
rsisams_create(NMEM nmem,struct rset_key_control * kcontrol,int scope,ISAMS is,ISAM_P pos,TERMID term)58 RSET rsisams_create(NMEM nmem, struct rset_key_control *kcontrol,
59 int scope,
60 ISAMS is, ISAM_P pos, TERMID term)
61 {
62 RSET rnew = rset_create_base(&control, nmem, kcontrol, scope, term, 0, 0);
63 struct rset_private *info;
64 info = (struct rset_private *) nmem_malloc(rnew->nmem, sizeof(*info));
65 rnew->priv = info;
66 info->is = is;
67 info->pos = pos;
68 return rnew;
69 }
70
r_delete(RSET ct)71 static void r_delete (RSET ct)
72 {
73 yaz_log (YLOG_DEBUG, "rsisams_delete");
74 }
75
r_open(RSET ct,int flag)76 RSFD r_open (RSET ct, int flag)
77 {
78 struct rset_private *info = (struct rset_private *) ct->priv;
79 RSFD rfd;
80 struct rfd_private *ptinfo;
81
82 yaz_log (YLOG_DEBUG, "risams_open");
83 if (flag & RSETF_WRITE)
84 {
85 yaz_log (YLOG_FATAL, "ISAMS set type is read-only");
86 return NULL;
87 }
88 rfd = rfd_create_base(ct);
89 if (rfd->priv)
90 ptinfo = (struct rfd_private *)(rfd->priv);
91 else {
92 ptinfo = (struct rfd_private *) nmem_malloc(ct->nmem,sizeof(*ptinfo));
93 rfd->priv = ptinfo;
94 }
95 ptinfo->pt = isams_pp_open (info->is, info->pos);
96 return rfd;
97 }
98
r_close(RSFD rfd)99 static void r_close (RSFD rfd)
100 {
101 struct rfd_private *ptinfo = (struct rfd_private *)(rfd->priv);
102
103 isams_pp_close (ptinfo->pt);
104 }
105
106
r_read(RSFD rfd,void * buf,TERMID * term)107 static int r_read (RSFD rfd, void *buf, TERMID *term)
108 {
109 struct rfd_private *ptinfo = (struct rfd_private *)(rfd->priv);
110 int rc = isams_pp_read(ptinfo->pt, buf);
111 if (rc && term)
112 *term = rfd->rset->term;
113 return rc;
114 }
115
r_write(RSFD rfd,const void * buf)116 static int r_write (RSFD rfd, const void *buf)
117 {
118 yaz_log (YLOG_FATAL, "ISAMS set type is read-only");
119 return -1;
120 }
121
r_pos(RSFD rfd,double * current,double * total)122 static void r_pos (RSFD rfd, double *current, double *total)
123 {
124 *current=-1; /* sorry, not implemented yet */
125 *total=-1;
126 }
127
128
129 /*
130 * Local variables:
131 * c-basic-offset: 4
132 * c-file-style: "Stroustrup"
133 * indent-tabs-mode: nil
134 * End:
135 * vim: shiftwidth=4 tabstop=8 expandtab
136 */
137
138