1 /* $Id: rset.h,v 1.32 2004-08-31 10:43:35 heikki Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
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
34 typedef struct rsfd *RSFD; /* Rset "file descriptor" */
35 typedef struct rset *RSET; /* Result set */
37 struct rsfd { /* the stuff common to all rsfd's. */
38 RSET rset; /* ptr to the rset this FD is opened to */
39 void *priv; /* private parameters for this type */
40 RSFD next; /* to keep lists of used/free rsfd's */
46 char *desc; /* text description of set type (for debugging) */
47 /* RSET rs_something_create(const struct rset_control *sel, ...); */
48 void (*f_delete)(RSET ct);
49 RSFD (*f_open)(RSET ct, int wflag);
50 void (*f_close)(RSFD rfd);
51 void (*f_rewind)(RSFD rfd);
52 int (*f_forward)(RSFD rfd, void *buf,
53 int (*cmpfunc)(const void *p1, const void *p2),
54 const void *untilbuf);
55 void (*f_pos)(RSFD rfd, double *current, double *total);
56 /* returns -1,-1 if pos function not implemented for this type */
57 int (*f_read)(RSFD rfd, void *buf);
58 int (*f_write)(RSFD rfd, const void *buf);
61 int rset_default_forward(RSFD rfd, void *buf,
62 int (*cmpfunc)(const void *p1, const void *p2),
63 const void *untilbuf);
68 const struct rset_control *control;
69 int count; /* reference count */
70 void *priv; /* stuff private to the given type of rset */
71 NMEM nmem; /* nibble memory for various allocs */
72 char my_nmem; /* Should the nmem be destroyed with the rset? */
73 /* 1 if created with it, 0 if passed from above */
74 RSFD free_list; /* all rfd's allocated but not currently in use */
76 /* rset is a "virtual base class", which will never exist on its own */
77 /* all instances are rsets of some specific type, like rsisamb, or rsbool */
78 /* They keep their own stuff behind the priv pointer. */
80 RSFD rfd_create_base(RSET rs);
81 void rfd_delete_base(RSFD rfd);
83 RSET rset_create_base(const struct rset_control *sel, NMEM nmem);
84 void rset_delete(RSET rs);
85 RSET rset_dup (RSET rs);
90 /* RSFD rset_open(RSET rs, int wflag); */
91 #define rset_open(rs, wflag) (*(rs)->control->f_open)((rs), (wflag))
93 /* void rset_close(RSFD rfd); */
94 #define rset_close(rfd) (*(rfd)->rset->control->f_close)(rfd)
96 /* void rset_rewind(RSFD rfd); */
97 #define rset_rewind(rfd) (*(rfd)->rset->control->f_rewind)((rfd))
99 /* int rset_forward(RSFD rfd, void *buf, void *untilbuf); */
100 #define rset_forward(rfd, buf, cmpfunc, untilbuf) \
101 (*(rfd)->rset->control->f_forward)((rfd),(buf),(cmpfunc),(untilbuf))
102 /*FIXME - get rid of the cmp function here, keep it in a general */
103 /* key_control block */
105 /* int rset_pos(RSFD fd, double *current, double *total); */
106 #define rset_pos(rfd,cur,tot) \
107 (*(rfd)->rset->control->f_pos)( (rfd),(cur),(tot))
109 /* int rset_read(RSFD rfd, void *buf); */
110 #define rset_read(rfd, buf) (*(rfd)->rset->control->f_read)((rfd), (buf))
112 /* int rset_write(RSFD rfd, const void *buf); */
113 #define rset_write(rfd, buf) (*(rfd)->rset->control->f_write)((rfd), (buf))
115 /* int rset_type (RSET) */
116 #define rset_type(rs) ((rs)->control->desc)