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/plugin/registry.h"
34
vector<plugin::Logging *> all_loggers;
37
bool plugin::Logging::addPlugin(plugin::Logging *handler)
40
all_loggers.push_back(handler);
44
void plugin::Logging::removePlugin(plugin::Logging *handler)
47
all_loggers.erase(find(all_loggers.begin(), all_loggers.end(), handler));
51
class PreIterate : public unary_function<plugin::Logging *, bool>
55
PreIterate(Session *session_arg) :
56
unary_function<plugin::Logging *, bool>(),
57
session(session_arg) {}
59
inline result_type operator()(argument_type handler)
61
if (handler->pre(session))
63
/* TRANSLATORS: The leading word "logging" is the name
64
of the plugin api, and so should not be translated. */
65
errmsg_printf(ERRMSG_LVL_ERROR,
66
_("logging '%s' pre() failed"),
67
handler->getName().c_str());
75
class PostIterate : public unary_function<plugin::Logging *, bool>
79
PostIterate(Session *session_arg) :
80
unary_function<plugin::Logging *, bool>(),
81
session(session_arg) {}
83
/* This gets called once for each loaded logging plugin */
84
inline result_type operator()(argument_type handler)
86
if (handler->post(session))
88
/* TRANSLATORS: The leading word "logging" is the name
89
of the plugin api, and so should not be translated. */
90
errmsg_printf(ERRMSG_LVL_ERROR,
91
_("logging '%s' post() failed"),
92
handler->getName().c_str());
99
class PostEndIterate : public unary_function<plugin::Logging *, bool>
103
PostEndIterate(Session *session_arg) :
104
unary_function<plugin::Logging *, bool>(),
105
session(session_arg) {}
107
/* This gets called once for each loaded logging plugin */
108
inline result_type operator()(argument_type handler)
110
if (handler->postEnd(session))
112
/* TRANSLATORS: The leading word "logging" is the name
113
of the plugin api, and so should not be translated. */
114
errmsg_printf(ERRMSG_LVL_ERROR,
115
_("logging '%s' postEnd() failed"),
116
handler->getName().c_str());
123
/* This is the Logging::preDo entry point.
124
This gets called by the rest of the Drizzle server code */
125
bool plugin::Logging::preDo(Session *session)
127
/* Use find_if instead of foreach so that we can collect return codes */
128
vector<plugin::Logging *>::iterator iter=
129
find_if(all_loggers.begin(), all_loggers.end(),
130
PreIterate(session));
131
/* If iter is == end() here, that means that all of the plugins returned
132
* false, which in this case means they all succeeded. Since we want to
133
* return false on success, we return the value of the two being !=
135
return iter != all_loggers.end();
138
/* This is the Logging::postDo entry point.
139
This gets called by the rest of the Drizzle server code */
140
bool plugin::Logging::postDo(Session *session)
142
/* Use find_if instead of foreach so that we can collect return codes */
143
vector<plugin::Logging *>::iterator iter=
144
find_if(all_loggers.begin(), all_loggers.end(),
145
PostIterate(session));
146
/* If iter is == end() here, that means that all of the plugins returned
147
* false, which in this case means they all succeeded. Since we want to
148
* return false on success, we return the value of the two being !=
150
return iter != all_loggers.end();
153
/* This gets called in the session destructor */
154
bool plugin::Logging::postEndDo(Session *session)
156
/* Use find_if instead of foreach so that we can collect return codes */
157
vector<plugin::Logging *>::iterator iter=
158
find_if(all_loggers.begin(), all_loggers.end(),
159
PostEndIterate(session));
160
/* If iter is == end() here, that means that all of the plugins returned
161
* false, which in this case means they all succeeded. Since we want to
162
* return false on success, we return the value of the two being !=
164
return iter != all_loggers.end();
167
} /* namespace drizzled */
1
#include <drizzled/server_includes.h>
2
#include <drizzled/logging.h>
4
int logging_initializer(st_plugin_int *plugin)
8
fprintf(stderr, "MRA %s plugin:%s dl:%s\n",
9
__func__, plugin->name.str, plugin->plugin_dl->dl.str);
11
p= (logging_t *) malloc(sizeof(logging_t));
12
if (p == NULL) return 1;
13
memset(p, 0, sizeof(logging_t));
15
plugin->data= (void *)p;
17
if (plugin->plugin->init)
19
if (plugin->plugin->init((void *)p))
21
sql_print_error("Logging plugin '%s' init function returned error.",
33
int logging_finalizer(st_plugin_int *plugin)
35
logging_t *p = (logging_t *) plugin->data;
37
fprintf(stderr, "MRA %s plugin:%s dl:%s\n",
38
__func__, plugin->name.str, plugin->plugin_dl->dl.str);
40
if (plugin->plugin->deinit)
42
if (plugin->plugin->deinit((void *)p))
44
sql_print_error("Logging plugin '%s' deinit function returned error.",
54
static bool logging_pre_iterate (THD *thd, plugin_ref plugin,
55
void *stuff __attribute__ ((__unused__)))
57
logging_t *l= plugin_data(plugin, logging_t *);
59
if (l && l->logging_pre)
61
if (l->logging_pre(thd))
67
void logging_pre_do (THD *thd)
69
if (plugin_foreach(thd, logging_pre_iterate, DRIZZLE_LOGGER_PLUGIN, NULL))
71
sql_print_error("Logging plugin pre had an error.");
76
static bool logging_post_iterate (THD *thd, plugin_ref plugin,
77
void *stuff __attribute__ ((__unused__)))
79
logging_t *l= plugin_data(plugin, logging_t *);
81
if (l && l->logging_post)
83
if (l->logging_post(thd))
89
void logging_post_do (THD *thd)
91
if (plugin_foreach(thd, logging_post_iterate, DRIZZLE_LOGGER_PLUGIN, NULL))
93
sql_print_error("Logging plugin post had an error.");