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>
23
int errmsg_initializer(st_plugin_int *plugin)
27
p= (errmsg_t *) malloc(sizeof(errmsg_t));
28
if (p == NULL) return 1;
29
memset(p, 0, sizeof(errmsg_t));
31
plugin->data= (void *)p;
33
if (plugin->plugin->init)
35
if (plugin->plugin->init((void *)p))
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."),
55
int errmsg_finalizer(st_plugin_int *plugin)
57
errmsg_t *p = (errmsg_t *) plugin->data;
59
if (plugin->plugin->deinit)
61
if (plugin->plugin->deinit((void *)p))
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 session.
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 */
95
static bool errmsg_iterate (Session *session, plugin_ref plugin, void *p)
97
errmsg_t *l= plugin_data(plugin, errmsg_t *);
98
errmsg_parms_t *parms= (errmsg_parms_t *) p;
100
if (l && l->errmsg_func)
102
if (l->errmsg_func(session, 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));
118
bool errmsg_vprintf (Session *session, int priority, const char *format, va_list ap)
121
errmsg_parms_t parms;
123
/* marshall the parameters so they will fit into the foreach */
124
parms.priority= priority;
125
parms.format= format;
126
va_copy(parms.ap, ap);
128
/* call errmsg_iterate
129
once for each loaded errmsg plugin */
130
foreach_rv= plugin_foreach(session,
132
DRIZZLE_ERRMSG_PLUGIN,
137
bool errmsg_printf (Session *session, int priority, const char *format, ...)
141
va_start(args, format);
142
rv= errmsg_vprintf(session, priority, format, args);