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
int errmsg_initializer(st_plugin_int *plugin)
28
p= (errmsg_t *) malloc(sizeof(errmsg_t));
29
if (p == NULL) return 1;
30
memset(p, 0, sizeof(errmsg_t));
32
plugin->data= (void *)p;
34
if (plugin->plugin->init)
36
if (plugin->plugin->init((void *)p))
38
/* we're doing the errmsg plugin api,
39
so we can't trust the errmsg api to emit our error messages
40
so we will emit error messages to stderr */
41
/* TRANSLATORS: The leading word "errmsg" is the name
42
of the plugin api, and so should not be translated. */
44
_("errmsg plugin '%s' init() failed."),
56
int errmsg_finalizer(st_plugin_int *plugin)
58
errmsg_t *p = (errmsg_t *) plugin->data;
60
if (plugin->plugin->deinit)
62
if (plugin->plugin->deinit((void *)p))
64
/* we're doing the errmsg plugin api,
65
so we can't trust the errmsg api to emit our error messages
66
so we will emit error messages to stderr */
67
/* TRANSLATORS: The leading word "errmsg" is the name
68
of the plugin api, and so should not be translated. */
70
_("errmsg plugin '%s' deinit() failed."),
80
/* The plugin_foreach() iterator requires that we
81
convert all the parameters of a plugin api entry point
82
into just one single void ptr, plus the session.
83
So we will take all the additional paramters of errmsg_vprintf,
84
and marshall them into a struct of this type, and
85
then just pass in a pointer to it.
87
typedef struct errmsg_parms_st
95
/* This gets called by plugin_foreach once for each loaded errmsg plugin */
96
static bool errmsg_iterate (Session *session, plugin_ref plugin, void *p)
98
errmsg_t *l= plugin_data(plugin, errmsg_t *);
99
errmsg_parms_t *parms= (errmsg_parms_t *) p;
101
if (l && l->errmsg_func)
103
if (l->errmsg_func(session, parms->priority, parms->format, parms->ap))
105
/* we're doing the errmsg plugin api,
106
so we can't trust the errmsg api to emit our error messages
107
so we will emit error messages to stderr */
108
/* TRANSLATORS: The leading word "errmsg" is the name
109
of the plugin api, and so should not be translated. */
111
_("errmsg plugin '%s' errmsg_func() failed"),
112
(char *)plugin_name(plugin));
119
bool errmsg_vprintf (Session *session, int priority, const char *format, va_list ap)
122
errmsg_parms_t parms;
124
/* marshall the parameters so they will fit into the foreach */
125
parms.priority= priority;
126
parms.format= format;
127
va_copy(parms.ap, ap);
129
/* call errmsg_iterate
130
once for each loaded errmsg plugin */
131
foreach_rv= plugin_foreach(session,
133
DRIZZLE_ERRMSG_PLUGIN,
138
bool errmsg_printf (Session *session, int priority, const char *format, ...)
142
va_start(args, format);
143
rv= errmsg_vprintf(session, priority, format, args);