~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/parser.cc

  • Committer: Brian Aker
  • Date: 2010-01-22 00:53:13 UTC
  • Revision ID: brian@gaz-20100122005313-jmizcbcdi1lt4tcx
Revert db patch.

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