~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/logging.cc

Renamed more stuff to drizzle.

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
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
 
using namespace std;
31
 
 
32
 
namespace drizzled
33
 
{
34
 
 
35
 
vector<plugin::Logging *> all_loggers;
36
 
 
37
 
 
38
 
bool plugin::Logging::addPlugin(plugin::Logging *handler)
39
 
{
40
 
  if (handler != NULL)
41
 
    all_loggers.push_back(handler);
42
 
  return false;
43
 
}
44
 
 
45
 
void plugin::Logging::removePlugin(plugin::Logging *handler)
46
 
{
47
 
  if (handler != NULL)
48
 
    all_loggers.erase(find(all_loggers.begin(), all_loggers.end(), handler));
49
 
}
50
 
 
51
 
 
52
 
class PreIterate : public unary_function<plugin::Logging *, bool>
53
 
{
54
 
  Session *session;
55
 
public:
56
 
  PreIterate(Session *session_arg) :
57
 
    unary_function<plugin::Logging *, bool>(),
58
 
    session(session_arg) {}
59
 
 
60
 
  inline result_type operator()(argument_type handler)
61
 
  {
62
 
    if (handler->pre(session))
63
 
    {
64
 
      /* TRANSLATORS: The leading word "logging" is the name
65
 
         of the plugin api, and so should not be translated. */
66
 
      errmsg_printf(ERRMSG_LVL_ERROR,
67
 
                    _("logging '%s' pre() failed"),
68
 
                    handler->getName().c_str());
69
 
      return true;
70
 
    }
71
 
    return false;
72
 
  }
73
 
};
74
 
 
75
 
 
76
 
class PostIterate : public unary_function<plugin::Logging *, bool>
77
 
{
78
 
  Session *session;
79
 
public:
80
 
  PostIterate(Session *session_arg) :
81
 
    unary_function<plugin::Logging *, bool>(),
82
 
    session(session_arg) {}
83
 
 
84
 
  /* This gets called once for each loaded logging plugin */
85
 
  inline result_type operator()(argument_type handler)
86
 
  {
87
 
    if (handler->post(session))
88
 
    {
89
 
      /* TRANSLATORS: The leading word "logging" is the name
90
 
         of the plugin api, and so should not be translated. */
91
 
      errmsg_printf(ERRMSG_LVL_ERROR,
92
 
                    _("logging '%s' post() failed"),
93
 
                    handler->getName().c_str());
94
 
      return true;
95
 
    }
96
 
    return false;
97
 
  }
98
 
};
99
 
 
100
 
class PostEndIterate : public unary_function<plugin::Logging *, bool>
101
 
{
102
 
  Session *session;
103
 
public:
104
 
  PostEndIterate(Session *session_arg) :
105
 
    unary_function<plugin::Logging *, bool>(),
106
 
    session(session_arg) {}
107
 
 
108
 
  /* This gets called once for each loaded logging plugin */
109
 
  inline result_type operator()(argument_type handler)
110
 
  {
111
 
    if (handler->postEnd(session))
112
 
    {
113
 
      /* TRANSLATORS: The leading word "logging" is the name
114
 
         of the plugin api, and so should not be translated. */
115
 
      errmsg_printf(ERRMSG_LVL_ERROR,
116
 
                    _("logging '%s' postEnd() failed"),
117
 
                    handler->getName().c_str());
118
 
      return true;
119
 
    }
120
 
    return false;
121
 
  }
122
 
};
123
 
 
124
 
/* This is the Logging::preDo entry point.
125
 
   This gets called by the rest of the Drizzle server code */
126
 
bool plugin::Logging::preDo(Session *session)
127
 
{
128
 
  /* Use find_if instead of foreach so that we can collect return codes */
129
 
  vector<plugin::Logging *>::iterator iter=
130
 
    find_if(all_loggers.begin(), all_loggers.end(),
131
 
            PreIterate(session)); 
132
 
  /* If iter is == end() here, that means that all of the plugins returned
133
 
   * false, which in this case means they all succeeded. Since we want to 
134
 
   * return false on success, we return the value of the two being != 
135
 
   */
136
 
  return iter != all_loggers.end();
137
 
}
138
 
 
139
 
/* This is the Logging::postDo entry point.
140
 
   This gets called by the rest of the Drizzle server code */
141
 
bool plugin::Logging::postDo(Session *session)
142
 
{
143
 
  /* Use find_if instead of foreach so that we can collect return codes */
144
 
  vector<plugin::Logging *>::iterator iter=
145
 
    find_if(all_loggers.begin(), all_loggers.end(),
146
 
            PostIterate(session)); 
147
 
  /* If iter is == end() here, that means that all of the plugins returned
148
 
   * false, which in this case means they all succeeded. Since we want to 
149
 
   * return false on success, we return the value of the two being != 
150
 
   */
151
 
  return iter != all_loggers.end();
152
 
}
153
 
 
154
 
/* This gets called in the session destructor */
155
 
bool plugin::Logging::postEndDo(Session *session)
156
 
{
157
 
  /* Use find_if instead of foreach so that we can collect return codes */
158
 
  vector<plugin::Logging *>::iterator iter=
159
 
    find_if(all_loggers.begin(), all_loggers.end(),
160
 
            PostEndIterate(session));
161
 
  /* If iter is == end() here, that means that all of the plugins returned
162
 
   * false, which in this case means they all succeeded. Since we want to
163
 
   * return false on success, we return the value of the two being !=
164
 
   */
165
 
  return iter != all_loggers.end();
166
 
}
167
 
 
168
 
} /* namespace drizzled */