1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Mark Atwood
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.
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.
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
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)
28
Error_message_handler *p;
30
if (plugin->plugin->init)
32
if (plugin->plugin->init(&p))
34
/* we're doing the errmsg plugin api,
35
so we can't trust the errmsg api to emit our error messages
36
so we will emit error messages to stderr */
37
/* TRANSLATORS: The leading word "errmsg" is the name
38
of the plugin api, and so should not be translated. */
40
_("errmsg plugin '%s' init() failed."),
46
plugin->data= (void *)p;
53
int errmsg_finalizer(st_plugin_int *plugin)
55
Error_message_handler *p= static_cast<Error_message_handler *>(plugin->data);
57
if (plugin->plugin->deinit)
59
if (plugin->plugin->deinit(p))
61
/* we're doing the errmsg plugin api,
62
so we can't trust the errmsg api to emit our error messages
63
so we will emit error messages to stderr */
64
/* TRANSLATORS: The leading word "errmsg" is the name
65
of the plugin api, and so should not be translated. */
67
_("errmsg plugin '%s' deinit() failed."),
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
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;
98
if (handler->errmsg(session, parms->priority, parms->format, parms->ap))
100
/* 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 */
103
/* TRANSLATORS: The leading word "errmsg" is the name
104
of the plugin api, and so should not be translated. */
106
_("errmsg plugin '%s' errmsg() failed"),
107
(char *)plugin_name(plugin));
114
bool errmsg_vprintf (Session *session, int priority,
115
char const *format, va_list ap)
118
errmsg_parms_t parms;
120
/* check to see if any errmsg plugin has been loaded
121
if not, just fall back to emitting the message to stderr */
124
/* if it turns out that the vfprintf doesnt do one single write
125
(single writes are atomic), then this needs to be rewritten to
126
vsprintf into a char buffer, and then write() that char buffer
128
vfprintf(stderr, format, ap);
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);