~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/errmsg.cc

  • Committer: Mark Atwood
  • Date: 2008-10-17 20:35:11 UTC
  • mto: (520.1.13 drizzle)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: mark@fallenpegasus.com-20081017203511-q1s2pruvxf6d7it2
fixes as per MontyT's comments, prep for internationalization

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
 
 
 
3
 *
5
4
 *  Copyright (C) 2008 Mark Atwood
6
5
 *
7
6
 *  This program is free software; you can redistribute it and/or modify
16
15
 *  You should have received a copy of the GNU General Public License
17
16
 *  along with this program; if not, write to the Free Software
18
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 
20
18
 */
21
19
 
22
20
#include <drizzled/server_includes.h>
23
21
#include <drizzled/errmsg.h>
24
22
 
25
 
typedef struct errmsg_parms_st
26
 
{
27
 
  int priority;
28
 
  const char *format;
29
 
  va_list ap;
30
 
} errmsg_parms_t;
31
 
 
32
23
int errmsg_initializer(st_plugin_int *plugin)
33
24
{
34
25
  errmsg_t *p;
35
26
 
36
 
  fprintf(stderr, "MRA %s plugin:%s dl:%s\n",
37
 
          __func__, plugin->name.str, plugin->plugin_dl->dl.str);
38
 
 
39
27
  p= (errmsg_t *) malloc(sizeof(errmsg_t));
40
28
  if (p == NULL) return 1;
41
29
  memset(p, 0, sizeof(errmsg_t));
46
34
  {
47
35
    if (plugin->plugin->init((void *)p))
48
36
    {
49
 
      sql_print_error("Errmsg plugin '%s' init function returned error.",
50
 
                      plugin->name.str);
 
37
      /* we're doing the errmsg plugin api,
 
38
         so we can't trust the errmsg api to emit our error messages
 
39
         so we will emit error messages to stderr */
 
40
      /* TRANSLATORS: The leading word "errmsg" is the name
 
41
         of the plugin api, and so should not be translated. */
 
42
      fprintf(stderr,
 
43
              _("errmsg plugin '%s' init() failed."),
 
44
              plugin->name.str);
51
45
      goto err;
52
46
    }
53
47
  }
62
56
63
57
  errmsg_t *p = (errmsg_t *) plugin->data;
64
58
 
65
 
  fprintf(stderr, "MRA %s plugin:%s dl:%s\n",
66
 
          __func__, plugin->name.str, plugin->plugin_dl->dl.str);
67
 
 
68
59
  if (plugin->plugin->deinit)
69
60
  {
70
61
    if (plugin->plugin->deinit((void *)p))
71
62
    {
72
 
      sql_print_error("Errmsg plugin '%s' deinit function returned error.",
73
 
                      plugin->name.str);
 
63
      /* we're doing the errmsg plugin api,
 
64
         so we can't trust the errmsg api to emit our error messages
 
65
         so we will emit error messages to stderr */
 
66
      /* TRANSLATORS: The leading word "errmsg" is the name
 
67
         of the plugin api, and so should not be translated. */
 
68
      fprintf(stderr,
 
69
              _("errmsg plugin '%s' deinit() failed."),
 
70
              plugin->name.str);
74
71
    }
75
72
  }
76
73
 
79
76
  return 0;
80
77
}
81
78
 
 
79
/* The plugin_foreach() iterator requires that we
 
80
   convert all the parameters of a plugin api entry point
 
81
   into just one single void ptr, plus the thd.
 
82
   So we will take all the additional paramters of errmsg_vprintf,
 
83
   and marshall them into a struct of this type, and
 
84
   then just pass in a pointer to it.
 
85
*/
 
86
typedef struct errmsg_parms_st
 
87
{
 
88
  int priority;
 
89
  const char *format;
 
90
  va_list ap;
 
91
} errmsg_parms_t;
 
92
 
 
93
 
 
94
/* This gets called by plugin_foreach once for each loaded errmsg plugin */
82
95
static bool errmsg_iterate (THD *thd, plugin_ref plugin, void *p)
83
96
{
84
97
  errmsg_t *l= plugin_data(plugin, errmsg_t *);
87
100
  if (l && l->errmsg_func)
88
101
  {
89
102
    if (l->errmsg_func(thd, parms->priority, parms->format, parms->ap))
 
103
    {
 
104
      /* we're doing the errmsg plugin api,
 
105
         so we can't trust the errmsg api to emit our error messages
 
106
         so we will emit error messages to stderr */
 
107
      /* TRANSLATORS: The leading word "errmsg" is the name
 
108
         of the plugin api, and so should not be translated. */
 
109
      fprintf(stderr,
 
110
              _("errmsg plugin '%s' errmsg_func() failed"),
 
111
              (char *)plugin_name(plugin));
90
112
      return true;
 
113
    }
91
114
  }
92
115
  return false;
93
116
}
94
117
 
95
 
void errmsg_vprintf (THD *thd, int priority, const char *format, va_list ap)
 
118
bool errmsg_vprintf (THD *thd, int priority, const char *format, va_list ap)
96
119
{
 
120
  bool foreach_rv;
97
121
  errmsg_parms_t parms;
98
122
 
 
123
  /* marshall the parameters so they will fit into the foreach */
99
124
  parms.priority= priority;
100
125
  parms.format= format;
101
 
  parms.ap= ap;
 
126
  va_copy(parms.ap, ap);
102
127
 
103
 
  if (plugin_foreach(thd, errmsg_iterate, DRIZZLE_ERRMSG_PLUGIN,
104
 
                     (void *) &parms))
105
 
  {
106
 
    sql_print_error("Errmsg plugin had an error.");
107
 
  }
108
 
  return;
 
128
  /* call errmsg_iterate
 
129
     once for each loaded errmsg plugin */
 
130
  foreach_rv= plugin_foreach(thd,
 
131
                             errmsg_iterate,
 
132
                             DRIZZLE_ERRMSG_PLUGIN,
 
133
                             (void *) &parms);
 
134
  return foreach_rv;
109
135
}
110
136
 
111
 
void errmsg_printf (THD *thd, int priority, const char *format, ...)
 
137
bool errmsg_printf (THD *thd, int priority, const char *format, ...)
112
138
{
 
139
  bool rv;
113
140
  va_list args;
114
141
  va_start(args, format);
115
 
  errmsg_vprintf(thd, priority, format, args);
 
142
  rv= errmsg_vprintf(thd, priority, format, args);
116
143
  va_end(args);
117
 
  return;
 
144
  return rv;
118
145
}