00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <drizzled/error.h>
00023 #include <drizzled/gettext.h>
00024 #include <drizzled/plugin/error_message.h>
00025
00026 #include <cstdio>
00027 #include <algorithm>
00028 #include <vector>
00029
00030 namespace drizzled
00031 {
00032
00033 std::vector<plugin::ErrorMessage *> all_errmsg_handler;
00034
00035 bool plugin::ErrorMessage::addPlugin(plugin::ErrorMessage *handler)
00036 {
00037 all_errmsg_handler.push_back(handler);
00038 return false;
00039 }
00040
00041 void plugin::ErrorMessage::removePlugin(plugin::ErrorMessage *)
00042 {
00043 all_errmsg_handler.clear();
00044 }
00045
00046
00047 class Print : public std::unary_function<plugin::ErrorMessage *, bool>
00048 {
00049 error::level_t priority;
00050 const char *format;
00051 va_list ap;
00052
00053 public:
00054 Print(error::level_t priority_arg,
00055 const char *format_arg, va_list ap_arg) :
00056 std::unary_function<plugin::ErrorMessage *, bool>(),
00057 priority(priority_arg), format(format_arg)
00058 {
00059 va_copy(ap, ap_arg);
00060 }
00061
00062 ~Print() { va_end(ap); }
00063
00064 inline result_type operator()(argument_type handler)
00065 {
00066 va_list handler_ap;
00067 va_copy(handler_ap, ap);
00068 if (handler->errmsg(priority, format, handler_ap))
00069 {
00070
00071
00072
00073
00074
00075 fprintf(stderr,
00076 _("errmsg plugin '%s' errmsg() failed"),
00077 handler->getName().c_str());
00078 va_end(handler_ap);
00079 return true;
00080 }
00081 va_end(handler_ap);
00082 return false;
00083 }
00084 };
00085
00086
00087 bool plugin::ErrorMessage::vprintf(error::level_t priority, char const *format, va_list ap)
00088 {
00089 if (not (priority >= error::verbosity()))
00090 return false;
00091
00092
00093
00094
00095
00096 if (not all_errmsg_handler.size())
00097 {
00098
00099
00100
00101
00102 vfprintf(stderr, format, ap);
00103 fputc('\n', stderr);
00104 return false;
00105 }
00106
00107
00108 std::vector<plugin::ErrorMessage *>::iterator iter=
00109 std::find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(),
00110 Print(priority, format, ap));
00111
00112
00113
00114
00115
00116 return iter != all_errmsg_handler.end();
00117 }
00118
00119 }