Extended the result set system. Added support for filtering/limits.
[idzebra-moved-to-github.git] / index / kcontrol.c
1 /* $Id: kcontrol.c,v 1.1 2005-05-03 09:11:34 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 <assert.h>
24 #include "index.h"
25
26 struct context_control {
27     int ref_count;
28     void (*filter_destroy)(void *data);
29 };
30
31 static void my_inc(struct rset_key_control *kc)
32 {
33     struct context_control *cp;
34
35     assert(kc);
36     cp = kc->context;
37     (cp->ref_count)++;
38 }
39
40 static void my_dec(struct rset_key_control *kc)
41 {
42     struct context_control *cp;
43
44     assert(kc);
45     cp = kc->context;
46     (cp->ref_count)--;
47     if (cp->ref_count == 0)
48     {
49         if (cp->filter_destroy)
50             (*cp->filter_destroy)(kc->filter_data);
51         xfree(cp);
52         xfree(kc);
53     }
54 }
55
56 struct rset_key_control *zebra_key_control_create(ZebraHandle zh)
57 {
58     struct rset_key_control *kc = xmalloc(sizeof(*kc));
59     struct context_control *cp = xmalloc(sizeof(*cp));
60
61     kc->context = cp;
62     kc->key_size = sizeof(struct it_key);
63     kc->scope = 2;
64     kc->cmp = key_compare_it;
65     kc->key_logdump_txt = key_logdump_txt;
66     kc->getseq = key_get_seq;
67     zebra_limit_for_rset(zh->m_limit, 
68                          &kc->filter_func,
69                          &cp->filter_destroy,
70                          &kc->filter_data);
71     kc->inc = my_inc;
72     kc->dec = my_dec;
73     cp->ref_count = 1;
74     return kc;
75 }
76