~drizzle-trunk/drizzle/development

499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
499.2.10 by Mark Atwood
add editor format hints, and other useful metadata comments
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
3
 *
499.2.10 by Mark Atwood
add editor format hints, and other useful metadata comments
4
 *  Copyright (C) 2008 Mark Atwood
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
20
#include <drizzled/server_includes.h>
21
#include <drizzled/qcache.h>
549 by Monty Taylor
Took gettext.h out of header files.
22
#include <drizzled/gettext.h>
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
23
24
int qcache_initializer(st_plugin_int *plugin)
25
{
26
  qcache_t *p;
27
28
  p= (qcache_t *) malloc(sizeof(qcache_t));
29
  if (p == NULL) return 1;
30
  memset(p, 0, sizeof(qcache_t));
31
32
  plugin->data= (void *)p;
33
34
  if (plugin->plugin->init)
35
  {
36
    if (plugin->plugin->init((void *)p))
37
    {
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
38
      /* TRANSLATORS: The leading word "qcache" is the name
39
         of the plugin api, and so should not be translated. */
40
      sql_print_error(_("qcache plugin '%s' init() failed"),
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
41
		      plugin->name.str);
42
      goto err;
43
    }
44
  }
45
  return 0;
46
47
err:
48
  free(p);
49
  return 1;
50
}
51
52
int qcache_finalizer(st_plugin_int *plugin)
53
{ 
54
  qcache_t *p= (qcache_t *) plugin->data;
55
56
  if (plugin->plugin->deinit)
57
  {
58
    if (plugin->plugin->deinit((void *)p))
59
    {
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
60
      /* TRANSLATORS: The leading word "qcache" is the name
61
         of the plugin api, and so should not be translated. */
62
      sql_print_error(_("qcache plugin '%s' deinit() failed"),
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
63
		      plugin->name.str);
64
    }
65
  }
66
67
  if (p) free(p);
68
69
  return 0;
70
}
71
72
/* The plugin_foreach() iterator requires that we
73
   convert all the parameters of a plugin api entry point
520.1.22 by Brian Aker
Second pass of thd cleanup
74
   into just one single void ptr, plus the session.
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
75
   So we will take all the additional paramters of qcache_do1,
76
   and marshall them into a struct of this type, and
77
   then just pass in a pointer to it.
499.2.9 by Mark Atwood
fix mistakes
78
*/
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
79
typedef struct qcache_do1_parms_st
80
{
81
  void *parm1;
82
  void *parm2;
83
} qcache_do1_parms_t;
84
85
/* This gets called by plugin_foreach once for each loaded qcache plugin */
520.1.22 by Brian Aker
Second pass of thd cleanup
86
static bool qcache_do1_iterate (Session *session, plugin_ref plugin, void *p)
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
87
{
88
  qcache_t *l= plugin_data(plugin, qcache_t *);
89
  qcache_do1_parms_t *parms= (qcache_do1_parms_t *) p;
90
91
  /* call this loaded qcache plugin's qcache_func1 function pointer */
92
  if (l && l->qcache_func1)
93
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
94
    if (l->qcache_func1(session, parms->parm1, parms->parm2))
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
95
    {
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
96
      /* TRANSLATORS: The leading word "qcache" is the name
97
         of the plugin api, and so should not be translated. */
98
      sql_print_error(_("qcache plugin '%s' do1() failed"),
499.2.9 by Mark Atwood
fix mistakes
99
		      (char *)plugin_name(plugin));
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
100
      return true;
499.2.9 by Mark Atwood
fix mistakes
101
    }
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
102
  }
103
  return false;
104
}
105
106
/* This is the qcache_do1 entry point.
107
   This gets called by the rest of the Drizzle server code */
520.1.22 by Brian Aker
Second pass of thd cleanup
108
bool qcache_do1 (Session *session, void *parm1, void *parm2)
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
109
{
110
  qcache_do1_parms_t parms;
111
  bool foreach_rv;
112
113
  /* marshall the parameters so they will fit into the foreach */
114
  parms.parm1= parm1;
115
  parms.parm2= parm2;
116
117
  /* call qcache_do1_iterate
118
     once for each loaded qcache plugin */
520.1.22 by Brian Aker
Second pass of thd cleanup
119
  foreach_rv= plugin_foreach(session,
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
120
                             qcache_do1_iterate,
121
                             DRIZZLE_QCACHE_PLUGIN,
122
                             (void *) &parms);
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
123
  return foreach_rv;
124
}
125
126
/* The plugin_foreach() iterator requires that we
127
   convert all the parameters of a plugin api entry point
520.1.22 by Brian Aker
Second pass of thd cleanup
128
   into just one single void ptr, plus the session.
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
129
   So we will take all the additional paramters of qcache_do2,
130
   and marshall them into a struct of this type, and
131
   then just pass in a pointer to it.
499.2.9 by Mark Atwood
fix mistakes
132
*/
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
133
typedef struct qcache_do2_parms_st
134
{
135
  void *parm3;
136
  void *parm4;
137
} qcache_do2_parms_t;
138
139
/* This gets called by plugin_foreach once for each loaded qcache plugin */
520.1.22 by Brian Aker
Second pass of thd cleanup
140
static bool qcache_do2_iterate (Session *session, plugin_ref plugin, void *p)
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
141
{
142
  qcache_t *l= plugin_data(plugin, qcache_t *);
143
  qcache_do2_parms_t *parms= (qcache_do2_parms_t *) p;
144
145
  /* call this loaded qcache plugin's qcache_func1 function pointer */
146
  if (l && l->qcache_func1)
147
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
148
    if (l->qcache_func2(session, parms->parm3, parms->parm4))
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
149
    {
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
150
      /* TRANSLATORS: The leading word "qcache" is the name
151
         of the plugin api, and so should not be translated. */
152
      sql_print_error(_("qcache plugin '%s' qcache_func2() failed"),
499.2.9 by Mark Atwood
fix mistakes
153
		      (char *)plugin_name(plugin));
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
154
155
      return true;
499.2.9 by Mark Atwood
fix mistakes
156
    }
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
157
  }
158
  return false;
159
}
160
161
/* This is the qcache_do2 entry point.
162
   This gets called by the rest of the Drizzle server code */
520.1.22 by Brian Aker
Second pass of thd cleanup
163
bool qcache_do2 (Session *session, void *parm3, void *parm4)
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
164
{
165
  qcache_do2_parms_t parms;
166
  bool foreach_rv;
167
168
  /* marshall the parameters so they will fit into the foreach */
169
  parms.parm3= parm3;
170
  parms.parm4= parm4;
171
172
  /* call qcache_do2_iterate
173
     once for each loaded qcache plugin */
520.1.22 by Brian Aker
Second pass of thd cleanup
174
  foreach_rv= plugin_foreach(session,
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
175
                             qcache_do2_iterate,
176
                             DRIZZLE_QCACHE_PLUGIN,
177
                             (void *) &parms);
520.2.2 by Mark Atwood
new plugin types, configvar and qcache
178
  return foreach_rv;
179
}