Do not build for Ubuntu raring, quantal (obsolete)
[idzebra-moved-to-github.git] / index / kcontrol.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 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 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
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
57 struct rset_key_control *zebra_key_control_create(ZebraHandle zh)
58 {
59     struct rset_key_control *kc = xmalloc(sizeof(*kc));
60     struct context_control *cp = xmalloc(sizeof(*cp));
61
62     kc->context = cp;
63     kc->key_size = sizeof(struct it_key);
64     kc->cmp = key_compare;
65     kc->key_logdump_txt = key_logdump_txt;
66     kc->getseq = key_get_seq;
67
68     if (zh->m_segment_indexing)
69     {
70         kc->scope = 3;  /* segment + seq is "same" record */
71         kc->get_segment = key_get_segment;
72     }
73     else
74     {
75         kc->scope = 2;  /* seq is "same" record */
76         kc->get_segment = 0;
77     }
78
79     zebra_limit_for_rset(zh->m_limit,
80                          &kc->filter_func,
81                          &cp->filter_destroy,
82                          &kc->filter_data);
83     kc->inc = my_inc;
84     kc->dec = my_dec;
85     cp->ref_count = 1;
86     return kc;
87 }
88
89 /*
90  * Local variables:
91  * c-basic-offset: 4
92  * c-file-style: "Stroustrup"
93  * indent-tabs-mode: nil
94  * End:
95  * vim: shiftwidth=4 tabstop=8 expandtab
96  */
97