00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021 #include <drizzled/plugin/logging.h>
00022 #include <drizzled/gettext.h>
00023 #include <drizzled/errmsg_print.h>
00024
00025 #include <vector>
00026 #include <algorithm>
00027
00028 class Session;
00029
00030 namespace drizzled
00031 {
00032
00033 std::vector<plugin::Logging *> all_loggers;
00034
00035
00036 bool plugin::Logging::addPlugin(plugin::Logging *handler)
00037 {
00038 if (handler != NULL)
00039 all_loggers.push_back(handler);
00040 return false;
00041 }
00042
00043 void plugin::Logging::removePlugin(plugin::Logging *handler)
00044 {
00045 if (handler != NULL)
00046 all_loggers.erase(std::find(all_loggers.begin(), all_loggers.end(), handler));
00047 }
00048
00049
00050 class PreIterate : public std::unary_function<plugin::Logging *, bool>
00051 {
00052 Session *session;
00053 public:
00054 PreIterate(Session *session_arg) :
00055 std::unary_function<plugin::Logging *, bool>(),
00056 session(session_arg) {}
00057
00058 inline result_type operator()(argument_type handler)
00059 {
00060 if (handler->pre(session))
00061 {
00062
00063
00064 errmsg_printf(error::ERROR,
00065 _("logging '%s' pre() failed"),
00066 handler->getName().c_str());
00067 return true;
00068 }
00069 return false;
00070 }
00071 };
00072
00073
00074 class PostIterate : public std::unary_function<plugin::Logging *, bool>
00075 {
00076 Session *session;
00077 public:
00078 PostIterate(Session *session_arg) :
00079 std::unary_function<plugin::Logging *, bool>(),
00080 session(session_arg) {}
00081
00082
00083 inline result_type operator()(argument_type handler)
00084 {
00085 if (handler->post(session))
00086 {
00087
00088
00089 errmsg_printf(error::ERROR,
00090 _("logging '%s' post() failed"),
00091 handler->getName().c_str());
00092 return true;
00093 }
00094 return false;
00095 }
00096 };
00097
00098 class PostEndIterate : public std::unary_function<plugin::Logging *, bool>
00099 {
00100 Session *session;
00101 public:
00102 PostEndIterate(Session *session_arg) :
00103 std::unary_function<plugin::Logging *, bool>(),
00104 session(session_arg) {}
00105
00106
00107 inline result_type operator()(argument_type handler)
00108 {
00109 if (handler->postEnd(session))
00110 {
00111
00112
00113 errmsg_printf(error::ERROR,
00114 _("logging '%s' postEnd() failed"),
00115 handler->getName().c_str());
00116 return true;
00117 }
00118 return false;
00119 }
00120 };
00121
00122 class ResetIterate : public std::unary_function<plugin::Logging *, bool>
00123 {
00124 Session *session;
00125 public:
00126 ResetIterate(Session *session_arg) :
00127 std::unary_function<plugin::Logging *, bool>(),
00128 session(session_arg) {}
00129
00130 inline result_type operator()(argument_type handler)
00131 {
00132 if (handler->resetGlobalScoreboard())
00133 {
00134
00135
00136 errmsg_printf(error::ERROR,
00137 _("logging '%s' resetCurrentScoreboard() failed"),
00138 handler->getName().c_str());
00139 return true;
00140 }
00141 return false;
00142 }
00143 };
00144
00145
00146
00147
00148 bool plugin::Logging::preDo(Session *session)
00149 {
00150
00151 std::vector<plugin::Logging *>::iterator iter=
00152 std::find_if(all_loggers.begin(), all_loggers.end(),
00153 PreIterate(session));
00154
00155
00156
00157
00158 return iter != all_loggers.end();
00159 }
00160
00161
00162
00163 bool plugin::Logging::postDo(Session *session)
00164 {
00165
00166 std::vector<plugin::Logging *>::iterator iter=
00167 std::find_if(all_loggers.begin(), all_loggers.end(),
00168 PostIterate(session));
00169
00170
00171
00172
00173 return iter != all_loggers.end();
00174 }
00175
00176
00177 bool plugin::Logging::postEndDo(Session *session)
00178 {
00179
00180 std::vector<plugin::Logging *>::iterator iter=
00181 std::find_if(all_loggers.begin(), all_loggers.end(),
00182 PostEndIterate(session));
00183
00184
00185
00186
00187 return iter != all_loggers.end();
00188 }
00189
00190
00191 bool plugin::Logging::resetStats(Session *session)
00192 {
00193 std::vector<plugin::Logging *>::iterator iter=
00194 std::find_if(all_loggers.begin(), all_loggers.end(),
00195 ResetIterate(session));
00196
00197 return iter != all_loggers.end();
00198 }
00199
00200 }