IDZEBRA  2.1.2
rsisamc.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 <stdio.h>
24 #include <assert.h>
25 #include <string.h>
26 #include <idzebra/util.h>
27 #include <rset.h>
28 
29 static RSFD r_open (RSET ct, int flag);
30 static void r_close (RSFD rfd);
31 static void r_delete (RSET ct);
32 static int r_read (RSFD rfd, void *buf, TERMID *term);
33 static void r_pos (RSFD rfd, double *current, double *total);
34 
35 static const struct rset_control control =
36 {
37  "isamc",
38  r_delete,
40  r_open,
41  r_close,
42  0, /* no forward */
43  r_pos,
44  r_read,
46 };
47 
48 struct rset_pp_info {
50  void *buf;
51 };
52 
56 };
57 
58 static int log_level = 0;
59 static int log_level_initialized = 0;
60 
61 RSET rsisamc_create(NMEM nmem, struct rset_key_control *kcontrol,
62  int scope,
63  ISAMC is, ISAM_P pos, TERMID term)
64 {
65  RSET rnew = rset_create_base(&control, nmem, kcontrol, scope, term, 0, 0);
66  struct rset_isamc_info *info;
68  {
69  log_level = yaz_log_module_level("rsisamc");
71  }
72  info = (struct rset_isamc_info *) nmem_malloc(rnew->nmem, sizeof(*info));
73  info->is = is;
74  info->pos = pos;
75  rnew->priv = info;
76  yaz_log(log_level, "create: term=%p", term);
77  return rnew;
78 }
79 
80 static void r_delete (RSET ct)
81 {
82  yaz_log(log_level, "rsisamc_delete");
83 }
84 
85 
86 RSFD r_open (RSET ct, int flag)
87 {
88  struct rset_isamc_info *info = (struct rset_isamc_info *) ct->priv;
89  RSFD rfd;
90  struct rset_pp_info *ptinfo;
91 
92  yaz_log(log_level, "risamc_open");
93  if (flag & RSETF_WRITE)
94  {
95  yaz_log(YLOG_FATAL, "ISAMC set type is read-only");
96  return NULL;
97  }
98  rfd = rfd_create_base(ct);
99  if (rfd->priv)
100  ptinfo = (struct rset_pp_info *)rfd->priv;
101  else {
102  ptinfo = (struct rset_pp_info *) nmem_malloc (ct->nmem,sizeof(*ptinfo));
103  rfd->priv = ptinfo;
104  ptinfo->buf = nmem_malloc (ct->nmem,ct->keycontrol->key_size);
105  }
106  ptinfo->pt = isamc_pp_open(info->is, info->pos);
107  return rfd;
108 }
109 
110 static void r_close (RSFD rfd)
111 {
112  struct rset_pp_info *p = (struct rset_pp_info *)(rfd->priv);
113 
114  isamc_pp_close(p->pt);
115 }
116 
117 
118 static int r_read (RSFD rfd, void *buf, TERMID *term)
119 {
120  struct rset_pp_info *p = (struct rset_pp_info *)(rfd->priv);
121  int r;
122  r = isamc_pp_read(p->pt, buf);
123  if (term)
124  *term = rfd->rset->term;
125  yaz_log(log_level, "isamc.r_read");
126  return r;
127 }
128 
129 static void r_pos (RSFD rfd, double *current, double *total)
130 {
131  *current = -1; /* sorry, not implemented yet */
132  *total = -1;
133 }
134 
135 
136 /*
137  * Local variables:
138  * c-basic-offset: 4
139  * c-file-style: "Stroustrup"
140  * indent-tabs-mode: nil
141  * End:
142  * vim: shiftwidth=4 tabstop=8 expandtab
143  */
144 
void * buf
Definition: rsisamb.c:65
void isamc_pp_close(ISAMC_PP pp)
Definition: isamc.c:457
ISAMC_PP pt
Definition: rsisamc.c:49
void * buf
Definition: rsisamc.c:50
TERMID term
Definition: rset.h:160
zint ISAM_P
Definition: isamc.h:28
struct rset_key_control * keycontrol
Definition: rset.h:153
static int r_read(RSFD rfd, void *buf, TERMID *term)
Definition: rsisamc.c:118
RSFD rfd_create_base(RSET rs)
Common constuctor for RFDs.
Definition: rset.c:43
static int log_level
Definition: rsisamc.c:58
int key_size
Definition: rset.h:128
static const struct rset_control control
Definition: rsisamc.c:35
ISAM_P pos
Definition: rsisamc.c:55
int rset_no_write(RSFD rfd, const void *buf)
Definition: rset.c:431
RSET rset
Definition: rset.h:74
const char * scope
Definition: tstlockscope.c:40
void * priv
Definition: rset.h:155
static void r_delete(RSET ct)
Definition: rsisamc.c:80
static int log_level_initialized
Definition: rsisamc.c:59
static void r_pos(RSFD rfd, double *current, double *total)
Definition: rsisamc.c:129
void rset_get_one_term(RSET ct, TERMID *terms, int maxterms, int *curterm)
is a getterms function for those that don&#39;t have any
Definition: rset.c:291
RSET rsisamc_create(NMEM nmem, struct rset_key_control *kcontrol, int scope, ISAMC is, ISAM_P pos, TERMID term)
Definition: rsisamc.c:61
NMEM nmem
Definition: rset.h:156
static RSFD r_open(RSET ct, int flag)
Definition: rsisamc.c:86
Definition: rset.h:150
Definition: rset.h:73
int isamc_pp_read(ISAMC_PP pp, void *buf)
Definition: isamc.c:510
void * priv
Definition: rset.h:75
Definition: rset.h:50
ISAMC_PP isamc_pp_open(ISAMC is, ISAM_P pos)
Definition: isamc.c:466
RSET rset_create_base(const struct rset_control *sel, NMEM nmem, struct rset_key_control *kcontrol, int scope, TERMID term, int no_children, RSET *children)
Common constuctor for RSETs.
Definition: rset.c:164
#define RSETF_WRITE
Definition: rset.h:200
static void r_close(RSFD rfd)
Definition: rsisamc.c:110