IDZEBRA  2.1.2
kcontrol.c
Go to the documentation of this file.
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 
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 
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;
66  kc->getseq = key_get_seq;
67 
68  if (zh->m_segment_indexing)
69  {
70  kc->scope = 3; /* segment + seq is "same" record */
72  }
73  else
74  {
75  kc->scope = 2; /* seq is "same" record */
76  kc->get_segment = 0;
77  }
78 
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 
int key_compare(const void *p1, const void *p2)
Definition: it_key.c:73
void(* filter_destroy)(void *data)
Definition: kcontrol.c:28
struct zebra_limit * m_limit
Definition: index.h:232
int(* filter_func)(const void *p, void *data)
Definition: rset.h:135
void(* inc)(struct rset_key_control *kc)
Definition: rset.h:137
void zebra_limit_for_rset(struct zebra_limit *zl, int(**filter_func)(const void *buf, void *data), void(**filter_destroy)(void *data), void **filter_data)
Definition: limit.c:96
zint key_get_seq(const void *p)
Definition: it_key.c:96
int key_size
Definition: rset.h:128
ZebraHandle zh
Definition: zebrash.c:64
struct rset_key_control * zebra_key_control_create(ZebraHandle zh)
Definition: kcontrol.c:57
int(* cmp)(const void *p1, const void *p2)
Definition: rset.h:131
static void my_inc(struct rset_key_control *kc)
Definition: kcontrol.c:31
zint(* getseq)(const void *p)
Definition: rset.h:133
zint key_get_segment(const void *p)
Definition: it_key.c:103
void * filter_data
Definition: rset.h:136
zint(* get_segment)(const void *p)
Definition: rset.h:134
void(* dec)(struct rset_key_control *kc)
Definition: rset.h:138
static void my_dec(struct rset_key_control *kc)
Definition: kcontrol.c:40
int m_segment_indexing
Definition: index.h:206
Definition: it_key.h:30
void key_logdump_txt(int logmask, const void *p, const char *txt)
Definition: it_key.c:37
void(* key_logdump_txt)(int logmask, const void *p, const char *txt)
Definition: rset.h:132
void * context
Definition: rset.h:127