1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
21
#include <drizzled/plugin/logging.h>
22
22
#include <drizzled/gettext.h>
23
#include <drizzled/errmsg_print.h>
23
#include "drizzled/plugin/registry.h"
33
std::vector<plugin::Logging *> all_loggers;
34
vector<plugin::Logging *> all_loggers;
36
37
bool plugin::Logging::addPlugin(plugin::Logging *handler)
43
44
void plugin::Logging::removePlugin(plugin::Logging *handler)
45
46
if (handler != NULL)
46
all_loggers.erase(std::find(all_loggers.begin(), all_loggers.end(), handler));
47
all_loggers.erase(find(all_loggers.begin(), all_loggers.end(), handler));
50
class PreIterate : public std::unary_function<plugin::Logging *, bool>
51
class PreIterate : public unary_function<plugin::Logging *, bool>
54
55
PreIterate(Session *session_arg) :
55
std::unary_function<plugin::Logging *, bool>(),
56
unary_function<plugin::Logging *, bool>(),
56
57
session(session_arg) {}
58
59
inline result_type operator()(argument_type handler)
62
63
/* TRANSLATORS: The leading word "logging" is the name
63
64
of the plugin api, and so should not be translated. */
64
errmsg_printf(error::ERROR,
65
errmsg_printf(ERRMSG_LVL_ERROR,
65
66
_("logging '%s' pre() failed"),
66
67
handler->getName().c_str());
74
class PostIterate : public std::unary_function<plugin::Logging *, bool>
75
class PostIterate : public unary_function<plugin::Logging *, bool>
78
79
PostIterate(Session *session_arg) :
79
std::unary_function<plugin::Logging *, bool>(),
80
unary_function<plugin::Logging *, bool>(),
80
81
session(session_arg) {}
82
83
/* This gets called once for each loaded logging plugin */
87
88
/* TRANSLATORS: The leading word "logging" is the name
88
89
of the plugin api, and so should not be translated. */
89
errmsg_printf(error::ERROR,
90
errmsg_printf(ERRMSG_LVL_ERROR,
90
91
_("logging '%s' post() failed"),
91
92
handler->getName().c_str());
98
class PostEndIterate : public std::unary_function<plugin::Logging *, bool>
99
class PostEndIterate : public unary_function<plugin::Logging *, bool>
100
101
Session *session;
102
103
PostEndIterate(Session *session_arg) :
103
std::unary_function<plugin::Logging *, bool>(),
104
unary_function<plugin::Logging *, bool>(),
104
105
session(session_arg) {}
106
107
/* This gets called once for each loaded logging plugin */
111
112
/* TRANSLATORS: The leading word "logging" is the name
112
113
of the plugin api, and so should not be translated. */
113
errmsg_printf(error::ERROR,
114
errmsg_printf(ERRMSG_LVL_ERROR,
114
115
_("logging '%s' postEnd() failed"),
115
116
handler->getName().c_str());
122
class ResetIterate : public std::unary_function<plugin::Logging *, bool>
126
ResetIterate(Session *session_arg) :
127
std::unary_function<plugin::Logging *, bool>(),
128
session(session_arg) {}
130
inline result_type operator()(argument_type handler)
132
if (handler->resetGlobalScoreboard())
134
/* TRANSLATORS: The leading word "logging" is the name
135
of the plugin api, and so should not be translated. */
136
errmsg_printf(error::ERROR,
137
_("logging '%s' resetCurrentScoreboard() failed"),
138
handler->getName().c_str());
146
123
/* This is the Logging::preDo entry point.
147
124
This gets called by the rest of the Drizzle server code */
148
125
bool plugin::Logging::preDo(Session *session)
150
127
/* Use find_if instead of foreach so that we can collect return codes */
151
std::vector<plugin::Logging *>::iterator iter=
152
std::find_if(all_loggers.begin(), all_loggers.end(),
153
PreIterate(session));
128
vector<plugin::Logging *>::iterator iter=
129
find_if(all_loggers.begin(), all_loggers.end(),
130
PreIterate(session));
154
131
/* If iter is == end() here, that means that all of the plugins returned
155
132
* false, which in this case means they all succeeded. Since we want to
156
133
* return false on success, we return the value of the two being !=
163
140
bool plugin::Logging::postDo(Session *session)
165
142
/* Use find_if instead of foreach so that we can collect return codes */
166
std::vector<plugin::Logging *>::iterator iter=
167
std::find_if(all_loggers.begin(), all_loggers.end(),
168
PostIterate(session));
143
vector<plugin::Logging *>::iterator iter=
144
find_if(all_loggers.begin(), all_loggers.end(),
145
PostIterate(session));
169
146
/* If iter is == end() here, that means that all of the plugins returned
170
147
* false, which in this case means they all succeeded. Since we want to
171
148
* return false on success, we return the value of the two being !=
177
154
bool plugin::Logging::postEndDo(Session *session)
179
156
/* Use find_if instead of foreach so that we can collect return codes */
180
std::vector<plugin::Logging *>::iterator iter=
181
std::find_if(all_loggers.begin(), all_loggers.end(),
182
PostEndIterate(session));
157
vector<plugin::Logging *>::iterator iter=
158
find_if(all_loggers.begin(), all_loggers.end(),
159
PostEndIterate(session));
183
160
/* If iter is == end() here, that means that all of the plugins returned
184
161
* false, which in this case means they all succeeded. Since we want to
185
162
* return false on success, we return the value of the two being !=
187
164
return iter != all_loggers.end();
190
/* Resets global stats for logging plugin */
191
bool plugin::Logging::resetStats(Session *session)
193
std::vector<plugin::Logging *>::iterator iter=
194
std::find_if(all_loggers.begin(), all_loggers.end(),
195
ResetIterate(session));
197
return iter != all_loggers.end();
200
167
} /* namespace drizzled */