Remove the obsolete rset public control variables. WS updates.
[idzebra-moved-to-github.git] / rset / rsisamb.c
1 /* $Id: rsisamb.c,v 1.32 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 #include <string.h>
28
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_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);
37
38 static const struct rset_control control = 
39 {
40     "isamb",
41     r_delete,
42     rset_get_one_term,
43     r_open,
44     r_close,
45     r_forward, 
46     r_pos,
47     r_read,
48     r_write,
49 };
50
51 struct rset_pp_info {
52     ISAMB_PP pt;
53     void *buf;
54 };
55
56 struct rset_isamb_info {
57     ISAMB   is;
58     ISAM_P pos;
59 };
60
61 static int log_level = 0;
62 static int log_level_initialized = 0;
63
64 RSET rsisamb_create(NMEM nmem, const struct key_control *kcontrol, int scope,
65                     ISAMB is, ISAM_P pos, TERMID term)
66 {
67     RSET rnew = rset_create_base(&control, nmem, kcontrol, scope, term);
68     struct rset_isamb_info *info;
69     if (!log_level_initialized)
70     {
71         log_level = yaz_log_module_level("rsisamb");
72         log_level_initialized = 1;
73     }
74     info = (struct rset_isamb_info *) nmem_malloc(rnew->nmem,sizeof(*info));
75     info->is = is;
76     info->pos = pos;
77     rnew->priv = info;
78     yaz_log(log_level,"rsisamb_create");
79     return rnew;
80 }
81
82 static void r_delete (RSET ct)
83 {
84     yaz_log(log_level, "rsisamb_delete");
85 }
86
87 RSFD r_open (RSET ct, int flag)
88 {
89     struct rset_isamb_info *info = (struct rset_isamb_info *) ct->priv;
90     RSFD rfd;
91     struct rset_pp_info *ptinfo;
92
93     if (flag & RSETF_WRITE)
94     {
95         yaz_log(YLOG_FATAL, "ISAMB set type is read-only");
96         return NULL;
97     }
98     rfd = rfd_create_base(ct);
99     if (rfd->priv)
100         ptinfo = (struct rset_pp_info *) (rfd->priv);
101     else {
102         ptinfo = (struct rset_pp_info *)nmem_malloc(ct->nmem,sizeof(*ptinfo));
103         ptinfo->buf = nmem_malloc (ct->nmem,ct->keycontrol->key_size);
104         rfd->priv = ptinfo;
105     }
106     ptinfo->pt = isamb_pp_open (info->is, info->pos, ct->scope );
107     yaz_log(log_level,"rsisamb_open");
108     return rfd;
109 }
110
111 static void r_close (RSFD rfd)
112 {
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");
117 }
118
119
120 static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
121 {
122     struct rset_pp_info *pinfo = (struct rset_pp_info *)(rfd->priv);
123     int rc;
124     rc = isamb_pp_forward(pinfo->pt, buf, untilbuf);
125     if (rc && term)
126         *term = rfd->rset->term;
127     yaz_log(log_level,"rsisamb_forward");
128     return rc; 
129 }
130
131 static void r_pos (RSFD rfd, double *current, double *total)
132 {
133     struct rset_pp_info *pinfo = (struct rset_pp_info *)(rfd->priv);
134     assert(rfd);
135     isamb_pp_pos(pinfo->pt, current, total);
136     yaz_log(log_level,"isamb.r_pos returning %0.1f/%0.1f",
137               *current, *total);
138 }
139
140 static int r_read (RSFD rfd, void *buf, TERMID *term)
141 {
142     struct rset_pp_info *pinfo = (struct rset_pp_info *)(rfd->priv);
143     int rc;
144     rc = isamb_pp_read(pinfo->pt, buf);
145     if (rc && term)
146         *term = rfd->rset->term;
147     yaz_log(log_level,"isamb.r_read ");
148     return rc;
149 }
150
151 static int r_write (RSFD rfd, const void *buf)
152 {
153     yaz_log(YLOG_FATAL, "ISAMB set type is read-only");
154     return -1;
155 }