1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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>
23
#include "drizzled/plugin/registry.h"
29
static vector<Error_message_handler *> all_errmsg_handler;
31
static bool errmsg_has= false;
33
void add_errmsg_handler(Error_message_handler *handler)
35
all_errmsg_handler.push_back(handler);
39
void remove_errmsg_handler(Error_message_handler *handler)
41
all_errmsg_handler.erase(find(all_errmsg_handler.begin(),
42
all_errmsg_handler.end(), handler));
46
class ErrorMessagePrint : public unary_function<Error_message_handler *, bool>
53
ErrorMessagePrint(Session *session_arg, int priority_arg,
54
const char *format_arg, va_list ap_arg) :
55
unary_function<Error_message_handler *, bool>(), session(session_arg),
56
priority(priority_arg), format(format_arg)
61
~ErrorMessagePrint() { va_end(ap); }
63
inline result_type operator()(argument_type handler)
65
if (handler->errmsg(session, priority, format, ap))
67
/* we're doing the errmsg plugin api,
68
so we can't trust the errmsg api to emit our error messages
69
so we will emit error messages to stderr */
70
/* TRANSLATORS: The leading word "errmsg" is the name
71
of the plugin api, and so should not be translated. */
73
_("errmsg plugin '%s' errmsg() failed"),
74
handler->getName().c_str());
81
bool errmsg_vprintf (Session *session, int priority,
82
char const *format, va_list ap)
85
/* check to see if any errmsg plugin has been loaded
86
if not, just fall back to emitting the message to stderr */
89
/* if it turns out that the vfprintf doesnt do one single write
90
(single writes are atomic), then this needs to be rewritten to
91
vsprintf into a char buffer, and then write() that char buffer
93
vfprintf(stderr, format, ap);
97
/* Use find_if instead of foreach so that we can collect return codes */
98
vector<Error_message_handler *>::iterator iter=
99
find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(),
100
ErrorMessagePrint(session, priority, format, ap));
101
/* If iter is == end() here, that means that all of the plugins returned
102
* false, which in this case means they all succeeded. Since we want to
103
* return false on success, we return the value of the two being !=
105
return iter != all_errmsg_handler.end();