~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/parser.cc

  • Committer: Monty Taylor
  • Date: 2008-10-22 00:51:14 UTC
  • mfrom: (520.3.2 newplugins2)
  • Revision ID: monty@inaugust.com-20081022005114-n5h44l2n0y7zqahk
Merged from mark again.

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