17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "drizzled/plugin/error_message.h"
22
#include <drizzled/error.h>
23
#include <drizzled/gettext.h>
24
#include <drizzled/plugin/error_message.h>
23
#include "drizzled/gettext.h"
27
26
#include <algorithm>
33
32
std::vector<plugin::ErrorMessage *> all_errmsg_handler;
33
bool errmsg_has= false;
35
36
bool plugin::ErrorMessage::addPlugin(plugin::ErrorMessage *handler)
37
38
all_errmsg_handler.push_back(handler);
41
void plugin::ErrorMessage::removePlugin(plugin::ErrorMessage *)
43
void plugin::ErrorMessage::removePlugin(plugin::ErrorMessage *handler)
43
all_errmsg_handler.clear();
45
all_errmsg_handler.erase(std::find(all_errmsg_handler.begin(),
46
all_errmsg_handler.end(), handler));
47
50
class Print : public std::unary_function<plugin::ErrorMessage *, bool>
49
error::level_t priority;
50
54
const char *format;
54
Print(error::level_t priority_arg,
58
Print(Session *session_arg, int priority_arg,
55
59
const char *format_arg, va_list ap_arg) :
56
60
std::unary_function<plugin::ErrorMessage *, bool>(),
57
62
priority(priority_arg), format(format_arg)
59
64
va_copy(ap, ap_arg);
66
71
va_list handler_ap;
67
72
va_copy(handler_ap, ap);
68
if (handler->errmsg(priority, format, handler_ap))
73
if (handler->errmsg(session, priority, format, handler_ap))
70
75
/* we're doing the errmsg plugin api,
71
76
so we can't trust the errmsg api to emit our error messages
87
bool plugin::ErrorMessage::vprintf(error::level_t priority, char const *format, va_list ap)
92
bool plugin::ErrorMessage::vprintf(Session *session, int priority,
93
char const *format, va_list ap)
89
if (not (priority >= error::verbosity()))
93
Check to see if any errmsg plugin has been loaded
94
if not, just fall back to emitting the message to stderr.
96
if (not all_errmsg_handler.size())
96
/* check to see if any errmsg plugin has been loaded
97
if not, just fall back to emitting the message to stderr */
98
100
/* if it turns out that the vfprintf doesnt do one single write
99
101
(single writes are atomic), then this needs to be rewritten to
100
102
vsprintf into a char buffer, and then write() that char buffer
102
vfprintf(stderr, format, ap);
104
vfprintf(stderr, format, ap);
107
108
/* Use find_if instead of foreach so that we can collect return codes */
108
109
std::vector<plugin::ErrorMessage *>::iterator iter=
109
110
std::find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(),
110
Print(priority, format, ap));
111
Print(session, priority, format, ap));
112
112
/* If iter is == end() here, that means that all of the plugins returned
113
113
* false, which in this case means they all succeeded. Since we want to
114
114
* return false on success, we return the value of the two being !=