2
-*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5
4
* Copyright (C) 2008 Mark Atwood
7
6
* This program is free software; you can redistribute it and/or modify
16
15
* You should have received a copy of the GNU General Public License
17
16
* along with this program; if not, write to the Free Software
18
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
20
#include <drizzled/server_includes.h>
23
21
#include <drizzled/errmsg.h>
25
typedef struct errmsg_parms_st
32
23
int errmsg_initializer(st_plugin_int *plugin)
36
fprintf(stderr, "MRA %s plugin:%s dl:%s\n",
37
__func__, plugin->name.str, plugin->plugin_dl->dl.str);
39
27
p= (errmsg_t *) malloc(sizeof(errmsg_t));
40
28
if (p == NULL) return 1;
41
29
memset(p, 0, sizeof(errmsg_t));
47
35
if (plugin->plugin->init((void *)p))
49
sql_print_error("Errmsg plugin '%s' init function returned error.",
37
/* we're doing the errmsg plugin api,
38
so we can't trust the errmsg api to emit our error messages
39
so we will emit error messages to stderr */
40
/* TRANSLATORS: The leading word "errmsg" is the name
41
of the plugin api, and so should not be translated. */
43
_("errmsg plugin '%s' init() failed."),
63
57
errmsg_t *p = (errmsg_t *) plugin->data;
65
fprintf(stderr, "MRA %s plugin:%s dl:%s\n",
66
__func__, plugin->name.str, plugin->plugin_dl->dl.str);
68
59
if (plugin->plugin->deinit)
70
61
if (plugin->plugin->deinit((void *)p))
72
sql_print_error("Errmsg plugin '%s' deinit function returned error.",
63
/* we're doing the errmsg plugin api,
64
so we can't trust the errmsg api to emit our error messages
65
so we will emit error messages to stderr */
66
/* TRANSLATORS: The leading word "errmsg" is the name
67
of the plugin api, and so should not be translated. */
69
_("errmsg plugin '%s' deinit() failed."),
79
/* The plugin_foreach() iterator requires that we
80
convert all the parameters of a plugin api entry point
81
into just one single void ptr, plus the thd.
82
So we will take all the additional paramters of errmsg_vprintf,
83
and marshall them into a struct of this type, and
84
then just pass in a pointer to it.
86
typedef struct errmsg_parms_st
94
/* This gets called by plugin_foreach once for each loaded errmsg plugin */
82
95
static bool errmsg_iterate (THD *thd, plugin_ref plugin, void *p)
84
97
errmsg_t *l= plugin_data(plugin, errmsg_t *);
87
100
if (l && l->errmsg_func)
89
102
if (l->errmsg_func(thd, parms->priority, parms->format, parms->ap))
104
/* we're doing the errmsg plugin api,
105
so we can't trust the errmsg api to emit our error messages
106
so we will emit error messages to stderr */
107
/* TRANSLATORS: The leading word "errmsg" is the name
108
of the plugin api, and so should not be translated. */
110
_("errmsg plugin '%s' errmsg_func() failed"),
111
(char *)plugin_name(plugin));
95
void errmsg_vprintf (THD *thd, int priority, const char *format, va_list ap)
118
bool errmsg_vprintf (THD *thd, int priority, const char *format, va_list ap)
97
121
errmsg_parms_t parms;
123
/* marshall the parameters so they will fit into the foreach */
99
124
parms.priority= priority;
100
125
parms.format= format;
126
va_copy(parms.ap, ap);
103
if (plugin_foreach(thd, errmsg_iterate, DRIZZLE_ERRMSG_PLUGIN,
106
sql_print_error("Errmsg plugin had an error.");
128
/* call errmsg_iterate
129
once for each loaded errmsg plugin */
130
foreach_rv= plugin_foreach(thd,
132
DRIZZLE_ERRMSG_PLUGIN,
111
void errmsg_printf (THD *thd, int priority, const char *format, ...)
137
bool errmsg_printf (THD *thd, int priority, const char *format, ...)
114
141
va_start(args, format);
115
errmsg_vprintf(thd, priority, format, args);
142
rv= errmsg_vprintf(thd, priority, format, args);