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, Inc.
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
21
#include "drizzled/plugin/error_message.h"
23
#include "drizzled/gettext.h"
32
std::vector<plugin::ErrorMessage *> all_errmsg_handler;
33
bool errmsg_has= false;
36
bool plugin::ErrorMessage::addPlugin(plugin::ErrorMessage *handler)
38
all_errmsg_handler.push_back(handler);
43
void plugin::ErrorMessage::removePlugin(plugin::ErrorMessage *handler)
45
all_errmsg_handler.erase(std::find(all_errmsg_handler.begin(),
46
all_errmsg_handler.end(), handler));
50
class Print : public std::unary_function<plugin::ErrorMessage *, bool>
58
Print(Session *session_arg, int priority_arg,
59
const char *format_arg, va_list ap_arg) :
60
std::unary_function<plugin::ErrorMessage *, bool>(),
62
priority(priority_arg), format(format_arg)
67
~Print() { va_end(ap); }
69
inline result_type operator()(argument_type handler)
72
va_copy(handler_ap, ap);
73
if (handler->errmsg(session, priority, format, handler_ap))
75
/* we're doing the errmsg plugin api,
76
so we can't trust the errmsg api to emit our error messages
77
so we will emit error messages to stderr */
78
/* TRANSLATORS: The leading word "errmsg" is the name
79
of the plugin api, and so should not be translated. */
81
_("errmsg plugin '%s' errmsg() failed"),
82
handler->getName().c_str());
92
bool plugin::ErrorMessage::vprintf(Session *session, int priority,
93
char const *format, va_list ap)
96
/* check to see if any errmsg plugin has been loaded
97
if not, just fall back to emitting the message to stderr */
100
/* if it turns out that the vfprintf doesnt do one single write
101
(single writes are atomic), then this needs to be rewritten to
102
vsprintf into a char buffer, and then write() that char buffer
104
vfprintf(stderr, format, ap);
108
/* Use find_if instead of foreach so that we can collect return codes */
109
std::vector<plugin::ErrorMessage *>::iterator iter=
110
std::find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(),
111
Print(session, priority, format, ap));
112
/* If iter is == end() here, that means that all of the plugins returned
113
* false, which in this case means they all succeeded. Since we want to
114
* return false on success, we return the value of the two being !=
116
return iter != all_errmsg_handler.end();
119
} /* namespace drizzled */