20
20
#include <drizzled/server_includes.h>
21
21
#include <drizzled/errmsg.h>
22
22
#include <drizzled/gettext.h>
27
static vector<Error_message_handler *> all_errmsg_handler;
24
29
static bool errmsg_has= false;
31
static void add_errmsg_handler(Error_message_handler *handler)
33
all_errmsg_handler.push_back(handler);
36
static void remove_errmsg_handler(Error_message_handler *handler)
38
all_errmsg_handler.erase(find(all_errmsg_handler.begin(),
39
all_errmsg_handler.end(), handler));
26
42
int errmsg_initializer(st_plugin_int *plugin)
28
44
Error_message_handler *p;
75
/* The plugin_foreach() iterator requires that we
76
convert all the parameters of a plugin api entry point
77
into just one single void ptr, plus the session.
78
So we will take all the additional paramters of errmsg_vprintf,
79
and marshall them into a struct of this type, and
80
then just pass in a pointer to it.
82
typedef struct errmsg_parms_st
94
class ErrorMessagePrint : public unary_function<Error_message_handler *, bool>
85
98
const char *format;
90
/* This gets called by plugin_foreach once for each loaded errmsg plugin */
91
static bool errmsg_iterate (Session *session, plugin_ref plugin, void *p)
93
Error_message_handler *handler= plugin_data(plugin, Error_message_handler *);
94
errmsg_parms_t *parms= (errmsg_parms_t *) p;
101
ErrorMessagePrint(Session *session_arg, int priority_arg,
102
const char *format_arg, va_list ap_arg) :
103
unary_function<Error_message_handler *, bool>(), session(session_arg),
104
priority(priority_arg), format(format_arg)
109
~ErrorMessagePrint() { va_end(ap); }
111
inline result_type operator()(argument_type handler)
98
if (handler->errmsg(session, parms->priority, parms->format, parms->ap))
113
if (handler->errmsg(session, priority, format, ap))
100
115
/* we're doing the errmsg plugin api,
101
so we can't trust the errmsg api to emit our error messages
102
so we will emit error messages to stderr */
116
so we can't trust the errmsg api to emit our error messages
117
so we will emit error messages to stderr */
103
118
/* TRANSLATORS: The leading word "errmsg" is the name
104
119
of the plugin api, and so should not be translated. */
106
121
_("errmsg plugin '%s' errmsg() failed"),
107
(char *)plugin_name(plugin));
122
handler->getName().c_str());
114
129
bool errmsg_vprintf (Session *session, int priority,
115
130
char const *format, va_list ap)
118
errmsg_parms_t parms;
120
133
/* check to see if any errmsg plugin has been loaded
121
134
if not, just fall back to emitting the message to stderr */
132
/* marshall the parameters so they will fit into the foreach */
133
parms.priority= priority;
134
parms.format= format;
135
va_copy(parms.ap, ap);
137
/* call errmsg_iterate
138
once for each loaded errmsg plugin */
139
foreach_rv= plugin_foreach(session, errmsg_iterate,
140
DRIZZLE_ERRMSG_PLUGIN, (void *) &parms);
145
/* Use find_if instead of foreach so that we can collect return codes */
146
vector<Error_message_handler *>::iterator iter=
147
find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(),
148
ErrorMessagePrint(session, priority, format, ap));
149
/* If iter is == end() here, that means that all of the plugins returned
150
* false, which in this case means they all succeeded. Since we want to
151
* return false on success, we return the value of the two being !=
153
return iter != all_errmsg_handler.end();