~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/parser.cc

Merged plugin-registration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
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
 
 
20
 
#include <drizzled/server_includes.h>
21
 
#include <drizzled/parser.h>
22
 
#include <drizzled/gettext.h>
23
 
 
24
 
int parser_initializer(st_plugin_int *plugin)
25
 
{
26
 
  parser_t *p;
27
 
 
28
 
  p= new parser_t;
29
 
 
30
 
  if (p == NULL) 
31
 
    return 1;
32
 
  memset(p, 0, sizeof(parser_t));
33
 
 
34
 
  plugin->data= (void *)p;
35
 
 
36
 
  if (plugin->plugin->init)
37
 
  {
38
 
    if (plugin->plugin->init((void *)p))
39
 
    {
40
 
      /* TRANSLATORS: The leading word "parser" is the name
41
 
         of the plugin api, and so should not be translated. */
42
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("parser plugin '%s' init() failed"),
43
 
                      plugin->name.str);
44
 
      goto err;
45
 
    }
46
 
  }
47
 
 
48
 
  return 0;
49
 
 
50
 
err:
51
 
  delete p;
52
 
 
53
 
  return 1;
54
 
}
55
 
 
56
 
int parser_finalizer(st_plugin_int *plugin)
57
 
{
58
 
  parser_t *p= (parser_t *) plugin->data;
59
 
 
60
 
  if (plugin->plugin->deinit)
61
 
  {
62
 
    if (plugin->plugin->deinit((void *)p))
63
 
    {
64
 
      /* TRANSLATORS: The leading word "parser" is the name
65
 
         of the plugin api, and so should not be translated. */
66
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("parser plugin '%s' deinit() failed"),
67
 
                      plugin->name.str);
68
 
    }
69
 
  }
70
 
 
71
 
  if (p) 
72
 
    delete p;
73
 
 
74
 
  return 0;
75
 
}
76
 
 
77
 
/* The plugin_foreach() iterator requires that we
78
 
   convert all the parameters of a plugin api entry point
79
 
   into just one single void ptr, plus the session.
80
 
   So we will take all the additional paramters of parser_do1,
81
 
   and marshall them into a struct of this type, and
82
 
   then just pass in a pointer to it.
83
 
*/
84
 
typedef struct parser_do1_parms_st
85
 
{
86
 
  void *parm1;
87
 
  void *parm2;
88
 
} parser_do1_parms_t;
89
 
 
90
 
/* This gets called by plugin_foreach once for each loaded parser plugin */
91
 
static bool parser_do1_iterate (Session *session, plugin_ref plugin, void *p)
92
 
{
93
 
  parser_t *l= plugin_data(plugin, parser_t *);
94
 
  parser_do1_parms_t *parms= (parser_do1_parms_t *) p;
95
 
 
96
 
  /* call this loaded parser plugin's parser_func1 function pointer */
97
 
  if (l && l->parser_func1)
98
 
  {
99
 
    if (l->parser_func1(session, parms->parm1, parms->parm2))
100
 
    {
101
 
      /* TRANSLATORS: The leading word "parser" is the name
102
 
         of the plugin api, and so should not be translated. */
103
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("parser plugin '%s' parser_func1() failed"),
104
 
                      (char *)plugin_name(plugin));
105
 
      return true;
106
 
    }
107
 
  }
108
 
  return false;
109
 
}
110
 
 
111
 
/* This is the parser_do1 entry point.
112
 
   This gets called by the rest of the Drizzle server code */
113
 
bool parser_do1 (Session *session, void *parm1, void *parm2)
114
 
{
115
 
  parser_do1_parms_t parms;
116
 
  bool foreach_rv;
117
 
 
118
 
  /* marshall the parameters so they will fit into the foreach */
119
 
  parms.parm1= parm1;
120
 
  parms.parm2= parm2;
121
 
 
122
 
  /* call parser_do1_iterate
123
 
     once for each loaded parser plugin */
124
 
  foreach_rv= plugin_foreach(session,
125
 
                             parser_do1_iterate,
126
 
                             DRIZZLE_PARSER_PLUGIN,
127
 
                             (void *) &parms);
128
 
  return foreach_rv;
129
 
}
130
 
 
131
 
/* The plugin_foreach() iterator requires that we
132
 
   convert all the parameters of a plugin api entry point
133
 
   into just one single void ptr, plus the session.
134
 
   So we will take all the additional paramters of parser_do2,
135
 
   and marshall them into a struct of this type, and
136
 
   then just pass in a pointer to it.
137
 
*/
138
 
typedef struct parser_do2_parms_st
139
 
{
140
 
  void *parm3;
141
 
  void *parm4;
142
 
} parser_do2_parms_t;
143
 
 
144
 
/* This gets called by plugin_foreach once for each loaded parser plugin */
145
 
static bool parser_do2_iterate (Session *session, plugin_ref plugin, void *p)
146
 
{
147
 
  parser_t *l= plugin_data(plugin, parser_t *);
148
 
  parser_do2_parms_t *parms= (parser_do2_parms_t *) p;
149
 
 
150
 
  /* call this loaded parser plugin's parser_func1 function pointer */
151
 
  if (l && l->parser_func2)
152
 
  {
153
 
    if (l->parser_func2(session, parms->parm3, parms->parm4))
154
 
    {
155
 
      /* TRANSLATORS: The leading word "parser" is the name
156
 
         of the plugin api, and so should not be translated. */
157
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("parser plugin '%s' parser_func2() failed"),
158
 
                      (char *)plugin_name(plugin));
159
 
 
160
 
      return true;
161
 
    }
162
 
  }
163
 
  return false;
164
 
}
165
 
 
166
 
/* This is the parser_do2 entry point.
167
 
   This gets called by the rest of the Drizzle server code */
168
 
bool parser_do2 (Session *session, void *parm3, void *parm4)
169
 
{
170
 
  parser_do2_parms_t parms;
171
 
  bool foreach_rv;
172
 
 
173
 
  /* marshall the parameters so they will fit into the foreach */
174
 
  parms.parm3= parm3;
175
 
  parms.parm4= parm4;
176
 
 
177
 
  /* call parser_do2_iterate
178
 
     once for each loaded parser plugin */
179
 
  foreach_rv= plugin_foreach(session,
180
 
                             parser_do2_iterate,
181
 
                             DRIZZLE_PARSER_PLUGIN,
182
 
                             (void *) &parms);
183
 
  return foreach_rv;
184
 
}