1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
4
* Copyright (C) 2008 Mark Atwood
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "drizzled/plugin/error_message.h"
22
#include "drizzled/plugin/registry.h"
24
#include "drizzled/gettext.h"
20
#include <drizzled/server_includes.h>
21
#include <drizzled/errmsg.h>
22
#include <drizzled/gettext.h>
23
#include "drizzled/plugin_registry.h"
28
27
using namespace std;
33
vector<plugin::ErrorMessage *> all_errmsg_handler;
34
bool errmsg_has= false;
37
bool plugin::ErrorMessage::addPlugin(plugin::ErrorMessage *handler)
29
static vector<Error_message_handler *> all_errmsg_handler;
31
static bool errmsg_has= false;
33
void add_errmsg_handler(Error_message_handler *handler)
39
35
all_errmsg_handler.push_back(handler);
44
void plugin::ErrorMessage::removePlugin(plugin::ErrorMessage *handler)
39
void remove_errmsg_handler(Error_message_handler *handler)
46
41
all_errmsg_handler.erase(find(all_errmsg_handler.begin(),
47
42
all_errmsg_handler.end(), handler));
51
class Print : public unary_function<plugin::ErrorMessage *, bool>
46
class ErrorMessagePrint : public unary_function<Error_message_handler *, bool>
55
50
const char *format;
58
Print(Session *session_arg, int priority_arg,
59
const char *format_arg, va_list ap_arg)
60
: unary_function<plugin::ErrorMessage *, bool>(), session(session_arg),
61
priority(priority_arg), format(format_arg)
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)
63
58
va_copy(ap, ap_arg);
66
~Print() { va_end(ap); }
61
~ErrorMessagePrint() { va_end(ap); }
68
63
inline result_type operator()(argument_type handler)
71
va_copy(handler_ap, ap);
72
if (handler->errmsg(session, priority, format, handler_ap))
65
if (handler->errmsg(session, priority, format, ap))
74
67
/* we're doing the errmsg plugin api,
75
68
so we can't trust the errmsg api to emit our error messages
80
73
_("errmsg plugin '%s' errmsg() failed"),
81
74
handler->getName().c_str());
91
bool plugin::ErrorMessage::vprintf(Session *session, int priority,
92
char const *format, va_list ap)
81
bool errmsg_vprintf (Session *session, int priority,
82
char const *format, va_list ap)
95
85
/* check to see if any errmsg plugin has been loaded
107
97
/* Use find_if instead of foreach so that we can collect return codes */
108
vector<plugin::ErrorMessage *>::iterator iter=
98
vector<Error_message_handler *>::iterator iter=
109
99
find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(),
110
Print(session, priority, format, ap));
100
ErrorMessagePrint(session, priority, format, ap));
111
101
/* If iter is == end() here, that means that all of the plugins returned
112
102
* false, which in this case means they all succeeded. Since we want to
113
103
* return false on success, we return the value of the two being !=