~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/logging.cc

  • Committer: Brian Aker
  • Date: 2009-02-05 10:38:55 UTC
  • Revision ID: brian@tangent.org-20090205103855-wajzccrbu7zbvmh4
Reworked some classes out of session.h
Also updated ignore file.

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 Mark Atwood
 
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
 
1
20
#include <drizzled/server_includes.h>
2
21
#include <drizzled/logging.h>
 
22
#include <drizzled/gettext.h>
3
23
 
4
24
int logging_initializer(st_plugin_int *plugin)
5
25
{
6
26
  logging_t *p;
7
27
 
8
 
  fprintf(stderr, "MRA %s plugin:%s dl:%s\n",
9
 
          __func__, plugin->name.str, plugin->plugin_dl->dl.str);
10
 
 
11
 
  p= (logging_t *) malloc(sizeof(logging_t));
 
28
  p= new logging_t;
12
29
  if (p == NULL) return 1;
13
30
  memset(p, 0, sizeof(logging_t));
14
31
 
18
35
  {
19
36
    if (plugin->plugin->init((void *)p))
20
37
    {
21
 
      sql_print_error("Logging plugin '%s' init function returned error.",
 
38
      /* TRANSLATORS: The leading word "logging" is the name
 
39
         of the plugin api, and so should not be translated. */
 
40
      errmsg_printf(ERRMSG_LVL_ERROR, "logging plugin '%s' init() failed",
22
41
                      plugin->name.str);
23
42
      goto err;
24
43
    }
25
44
  }
 
45
 
 
46
  plugin->state= PLUGIN_IS_READY;
 
47
 
26
48
  return 0;
27
49
 
28
50
err:
29
 
  free(p);
 
51
  delete p;
30
52
  return 1;
31
53
}
32
54
 
33
55
int logging_finalizer(st_plugin_int *plugin)
34
 
 
56
{
35
57
  logging_t *p = (logging_t *) plugin->data;
36
58
 
37
 
  fprintf(stderr, "MRA %s plugin:%s dl:%s\n",
38
 
          __func__, plugin->name.str, plugin->plugin_dl->dl.str);
39
 
 
40
59
  if (plugin->plugin->deinit)
41
60
  {
42
61
    if (plugin->plugin->deinit((void *)p))
43
62
    {
44
 
      sql_print_error("Logging plugin '%s' deinit function returned error.",
45
 
                      plugin->name.str);
 
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, _("logging plugin '%s' deinit() failed"),
 
66
                      plugin->name.str);
46
67
    }
47
68
  }
48
69
 
49
 
  if (p) free(p);
 
70
  if (p) delete p;
50
71
 
51
72
  return 0;
52
73
}
53
74
 
54
 
static bool logging_pre_iterate (THD *thd, plugin_ref plugin,
55
 
                                 void *stuff __attribute__ ((__unused__)))
 
75
/* This gets called by plugin_foreach once for each loaded logging plugin */
 
76
static bool logging_pre_iterate (Session *session, plugin_ref plugin, void *)
56
77
{
57
78
  logging_t *l= plugin_data(plugin, logging_t *);
58
79
 
 
80
  /* call this loaded logging plugin's logging_pre function pointer */
59
81
  if (l && l->logging_pre)
60
82
  {
61
 
    if (l->logging_pre(thd))
 
83
    if (l->logging_pre(session))
 
84
    {
 
85
      /* TRANSLATORS: The leading word "logging" is the name
 
86
         of the plugin api, and so should not be translated. */
 
87
      errmsg_printf(ERRMSG_LVL_ERROR, _("logging plugin '%s' logging_pre() failed"),
 
88
                      (char *)plugin_name(plugin));
62
89
      return true;
 
90
    }
63
91
  }
64
92
  return false;
65
93
}
66
94
 
67
 
void logging_pre_do (THD *thd)
 
95
/* This is the logging_pre_do entry point.
 
96
   This gets called by the rest of the Drizzle server code */
 
97
bool logging_pre_do (Session *session)
68
98
{
69
 
  if (plugin_foreach(thd, logging_pre_iterate, DRIZZLE_LOGGER_PLUGIN, NULL))
70
 
  {
71
 
    sql_print_error("Logging plugin pre had an error.");
72
 
  }
73
 
  return;
 
99
  bool foreach_rv;
 
100
 
 
101
  foreach_rv= plugin_foreach(session,
 
102
                             logging_pre_iterate,
 
103
                             DRIZZLE_LOGGER_PLUGIN,
 
104
                             NULL);
 
105
  return foreach_rv;
74
106
}
75
107
 
76
 
static bool logging_post_iterate (THD *thd, plugin_ref plugin, 
77
 
                                  void *stuff __attribute__ ((__unused__)))
 
108
/* This gets called by plugin_foreach once for each loaded logging plugin */
 
109
static bool logging_post_iterate (Session *session, plugin_ref plugin, void *)
78
110
{
79
111
  logging_t *l= plugin_data(plugin, logging_t *);
80
112
 
81
113
  if (l && l->logging_post)
82
114
  {
83
 
    if (l->logging_post(thd))
 
115
    if (l->logging_post(session))
 
116
    {
 
117
      /* TRANSLATORS: The leading word "logging" is the name
 
118
         of the plugin api, and so should not be translated. */
 
119
      errmsg_printf(ERRMSG_LVL_ERROR, _("logging plugin '%s' logging_post() failed"),
 
120
                      (char *)plugin_name(plugin));
84
121
      return true;
 
122
    }
85
123
  }
86
124
  return false;
87
125
}
88
126
 
89
 
void logging_post_do (THD *thd)
 
127
/* This is the logging_pre_do entry point.
 
128
   This gets called by the rest of the Drizzle server code */
 
129
bool logging_post_do (Session *session)
90
130
{
91
 
  if (plugin_foreach(thd, logging_post_iterate, DRIZZLE_LOGGER_PLUGIN, NULL))
92
 
  {
93
 
    sql_print_error("Logging plugin post had an error.");
94
 
  }
95
 
  return;
 
131
  bool foreach_rv;
 
132
 
 
133
  foreach_rv= plugin_foreach(session,
 
134
                             logging_post_iterate,
 
135
                             DRIZZLE_LOGGER_PLUGIN,
 
136
                             NULL);
 
137
  return foreach_rv;
96
138
}