1 /* $Id: rsisamb.c,v 1.16 2004-08-23 12:38:53 heikki Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
5 This file is part of the Zebra server.
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
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
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
28 #include <../index/index.h> /* for log_keydump. Debugging only */
34 static void *r_create(RSET ct, const struct rset_control *sel, void *parms);
35 static RSFD r_open (RSET ct, int flag);
36 static void r_close (RSFD rfd);
37 static void r_delete (RSET ct);
38 static void r_rewind (RSFD rfd);
39 static int r_forward(RSET ct, RSFD rfd, void *buf,
40 int (*cmpfunc)(const void *p1, const void *p2),
41 const void *untilbuf);
42 static void r_pos (RSFD rfd, double *current, double *total);
43 static int r_read (RSFD rfd, void *buf);
44 static int r_write (RSFD rfd, const void *buf);
46 static const struct rset_control control =
54 r_forward, /* rset_default_forward, */
60 const struct rset_control *rset_kind_isamb = &control;
64 struct rset_pp_info *next;
65 struct rset_isamb_info *info;
69 struct rset_isamb_info {
73 int (*cmp)(const void *p1, const void *p2);
74 struct rset_pp_info *ispt_list;
77 static void *r_create(RSET ct, const struct rset_control *sel, void *parms)
79 rset_isamb_parms *pt = (rset_isamb_parms *) parms;
80 struct rset_isamb_info *info;
82 info = (struct rset_isamb_info *) xmalloc (sizeof(*info));
85 info->key_size = pt->key_size;
87 info->ispt_list = NULL;
91 RSFD r_open (RSET ct, int flag)
93 struct rset_isamb_info *info = (struct rset_isamb_info *) ct->buf;
94 struct rset_pp_info *ptinfo;
96 logf (LOG_DEBUG, "risamb_open");
97 if (flag & RSETF_WRITE)
99 logf (LOG_FATAL, "ISAMB set type is read-only");
102 ptinfo = (struct rset_pp_info *) xmalloc (sizeof(*ptinfo));
103 ptinfo->next = info->ispt_list;
104 info->ispt_list = ptinfo;
105 ptinfo->pt = isamb_pp_open (info->is, info->pos);
107 ptinfo->buf = xmalloc (info->key_size);
111 static void r_close (RSFD rfd)
113 struct rset_isamb_info *info = ((struct rset_pp_info*) rfd)->info;
114 struct rset_pp_info **ptinfop;
116 for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
119 xfree ((*ptinfop)->buf);
120 isamb_pp_close ((*ptinfop)->pt);
121 *ptinfop = (*ptinfop)->next;
125 logf (LOG_FATAL, "r_close but no rfd match!");
129 static void r_delete (RSET ct)
131 struct rset_isamb_info *info = (struct rset_isamb_info *) ct->buf;
133 logf (LOG_DEBUG, "rsisamb_delete");
134 assert (info->ispt_list == NULL);
138 static void r_rewind (RSFD rfd)
140 logf (LOG_DEBUG, "rsisamb_rewind");
144 static int r_forward(RSET ct, RSFD rfd, void *buf,
145 int (*cmpfunc)(const void *p1, const void *p2),
146 const void *untilbuf)
149 struct rset_pp_info *pinfo = (struct rset_pp_info *) rfd;
151 logf (LOG_DEBUG, "rset_rsisamb_forward starting '%s' (ct=%p rfd=%p)",
152 ct->control->desc, ct,rfd);
153 key_logdump(LOG_DEBUG, untilbuf);
154 key_logdump(LOG_DEBUG, buf);
157 i=isamb_pp_forward(pinfo->pt, buf, untilbuf);
159 logf (LOG_DEBUG, "rset_rsisamb_forward returning %d",i);
164 static void r_pos (RSFD rfd, double *current, double *total)
166 struct rset_pp_info *pinfo = (struct rset_pp_info *) rfd;
168 isamb_pp_pos(pinfo->pt, current, total);
170 logf(LOG_DEBUG,"isamb.r_pos returning %0.1f/%0.1f",
175 static int r_read (RSFD rfd, void *buf)
177 struct rset_pp_info *pinfo = (struct rset_pp_info *) rfd;
180 r = isamb_pp_read(pinfo->pt, buf);
184 static int r_write (RSFD rfd, const void *buf)
186 logf (LOG_FATAL, "ISAMB set type is read-only");