Updated footer comment
[idzebra-moved-to-github.git] / index / kcontrol.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2009 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #include <assert.h>
21 #include "index.h"
22
23 struct context_control {
24     int ref_count;
25     void (*filter_destroy)(void *data);
26 };
27
28 static void my_inc(struct rset_key_control *kc)
29 {
30     struct context_control *cp;
31
32     assert(kc);
33     cp = kc->context;
34     (cp->ref_count)++;
35 }
36
37 static void my_dec(struct rset_key_control *kc)
38 {
39     struct context_control *cp;
40
41     assert(kc);
42     cp = kc->context;
43     (cp->ref_count)--;
44     if (cp->ref_count == 0)
45     {
46         if (cp->filter_destroy)
47             (*cp->filter_destroy)(kc->filter_data);
48         xfree(cp);
49         xfree(kc);
50     }
51 }
52
53
54 struct rset_key_control *zebra_key_control_create(ZebraHandle zh)
55 {
56     struct rset_key_control *kc = xmalloc(sizeof(*kc));
57     struct context_control *cp = xmalloc(sizeof(*cp));
58
59     kc->context = cp;
60     kc->key_size = sizeof(struct it_key);
61     kc->cmp = key_compare_it;
62     kc->key_logdump_txt = key_logdump_txt;
63     kc->getseq = key_get_seq;
64
65     if (zh->m_segment_indexing)
66     {
67         kc->scope = 3;  /* segment + seq is "same" record */
68         kc->get_segment = key_get_segment;
69     }
70     else
71     {
72         kc->scope = 2;  /* seq is "same" record */
73         kc->get_segment = 0;
74     }
75
76     zebra_limit_for_rset(zh->m_limit, 
77                          &kc->filter_func,
78                          &cp->filter_destroy,
79                          &kc->filter_data);
80     kc->inc = my_inc;
81     kc->dec = my_dec;
82     cp->ref_count = 1;
83     return kc;
84 }
85
86 /*
87  * Local variables:
88  * c-basic-offset: 4
89  * c-file-style: "Stroustrup"
90  * indent-tabs-mode: nil
91  * End:
92  * vim: shiftwidth=4 tabstop=8 expandtab
93  */
94