17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "drizzled/plugin/error_message.h"
23
#include "drizzled/gettext.h"
32
std::vector<plugin::ErrorMessage *> all_errmsg_handler;
33
bool errmsg_has= false;
36
bool plugin::ErrorMessage::addPlugin(plugin::ErrorMessage *handler)
38
all_errmsg_handler.push_back(handler);
20
#include <drizzled/server_includes.h>
21
#include <drizzled/errmsg.h>
22
#include <drizzled/gettext.h>
24
static bool errmsg_has= false;
26
int errmsg_initializer(st_plugin_int *plugin)
31
if (p == NULL) return 1;
32
memset(p, 0, sizeof(errmsg_t));
34
plugin->data= (void *)p;
36
if (plugin->plugin->init)
38
if (plugin->plugin->init((void *)p))
40
/* we're doing the errmsg plugin api,
41
so we can't trust the errmsg api to emit our error messages
42
so we will emit error messages to stderr */
43
/* TRANSLATORS: The leading word "errmsg" is the name
44
of the plugin api, and so should not be translated. */
46
_("errmsg plugin '%s' init() failed."),
43
void plugin::ErrorMessage::removePlugin(plugin::ErrorMessage *handler)
45
all_errmsg_handler.erase(std::find(all_errmsg_handler.begin(),
46
all_errmsg_handler.end(), handler));
50
class Print : public std::unary_function<plugin::ErrorMessage *, bool>
61
int errmsg_finalizer(st_plugin_int *plugin)
63
errmsg_t *p = (errmsg_t *) plugin->data;
65
if (plugin->plugin->deinit)
67
if (plugin->plugin->deinit((void *)p))
69
/* we're doing the errmsg plugin api,
70
so we can't trust the errmsg api to emit our error messages
71
so we will emit error messages to stderr */
72
/* TRANSLATORS: The leading word "errmsg" is the name
73
of the plugin api, and so should not be translated. */
75
_("errmsg plugin '%s' deinit() failed."),
85
/* The plugin_foreach() iterator requires that we
86
convert all the parameters of a plugin api entry point
87
into just one single void ptr, plus the session.
88
So we will take all the additional paramters of errmsg_vprintf,
89
and marshall them into a struct of this type, and
90
then just pass in a pointer to it.
92
typedef struct errmsg_parms_st
54
95
const char *format;
58
Print(Session *session_arg, int priority_arg,
59
const char *format_arg, va_list ap_arg) :
60
std::unary_function<plugin::ErrorMessage *, bool>(),
62
priority(priority_arg), format(format_arg)
67
~Print() { va_end(ap); }
69
inline result_type operator()(argument_type handler)
72
va_copy(handler_ap, ap);
73
if (handler->errmsg(session, priority, format, handler_ap))
100
/* This gets called by plugin_foreach once for each loaded errmsg plugin */
101
static bool errmsg_iterate (Session *session, plugin_ref plugin, void *p)
103
errmsg_t *l= plugin_data(plugin, errmsg_t *);
104
errmsg_parms_t *parms= (errmsg_parms_t *) p;
106
if (l && l->errmsg_func)
108
if (l->errmsg_func(session, parms->priority, parms->format, parms->ap))
75
110
/* we're doing the errmsg plugin api,
76
so we can't trust the errmsg api to emit our error messages
77
so we will emit error messages to stderr */
111
so we can't trust the errmsg api to emit our error messages
112
so we will emit error messages to stderr */
78
113
/* TRANSLATORS: The leading word "errmsg" is the name
79
114
of the plugin api, and so should not be translated. */
81
_("errmsg plugin '%s' errmsg() failed"),
82
handler->getName().c_str());
116
_("errmsg plugin '%s' errmsg_func() failed"),
117
(char *)plugin_name(plugin));
92
bool plugin::ErrorMessage::vprintf(Session *session, int priority,
93
char const *format, va_list ap)
124
bool errmsg_vprintf (Session *session, int priority, char const *format, va_list ap)
127
errmsg_parms_t parms;
96
129
/* check to see if any errmsg plugin has been loaded
97
130
if not, just fall back to emitting the message to stderr */
108
/* Use find_if instead of foreach so that we can collect return codes */
109
std::vector<plugin::ErrorMessage *>::iterator iter=
110
std::find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(),
111
Print(session, priority, format, ap));
112
/* If iter is == end() here, that means that all of the plugins returned
113
* false, which in this case means they all succeeded. Since we want to
114
* return false on success, we return the value of the two being !=
116
return iter != all_errmsg_handler.end();
141
/* marshall the parameters so they will fit into the foreach */
142
parms.priority= priority;
143
parms.format= format;
144
va_copy(parms.ap, ap);
146
/* call errmsg_iterate
147
once for each loaded errmsg plugin */
148
foreach_rv= plugin_foreach(session, errmsg_iterate,
149
DRIZZLE_ERRMSG_PLUGIN, (void *) &parms);
119
} /* namespace drizzled */