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::priority_t priority;
00050 const char *format;
00051 va_list ap;
00052
00053 public:
00054 Print(error::priority_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
00080 return true;
00081 }
00082 va_end(handler_ap);
00083 return false;
00084 }
00085 };
00086
00087
00088 bool plugin::ErrorMessage::vprintf(error::priority_t priority, char const *format, va_list ap)
00089 {
00090 if (priority > error::verbosity())
00091 {
00092 return false;
00093 }
00094
00095
00096
00097
00098
00099 if (all_errmsg_handler.size() == 0)
00100 {
00101
00102
00103
00104
00105
00106 vfprintf(stderr, format, ap);
00107 fputc('\n', stderr);
00108
00109 return false;
00110 }
00111
00112
00113 std::vector<plugin::ErrorMessage *>::iterator iter=
00114 std::find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(),
00115 Print(priority, format, ap));
00116
00117
00118
00119
00120
00121 return iter != all_errmsg_handler.end();
00122 }
00123
00124 }