~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/logging.cc

  • Committer: Monty
  • Date: 2008-10-02 05:41:33 UTC
  • mfrom: (398.1.10 codestyle)
  • Revision ID: mordred@scylla.inaugust.com-20081002054133-tyxv5bmqpazfaqqi
Merged up to 408 of stdint-includes-fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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
 
 
20
 
#include <config.h>
21
 
#include <drizzled/plugin/logging.h>
22
 
#include <drizzled/gettext.h>
23
 
#include <drizzled/errmsg_print.h>
24
 
 
25
 
#include <vector>
26
 
#include <algorithm>
27
 
 
28
 
class Session;
29
 
 
30
 
namespace drizzled
31
 
{
32
 
 
33
 
std::vector<plugin::Logging *> all_loggers;
34
 
 
35
 
 
36
 
bool plugin::Logging::addPlugin(plugin::Logging *handler)
37
 
{
38
 
  if (handler != NULL)
39
 
    all_loggers.push_back(handler);
40
 
  return false;
41
 
}
42
 
 
43
 
void plugin::Logging::removePlugin(plugin::Logging *handler)
44
 
{
45
 
  if (handler != NULL)
46
 
    all_loggers.erase(std::find(all_loggers.begin(), all_loggers.end(), handler));
47
 
}
48
 
 
49
 
 
50
 
class PreIterate : public std::unary_function<plugin::Logging *, bool>
51
 
{
52
 
  Session *session;
53
 
public:
54
 
  PreIterate(Session *session_arg) :
55
 
    std::unary_function<plugin::Logging *, bool>(),
56
 
    session(session_arg) {}
57
 
 
58
 
  inline result_type operator()(argument_type handler)
59
 
  {
60
 
    if (handler->pre(session))
61
 
    {
62
 
      /* TRANSLATORS: The leading word "logging" is the name
63
 
         of the plugin api, and so should not be translated. */
64
 
      errmsg_printf(error::ERROR,
65
 
                    _("logging '%s' pre() failed"),
66
 
                    handler->getName().c_str());
67
 
      return true;
68
 
    }
69
 
    return false;
70
 
  }
71
 
};
72
 
 
73
 
 
74
 
class PostIterate : public std::unary_function<plugin::Logging *, bool>
75
 
{
76
 
  Session *session;
77
 
public:
78
 
  PostIterate(Session *session_arg) :
79
 
    std::unary_function<plugin::Logging *, bool>(),
80
 
    session(session_arg) {}
81
 
 
82
 
  /* This gets called once for each loaded logging plugin */
83
 
  inline result_type operator()(argument_type handler)
84
 
  {
85
 
    if (handler->post(session))
86
 
    {
87
 
      /* TRANSLATORS: The leading word "logging" is the name
88
 
         of the plugin api, and so should not be translated. */
89
 
      errmsg_printf(error::ERROR,
90
 
                    _("logging '%s' post() failed"),
91
 
                    handler->getName().c_str());
92
 
      return true;
93
 
    }
94
 
    return false;
95
 
  }
96
 
};
97
 
 
98
 
class PostEndIterate : public std::unary_function<plugin::Logging *, bool>
99
 
{
100
 
  Session *session;
101
 
public:
102
 
  PostEndIterate(Session *session_arg) :
103
 
    std::unary_function<plugin::Logging *, bool>(),
104
 
    session(session_arg) {}
105
 
 
106
 
  /* This gets called once for each loaded logging plugin */
107
 
  inline result_type operator()(argument_type handler)
108
 
  {
109
 
    if (handler->postEnd(session))
110
 
    {
111
 
      /* TRANSLATORS: The leading word "logging" is the name
112
 
         of the plugin api, and so should not be translated. */
113
 
      errmsg_printf(error::ERROR,
114
 
                    _("logging '%s' postEnd() failed"),
115
 
                    handler->getName().c_str());
116
 
      return true;
117
 
    }
118
 
    return false;
119
 
  }
120
 
};
121
 
 
122
 
class ResetIterate : public std::unary_function<plugin::Logging *, bool>
123
 
{
124
 
  Session *session;
125
 
public:
126
 
  ResetIterate(Session *session_arg) :
127
 
    std::unary_function<plugin::Logging *, bool>(),
128
 
    session(session_arg) {}
129
 
 
130
 
  inline result_type operator()(argument_type handler)
131
 
  {
132
 
    if (handler->resetGlobalScoreboard())
133
 
    {
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());
139
 
      return true;
140
 
    }
141
 
    return false;
142
 
  }
143
 
};
144
 
 
145
 
 
146
 
/* This is the Logging::preDo entry point.
147
 
   This gets called by the rest of the Drizzle server code */
148
 
bool plugin::Logging::preDo(Session *session)
149
 
{
150
 
  /* 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)); 
154
 
  /* If iter is == end() here, that means that all of the plugins returned
155
 
   * false, which in this case means they all succeeded. Since we want to 
156
 
   * return false on success, we return the value of the two being != 
157
 
   */
158
 
  return iter != all_loggers.end();
159
 
}
160
 
 
161
 
/* This is the Logging::postDo entry point.
162
 
   This gets called by the rest of the Drizzle server code */
163
 
bool plugin::Logging::postDo(Session *session)
164
 
{
165
 
  /* 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)); 
169
 
  /* If iter is == end() here, that means that all of the plugins returned
170
 
   * false, which in this case means they all succeeded. Since we want to 
171
 
   * return false on success, we return the value of the two being != 
172
 
   */
173
 
  return iter != all_loggers.end();
174
 
}
175
 
 
176
 
/* This gets called in the session destructor */
177
 
bool plugin::Logging::postEndDo(Session *session)
178
 
{
179
 
  /* 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));
183
 
  /* If iter is == end() here, that means that all of the plugins returned
184
 
   * false, which in this case means they all succeeded. Since we want to
185
 
   * return false on success, we return the value of the two being !=
186
 
   */
187
 
  return iter != all_loggers.end();
188
 
}
189
 
 
190
 
/* Resets global stats for logging plugin */
191
 
bool plugin::Logging::resetStats(Session *session)
192
 
{
193
 
  std::vector<plugin::Logging *>::iterator iter=
194
 
    std::find_if(all_loggers.begin(), all_loggers.end(),
195
 
                 ResetIterate(session));
196
 
 
197
 
  return iter != all_loggers.end();
198
 
}
199
 
 
200
 
} /* namespace drizzled */