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