1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "drizzled/plugin/logging.h"
22
#include "drizzled/gettext.h"
23
#include "drizzled/errmsg_print.h"
35
vector<plugin::Logging *> all_loggers;
38
bool plugin::Logging::addPlugin(plugin::Logging *handler)
41
all_loggers.push_back(handler);
45
void plugin::Logging::removePlugin(plugin::Logging *handler)
48
all_loggers.erase(find(all_loggers.begin(), all_loggers.end(), handler));
52
class PreIterate : public unary_function<plugin::Logging *, bool>
56
PreIterate(Session *session_arg) :
57
unary_function<plugin::Logging *, bool>(),
58
session(session_arg) {}
60
inline result_type operator()(argument_type handler)
62
if (handler->pre(session))
64
/* TRANSLATORS: The leading word "logging" is the name
65
of the plugin api, and so should not be translated. */
66
errmsg_printf(ERRMSG_LVL_ERROR,
67
_("logging '%s' pre() failed"),
68
handler->getName().c_str());
76
class PostIterate : public unary_function<plugin::Logging *, bool>
80
PostIterate(Session *session_arg) :
81
unary_function<plugin::Logging *, bool>(),
82
session(session_arg) {}
84
/* This gets called once for each loaded logging plugin */
85
inline result_type operator()(argument_type handler)
87
if (handler->post(session))
89
/* TRANSLATORS: The leading word "logging" is the name
90
of the plugin api, and so should not be translated. */
91
errmsg_printf(ERRMSG_LVL_ERROR,
92
_("logging '%s' post() failed"),
93
handler->getName().c_str());
100
class PostEndIterate : public unary_function<plugin::Logging *, bool>
104
PostEndIterate(Session *session_arg) :
105
unary_function<plugin::Logging *, bool>(),
106
session(session_arg) {}
108
/* This gets called once for each loaded logging plugin */
109
inline result_type operator()(argument_type handler)
111
if (handler->postEnd(session))
113
/* TRANSLATORS: The leading word "logging" is the name
114
of the plugin api, and so should not be translated. */
115
errmsg_printf(ERRMSG_LVL_ERROR,
116
_("logging '%s' postEnd() failed"),
117
handler->getName().c_str());
124
/* This is the Logging::preDo entry point.
125
This gets called by the rest of the Drizzle server code */
126
bool plugin::Logging::preDo(Session *session)
128
/* Use find_if instead of foreach so that we can collect return codes */
129
vector<plugin::Logging *>::iterator iter=
130
find_if(all_loggers.begin(), all_loggers.end(),
131
PreIterate(session));
132
/* If iter is == end() here, that means that all of the plugins returned
133
* false, which in this case means they all succeeded. Since we want to
134
* return false on success, we return the value of the two being !=
136
return iter != all_loggers.end();
139
/* This is the Logging::postDo entry point.
140
This gets called by the rest of the Drizzle server code */
141
bool plugin::Logging::postDo(Session *session)
143
/* Use find_if instead of foreach so that we can collect return codes */
144
vector<plugin::Logging *>::iterator iter=
145
find_if(all_loggers.begin(), all_loggers.end(),
146
PostIterate(session));
147
/* If iter is == end() here, that means that all of the plugins returned
148
* false, which in this case means they all succeeded. Since we want to
149
* return false on success, we return the value of the two being !=
151
return iter != all_loggers.end();
154
/* This gets called in the session destructor */
155
bool plugin::Logging::postEndDo(Session *session)
157
/* Use find_if instead of foreach so that we can collect return codes */
158
vector<plugin::Logging *>::iterator iter=
159
find_if(all_loggers.begin(), all_loggers.end(),
160
PostEndIterate(session));
161
/* If iter is == end() here, that means that all of the plugins returned
162
* false, which in this case means they all succeeded. Since we want to
163
* return false on success, we return the value of the two being !=
165
return iter != all_loggers.end();
168
} /* namespace drizzled */