~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/logging.cc

  • Committer: Joe Daly
  • Date: 2010-04-29 03:08:04 UTC
  • mto: This revision was merged to the branch mainline in revision 1523.
  • Revision ID: skinny.moey@gmail.com-20100429030804-ppssp19xwyrgm5of
remove com_stat_vars and rework lock in scoreboard to not lock on Sessions locating a slot they previously owned

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
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
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
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"
24
24
 
25
25
#include <vector>
26
 
#include <algorithm>
27
26
 
28
27
class Session;
29
28
 
 
29
using namespace std;
 
30
 
30
31
namespace drizzled
31
32
{
32
33
 
33
 
std::vector<plugin::Logging *> all_loggers;
 
34
vector<plugin::Logging *> all_loggers;
34
35
 
35
36
 
36
37
bool plugin::Logging::addPlugin(plugin::Logging *handler)
43
44
void plugin::Logging::removePlugin(plugin::Logging *handler)
44
45
{
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));
47
48
}
48
49
 
49
50
 
50
 
class PreIterate : public std::unary_function<plugin::Logging *, bool>
 
51
class PreIterate : public unary_function<plugin::Logging *, bool>
51
52
{
52
53
  Session *session;
53
54
public:
54
55
  PreIterate(Session *session_arg) :
55
 
    std::unary_function<plugin::Logging *, bool>(),
 
56
    unary_function<plugin::Logging *, bool>(),
56
57
    session(session_arg) {}
57
58
 
58
59
  inline result_type operator()(argument_type handler)
61
62
    {
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());
67
68
      return true;
71
72
};
72
73
 
73
74
 
74
 
class PostIterate : public std::unary_function<plugin::Logging *, bool>
 
75
class PostIterate : public unary_function<plugin::Logging *, bool>
75
76
{
76
77
  Session *session;
77
78
public:
78
79
  PostIterate(Session *session_arg) :
79
 
    std::unary_function<plugin::Logging *, bool>(),
 
80
    unary_function<plugin::Logging *, bool>(),
80
81
    session(session_arg) {}
81
82
 
82
83
  /* This gets called once for each loaded logging plugin */
86
87
    {
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());
92
93
      return true;
95
96
  }
96
97
};
97
98
 
98
 
class PostEndIterate : public std::unary_function<plugin::Logging *, bool>
 
99
class PostEndIterate : public unary_function<plugin::Logging *, bool>
99
100
{
100
101
  Session *session;
101
102
public:
102
103
  PostEndIterate(Session *session_arg) :
103
 
    std::unary_function<plugin::Logging *, bool>(),
 
104
    unary_function<plugin::Logging *, bool>(),
104
105
    session(session_arg) {}
105
106
 
106
107
  /* This gets called once for each loaded logging plugin */
110
111
    {
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());
116
117
      return true;
119
120
  }
120
121
};
121
122
 
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
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)
149
126
{
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)
164
141
{
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)
178
155
{
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();
188
165
}
189
166
 
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
167
} /* namespace drizzled */