Remove the obsolete rset public control variables. WS updates.
[idzebra-moved-to-github.git] / rset / rsisamc.c
1 /* $Id: rsisamc.c,v 1.38 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 <string.h>
26 #include <idzebra/util.h>
27 #include <rset.h>
28
29 static RSFD r_open (RSET ct, int flag);
30 static void r_close (RSFD rfd);
31 static void r_delete (RSET ct);
32 static int r_read (RSFD rfd, void *buf, TERMID *term);
33 static int r_write (RSFD rfd, const void *buf);
34 static void r_pos (RSFD rfd, double *current, double *total);
35
36 static const struct rset_control control = 
37 {
38     "isamc",
39     r_delete,
40     rset_get_one_term,
41     r_open,
42     r_close,
43     rset_default_forward,
44     r_pos,
45     r_read,
46     r_write,
47 };
48
49 struct rset_pp_info {
50     ISAMC_PP pt;
51     void *buf;
52 };
53
54 struct rset_isamc_info {
55     ISAMC   is;
56     ISAM_P pos;
57 };
58
59 static int log_level = 0;
60 static int log_level_initialized = 0;
61
62 RSET rsisamc_create(NMEM nmem, const struct key_control *kcontrol, int scope,
63                     ISAMC is, ISAM_P pos, TERMID term)
64 {
65     RSET rnew = rset_create_base(&control, nmem, kcontrol, scope,term);
66     struct rset_isamc_info *info;
67     if (!log_level_initialized)
68     {
69         log_level = yaz_log_module_level("rsisamc");
70         log_level_initialized = 1;
71     }
72     info = (struct rset_isamc_info *) nmem_malloc(rnew->nmem,sizeof(*info));
73     info->is = is;
74     info->pos = pos;
75     rnew->priv = info;
76     yaz_log(log_level, "create: term=%p", term);
77     return rnew;
78 }
79
80 static void r_delete (RSET ct)
81 {
82     yaz_log(log_level, "rsisamc_delete");
83 }
84
85
86 RSFD r_open (RSET ct, int flag)
87 {
88     struct rset_isamc_info *info = (struct rset_isamc_info *) ct->priv;
89     RSFD rfd;
90     struct rset_pp_info *ptinfo;
91
92     yaz_log(log_level, "risamc_open");
93     if (flag & RSETF_WRITE)
94     {
95         yaz_log(YLOG_FATAL, "ISAMC 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         rfd->priv = ptinfo;
104         ptinfo->buf = nmem_malloc (ct->nmem,ct->keycontrol->key_size);
105     }
106     ptinfo->pt = isamc_pp_open(info->is, info->pos);
107     return rfd;
108 }
109
110 static void r_close (RSFD rfd)
111 {
112     struct rset_pp_info *p = (struct rset_pp_info *)(rfd->priv);
113
114     isamc_pp_close(p->pt);
115     rfd_delete_base(rfd);
116 }
117
118
119 static int r_read (RSFD rfd, void *buf, TERMID *term)
120 {
121     struct rset_pp_info *p = (struct rset_pp_info *)(rfd->priv);
122     int r;
123     r = isamc_pp_read(p->pt, buf);
124     if (term)
125         *term = rfd->rset->term;
126     yaz_log(log_level, "isamc.r_read");
127     return r;
128 }
129
130 static int r_write (RSFD rfd, const void *buf)
131 {
132     yaz_log(YLOG_FATAL, "ISAMC set type is read-only");
133     return -1;
134 }
135
136 static void r_pos (RSFD rfd, double *current, double *total)
137 {
138     *current = -1;  /* sorry, not implemented yet */
139     *total = -1;
140 }
141
142
143