~drizzle-trunk/drizzle/development

499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
499.2.10 by Mark Atwood
add editor format hints, and other useful metadata comments
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
499.2.10 by Mark Atwood
add editor format hints, and other useful metadata comments
5
 *
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.
9
 *
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.
14
 *
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
18
 */
19
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <config.h>
21
#include <drizzled/plugin/logging.h>
22
#include <drizzled/gettext.h>
23
#include <drizzled/errmsg_print.h>
971.1.46 by Monty Taylor
Made plugin registration go through Plugin_registry.
24
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
25
#include <vector>
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
26
#include <algorithm>
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
27
2252.1.22 by Olaf van der Spek
Common fwd
28
namespace drizzled {
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
29
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
30
std::vector<plugin::Logging *> all_loggers;
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
31
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
32
bool plugin::Logging::addPlugin(plugin::Logging *handler)
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
33
{
971.1.74 by Monty Taylor
Added a null trap.
34
  if (handler != NULL)
35
    all_loggers.push_back(handler);
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
36
  return false;
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
37
}
38
1130.1.18 by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that
39
void plugin::Logging::removePlugin(plugin::Logging *handler)
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
40
{
971.1.74 by Monty Taylor
Added a null trap.
41
  if (handler != NULL)
1966.2.14 by Brian Aker
Merge in some additional std namespace finds.
42
    all_loggers.erase(std::find(all_loggers.begin(), all_loggers.end(), handler));
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
43
}
383.6.1 by Mark Atwood
add pluggable logging
44
958.1.1 by Monty Taylor
Made logging plugin class based.
45
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
46
class PreIterate : public std::unary_function<plugin::Logging *, bool>
383.6.1 by Mark Atwood
add pluggable logging
47
{
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
48
  Session *session;
49
public:
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
50
  PreIterate(Session *session_arg) :
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
51
    std::unary_function<plugin::Logging *, bool>(),
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
52
    session(session_arg) {}
383.6.1 by Mark Atwood
add pluggable logging
53
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
54
  inline result_type operator()(argument_type handler)
383.6.1 by Mark Atwood
add pluggable logging
55
  {
958.1.1 by Monty Taylor
Made logging plugin class based.
56
    if (handler->pre(session))
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
57
    {
58
      /* TRANSLATORS: The leading word "logging" is the name
59
         of the plugin api, and so should not be translated. */
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
60
      errmsg_printf(error::ERROR,
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
61
                    _("logging '%s' pre() failed"),
62
                    handler->getName().c_str());
63
      return true;
64
    }
65
    return false;
66
  }
67
};
68
69
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
70
class PostIterate : public std::unary_function<plugin::Logging *, bool>
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
71
{
72
  Session *session;
73
public:
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
74
  PostIterate(Session *session_arg) :
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
75
    std::unary_function<plugin::Logging *, bool>(),
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
76
    session(session_arg) {}
77
968.2.34 by Monty Taylor
Made all_logging static - not that it matters since it's gonna become a member variable one day.
78
  /* This gets called once for each loaded logging plugin */
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
79
  inline result_type operator()(argument_type handler)
80
  {
81
    if (handler->post(session))
82
    {
83
      /* TRANSLATORS: The leading word "logging" is the name
84
         of the plugin api, and so should not be translated. */
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
85
      errmsg_printf(error::ERROR,
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
86
                    _("logging '%s' post() failed"),
87
                    handler->getName().c_str());
88
      return true;
89
    }
90
    return false;
91
  }
92
};
93
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
94
class PostEndIterate : public std::unary_function<plugin::Logging *, bool>
1316.1.1 by Joe Daly
add plugin handle to logging to indicate when the session destructor is called
95
{
96
  Session *session;
97
public:
98
  PostEndIterate(Session *session_arg) :
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
99
    std::unary_function<plugin::Logging *, bool>(),
1316.1.1 by Joe Daly
add plugin handle to logging to indicate when the session destructor is called
100
    session(session_arg) {}
101
102
  /* This gets called once for each loaded logging plugin */
103
  inline result_type operator()(argument_type handler)
104
  {
105
    if (handler->postEnd(session))
106
    {
107
      /* TRANSLATORS: The leading word "logging" is the name
108
         of the plugin api, and so should not be translated. */
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
109
      errmsg_printf(error::ERROR,
1316.1.1 by Joe Daly
add plugin handle to logging to indicate when the session destructor is called
110
                    _("logging '%s' postEnd() failed"),
111
                    handler->getName().c_str());
112
      return true;
113
    }
114
    return false;
115
  }
116
};
383.6.1 by Mark Atwood
add pluggable logging
117
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
118
class ResetIterate : public std::unary_function<plugin::Logging *, bool>
1900.3.1 by Andrew Hutchings
Add FLUSH GLOBAL STATUS; command
119
{
120
  Session *session;
121
public:
122
  ResetIterate(Session *session_arg) :
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
123
    std::unary_function<plugin::Logging *, bool>(),
1900.3.1 by Andrew Hutchings
Add FLUSH GLOBAL STATUS; command
124
    session(session_arg) {}
125
126
  inline result_type operator()(argument_type handler)
127
  {
128
    if (handler->resetGlobalScoreboard())
129
    {
130
      /* TRANSLATORS: The leading word "logging" is the name
131
         of the plugin api, and so should not be translated. */
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
132
      errmsg_printf(error::ERROR,
1900.3.1 by Andrew Hutchings
Add FLUSH GLOBAL STATUS; command
133
                    _("logging '%s' resetCurrentScoreboard() failed"),
134
                    handler->getName().c_str());
135
      return true;
136
    }
137
    return false;
138
  }
139
};
140
141
1130.1.16 by Monty Taylor
Fixed naming issue.
142
/* This is the Logging::preDo entry point.
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
143
   This gets called by the rest of the Drizzle server code */
1130.1.16 by Monty Taylor
Fixed naming issue.
144
bool plugin::Logging::preDo(Session *session)
383.6.1 by Mark Atwood
add pluggable logging
145
{
968.2.34 by Monty Taylor
Made all_logging static - not that it matters since it's gonna become a member variable one day.
146
  /* Use find_if instead of foreach so that we can collect return codes */
1966.2.6 by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing
147
  std::vector<plugin::Logging *>::iterator iter=
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
148
    std::find_if(all_loggers.begin(), all_loggers.end(),
149
                 PreIterate(session)); 
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
150
  /* If iter is == end() here, that means that all of the plugins returned
151
   * false, which in this case means they all succeeded. Since we want to 
152
   * return false on success, we return the value of the two being != 
153
   */
154
  return iter != all_loggers.end();
155
}
156
1130.1.16 by Monty Taylor
Fixed naming issue.
157
/* This is the Logging::postDo entry point.
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
158
   This gets called by the rest of the Drizzle server code */
1130.1.16 by Monty Taylor
Fixed naming issue.
159
bool plugin::Logging::postDo(Session *session)
383.6.1 by Mark Atwood
add pluggable logging
160
{
968.2.34 by Monty Taylor
Made all_logging static - not that it matters since it's gonna become a member variable one day.
161
  /* Use find_if instead of foreach so that we can collect return codes */
1966.2.6 by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing
162
  std::vector<plugin::Logging *>::iterator iter=
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
163
    std::find_if(all_loggers.begin(), all_loggers.end(),
164
                 PostIterate(session)); 
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
165
  /* If iter is == end() here, that means that all of the plugins returned
166
   * false, which in this case means they all succeeded. Since we want to 
167
   * return false on success, we return the value of the two being != 
168
   */
169
  return iter != all_loggers.end();
383.6.1 by Mark Atwood
add pluggable logging
170
}
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
171
1316.1.1 by Joe Daly
add plugin handle to logging to indicate when the session destructor is called
172
/* This gets called in the session destructor */
173
bool plugin::Logging::postEndDo(Session *session)
174
{
175
  /* Use find_if instead of foreach so that we can collect return codes */
1966.2.6 by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing
176
  std::vector<plugin::Logging *>::iterator iter=
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
177
    std::find_if(all_loggers.begin(), all_loggers.end(),
178
                 PostEndIterate(session));
1316.1.1 by Joe Daly
add plugin handle to logging to indicate when the session destructor is called
179
  /* If iter is == end() here, that means that all of the plugins returned
180
   * false, which in this case means they all succeeded. Since we want to
181
   * return false on success, we return the value of the two being !=
182
   */
183
  return iter != all_loggers.end();
184
}
185
1900.3.1 by Andrew Hutchings
Add FLUSH GLOBAL STATUS; command
186
/* Resets global stats for logging plugin */
187
bool plugin::Logging::resetStats(Session *session)
188
{
1966.2.6 by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing
189
  std::vector<plugin::Logging *>::iterator iter=
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
190
    std::find_if(all_loggers.begin(), all_loggers.end(),
191
                 ResetIterate(session));
1900.3.1 by Andrew Hutchings
Add FLUSH GLOBAL STATUS; command
192
193
  return iter != all_loggers.end();
194
}
195
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
196
} /* namespace drizzled */