~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/logging.cc

  • Committer: Brian Aker
  • Date: 2008-12-19 07:02:38 UTC
  • Revision ID: brian@tangent.org-20081219070238-569uxp3vsr6r37v1
Updated/fix to foreign key test.

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