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