~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/configvar.cc

  • Committer: Mark Atwood
  • Date: 2008-10-16 16:14:18 UTC
  • mto: (499.2.8 drizzle-errmsg)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: mark@fallenpegasus.com-20081016161418-8jrxbh9fhktzcl2m
new plugin types, configvar and qcache

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <drizzled/server_includes.h>
 
2
#include <drizzled/configvar.h>
 
3
 
 
4
int configvar_initializer(st_plugin_int *plugin)
 
5
{
 
6
  configvar_t *p;
 
7
 
 
8
  p= (configvar_t *) malloc(sizeof(configvar_t));
 
9
  if (p == NULL) return 1;
 
10
  memset(p, 0, sizeof(configvar_t));
 
11
 
 
12
  plugin->data= (void *)p;
 
13
 
 
14
  if (plugin->plugin->init)
 
15
  {
 
16
    if (plugin->plugin->init((void *)p))
 
17
    {
 
18
      sql_print_error("Configvar plugin '%s' init() failed",
 
19
                      plugin->name.str);
 
20
      goto err;
 
21
    }
 
22
  }
 
23
  return 0;
 
24
 
 
25
err:
 
26
  free(p);
 
27
  return 1;
 
28
}
 
29
 
 
30
int configvar_finalizer(st_plugin_int *plugin)
 
31
 
32
  configvar_t *p= (configvar_t *) plugin->data;
 
33
 
 
34
  if (plugin->plugin->deinit)
 
35
  {
 
36
    if (plugin->plugin->deinit((void *)p))
 
37
    {
 
38
      sql_print_error("Configvar plugin '%s' deinit() failed",
 
39
                      plugin->name.str);
 
40
    }
 
41
  }
 
42
 
 
43
  if (p) free(p);
 
44
 
 
45
  return 0;
 
46
}
 
47
 
 
48
/* The plugin_foreach() iterator requires that we
 
49
   convert all the parameters of a plugin api entry point
 
50
   into just one single void ptr, plus the thd.
 
51
   So we will take all the additional paramters of configvar_do1,
 
52
   and marshall them into a struct of this type, and
 
53
   then just pass in a pointer to it.
 
54
 */
 
55
typedef struct configvar_do1_parms_st
 
56
{
 
57
  void *parm1;
 
58
  void *parm2;
 
59
} configvar_do1_parms_t;
 
60
 
 
61
/* This gets called by plugin_foreach once for each loaded configvar plugin */
 
62
static bool configvar_do1_iterate (THD *thd, plugin_ref plugin, void *p)
 
63
{
 
64
  configvar_t *l= plugin_data(plugin, configvar_t *);
 
65
  configvar_do1_parms_t *parms= (configvar_do1_parms_t *) p;
 
66
 
 
67
  /* call this loaded configvar plugin's configvar_func1 function pointer */
 
68
  if (l && l->configvar_func1)
 
69
  {
 
70
    if (l->configvar_func1(thd, parms->parm1, parms->parm2))
 
71
    {
 
72
      sql_print_error("Configvar plugin '%s' do1() failed",
 
73
                      plugin->name.str);
 
74
 
 
75
      return true;
 
76
  }
 
77
  return false;
 
78
}
 
79
 
 
80
/* This is the configvar_do1 entry point.
 
81
   This gets called by the rest of the Drizzle server code */
 
82
bool configvar_do1 (THD *thd, void *parm1, void *parm2)
 
83
{
 
84
  configvar_do1_parms_t parms;
 
85
  bool foreach_rv;
 
86
 
 
87
  /* marshall the parameters so they will fit into the foreach */
 
88
  parms.parm1= parm1;
 
89
  parms.parm2= parm2;
 
90
 
 
91
  /* call configvar_do1_iterate
 
92
     once for each loaded configvar plugin */
 
93
  foreach_rv= plugin_foreach(thd,
 
94
                             configvar_do1_iterate,
 
95
                             DRIZZLE_CONFIGVAR_PLUGIN,
 
96
                             (void *) &parms));
 
97
  return foreach_rv;
 
98
}
 
99
 
 
100
/* The plugin_foreach() iterator requires that we
 
101
   convert all the parameters of a plugin api entry point
 
102
   into just one single void ptr, plus the thd.
 
103
   So we will take all the additional paramters of configvar_do2,
 
104
   and marshall them into a struct of this type, and
 
105
   then just pass in a pointer to it.
 
106
 */
 
107
typedef struct configvar_do2_parms_st
 
108
{
 
109
  void *parm3;
 
110
  void *parm4;
 
111
} configvar_do2_parms_t;
 
112
 
 
113
/* This gets called by plugin_foreach once for each loaded configvar plugin */
 
114
static bool configvar_do2_iterate (THD *thd, plugin_ref plugin, void *p)
 
115
{
 
116
  configvar_t *l= plugin_data(plugin, configvar_t *);
 
117
  configvar_do2_parms_t *parms= (configvar_do2_parms_t *) p;
 
118
 
 
119
  /* call this loaded configvar plugin's configvar_func1 function pointer */
 
120
  if (l && l->configvar_func1)
 
121
  {
 
122
    if (l->configvar_func1(thd, parms->parm3, parms->parm4))
 
123
    {
 
124
      sql_print_error("Configvar plugin '%s' do2() failed",
 
125
                      plugin->name.str);
 
126
 
 
127
      return true;
 
128
  }
 
129
  return false;
 
130
}
 
131
 
 
132
/* This is the configvar_do2 entry point.
 
133
   This gets called by the rest of the Drizzle server code */
 
134
bool configvar_do2 (THD *thd, void *parm3, void *parm4)
 
135
{
 
136
  configvar_do2_parms_t parms;
 
137
  bool foreach_rv;
 
138
 
 
139
  /* marshall the parameters so they will fit into the foreach */
 
140
  parms.parm3= parm3;
 
141
  parms.parm4= parm4;
 
142
 
 
143
  /* call configvar_do2_iterate
 
144
     once for each loaded configvar plugin */
 
145
  foreach_rv= plugin_foreach(thd,
 
146
                             configvar_do2_iterate,
 
147
                             DRIZZLE_CONFIGVAR_PLUGIN,
 
148
                             (void *) &parms));
 
149
  return foreach_rv;
 
150
}