~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
 *
1010 by Brian Aker
Replacing Sun employee copyright headers (aka... anything done by a Sun
4
 *  Copyright (C) 2008 Sun Microsystems
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
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
20
#include "config.h"
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
21
#include <drizzled/plugin/logging.h>
549 by Monty Taylor
Took gettext.h out of header files.
22
#include <drizzled/gettext.h>
1110.1.5 by Monty Taylor
Renamed PluginRegistry to plugin::Registry.
23
#include "drizzled/plugin/registry.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>
26
1241.9.26 by Monty Taylor
Removed forward declares from server_includes.h
27
class Session;
28
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
29
using namespace std;
30
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
31
namespace drizzled
32
{
33
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
34
vector<plugin::Logging *> all_loggers;
35
36
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
37
bool plugin::Logging::addPlugin(plugin::Logging *handler)
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
38
{
971.1.74 by Monty Taylor
Added a null trap.
39
  if (handler != NULL)
40
    all_loggers.push_back(handler);
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
41
  return false;
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
42
}
43
1130.1.18 by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that
44
void plugin::Logging::removePlugin(plugin::Logging *handler)
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
45
{
971.1.74 by Monty Taylor
Added a null trap.
46
  if (handler != NULL)
47
    all_loggers.erase(find(all_loggers.begin(), all_loggers.end(), handler));
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
48
}
383.6.1 by Mark Atwood
add pluggable logging
49
958.1.1 by Monty Taylor
Made logging plugin class based.
50
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
51
class PreIterate : public unary_function<plugin::Logging *, bool>
383.6.1 by Mark Atwood
add pluggable logging
52
{
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
53
  Session *session;
54
public:
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
55
  PreIterate(Session *session_arg) :
56
    unary_function<plugin::Logging *, bool>(),
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
57
    session(session_arg) {}
383.6.1 by Mark Atwood
add pluggable logging
58
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
59
  inline result_type operator()(argument_type handler)
383.6.1 by Mark Atwood
add pluggable logging
60
  {
958.1.1 by Monty Taylor
Made logging plugin class based.
61
    if (handler->pre(session))
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
62
    {
63
      /* TRANSLATORS: The leading word "logging" is the name
64
         of the plugin api, and so should not be translated. */
958.1.1 by Monty Taylor
Made logging plugin class based.
65
      errmsg_printf(ERRMSG_LVL_ERROR,
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
66
                    _("logging '%s' pre() failed"),
67
                    handler->getName().c_str());
68
      return true;
69
    }
70
    return false;
71
  }
72
};
73
74
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
75
class PostIterate : public unary_function<plugin::Logging *, bool>
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
76
{
77
  Session *session;
78
public:
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
79
  PostIterate(Session *session_arg) :
80
    unary_function<plugin::Logging *, bool>(),
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
81
    session(session_arg) {}
82
968.2.34 by Monty Taylor
Made all_logging static - not that it matters since it's gonna become a member variable one day.
83
  /* This gets called once for each loaded logging plugin */
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
84
  inline result_type operator()(argument_type handler)
85
  {
86
    if (handler->post(session))
87
    {
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());
93
      return true;
94
    }
95
    return false;
96
  }
97
};
98
383.6.1 by Mark Atwood
add pluggable logging
99
1130.1.16 by Monty Taylor
Fixed naming issue.
100
/* This is the Logging::preDo entry point.
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
101
   This gets called by the rest of the Drizzle server code */
1130.1.16 by Monty Taylor
Fixed naming issue.
102
bool plugin::Logging::preDo(Session *session)
383.6.1 by Mark Atwood
add pluggable logging
103
{
968.2.34 by Monty Taylor
Made all_logging static - not that it matters since it's gonna become a member variable one day.
104
  /* Use find_if instead of foreach so that we can collect return codes */
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
105
  vector<plugin::Logging *>::iterator iter=
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
106
    find_if(all_loggers.begin(), all_loggers.end(),
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
107
            PreIterate(session)); 
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
108
  /* If iter is == end() here, that means that all of the plugins returned
109
   * false, which in this case means they all succeeded. Since we want to 
110
   * return false on success, we return the value of the two being != 
111
   */
112
  return iter != all_loggers.end();
113
}
114
1130.1.16 by Monty Taylor
Fixed naming issue.
115
/* This is the Logging::postDo entry point.
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
116
   This gets called by the rest of the Drizzle server code */
1130.1.16 by Monty Taylor
Fixed naming issue.
117
bool plugin::Logging::postDo(Session *session)
383.6.1 by Mark Atwood
add pluggable logging
118
{
968.2.34 by Monty Taylor
Made all_logging static - not that it matters since it's gonna become a member variable one day.
119
  /* Use find_if instead of foreach so that we can collect return codes */
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
120
  vector<plugin::Logging *>::iterator iter=
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
121
    find_if(all_loggers.begin(), all_loggers.end(),
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
122
            PostIterate(session)); 
968.2.33 by Monty Taylor
Removed plugin_foreach from logging_handler.
123
  /* If iter is == end() here, that means that all of the plugins returned
124
   * false, which in this case means they all succeeded. Since we want to 
125
   * return false on success, we return the value of the two being != 
126
   */
127
  return iter != all_loggers.end();
383.6.1 by Mark Atwood
add pluggable logging
128
}
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
129
130
} /* namespace drizzled */