17
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>
20
#include "drizzled/server_includes.h"
21
#include "drizzled/slot/error_message.h"
22
#include "drizzled/plugin/error_message.h"
23
23
#include "drizzled/plugin/registry.h"
25
#include "drizzled/gettext.h"
29
using namespace drizzled;
27
30
using namespace std;
29
static vector<Error_message_handler *> all_errmsg_handler;
31
static bool errmsg_has= false;
33
void add_errmsg_handler(Error_message_handler *handler)
32
void slot::ErrorMessage::add(plugin::ErrorMessage *handler)
35
34
all_errmsg_handler.push_back(handler);
39
void remove_errmsg_handler(Error_message_handler *handler)
38
void slot::ErrorMessage::remove(plugin::ErrorMessage *handler)
41
40
all_errmsg_handler.erase(find(all_errmsg_handler.begin(),
42
41
all_errmsg_handler.end(), handler));
46
class ErrorMessagePrint : public unary_function<Error_message_handler *, bool>
52
class Print : public unary_function<plugin::ErrorMessage *, bool>
50
56
const char *format;
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)
59
Print(Session *session_arg, int priority_arg,
60
const char *format_arg, va_list ap_arg)
61
: unary_function<plugin::ErrorMessage *, bool>(), session(session_arg),
62
priority(priority_arg), format(format_arg)
58
64
va_copy(ap, ap_arg);
61
~ErrorMessagePrint() { va_end(ap); }
67
~Print() { va_end(ap); }
63
69
inline result_type operator()(argument_type handler)
81
bool errmsg_vprintf (Session *session, int priority,
82
char const *format, va_list ap)
87
} /* namespace errmsg_priv */
88
} /* namespace slot */
89
} /* namespace drizzled */
91
bool slot::ErrorMessage::vprintf(Session *session, int priority,
92
char const *format, va_list ap)
85
95
/* check to see if any errmsg plugin has been loaded
97
107
/* Use find_if instead of foreach so that we can collect return codes */
98
vector<Error_message_handler *>::iterator iter=
108
vector<plugin::ErrorMessage *>::iterator iter=
99
109
find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(),
100
ErrorMessagePrint(session, priority, format, ap));
110
slot::errmsg_priv::Print(session, priority, format, ap));
101
111
/* If iter is == end() here, that means that all of the plugins returned
102
112
* false, which in this case means they all succeeded. Since we want to
103
113
* return false on success, we return the value of the two being !=