~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
 *
499.2.10 by Mark Atwood
add editor format hints, and other useful metadata comments
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
 */
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
19
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
20
#include "config.h"
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
21
#include <drizzled/plugin/error_message.h>
549 by Monty Taylor
Took gettext.h out of header files.
22
#include <drizzled/gettext.h>
1237.9.6 by Padraig O'Sullivan
Resolved some conflicts that appeared after merging with trunk.
23
#include <drizzled/plugin.h>
24
#include <drizzled/plugin/registry.h>
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
25
26
#include <stdio.h>  /* for vsnprintf */
27
#include <stdarg.h>  /* for va_list */
28
#include <unistd.h>  /* for write(2) */
29
499.2.10 by Mark Atwood
add editor format hints, and other useful metadata comments
30
/* todo, make this dynamic as needed */
499.2.7 by Mark Atwood
some bugs in errmsg plugin
31
#define MAX_MSG_LEN 8192
32
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
33
class Error_message_stderr : public drizzled::plugin::ErrorMessage
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
34
{
942.1.16 by Monty Taylor
Converted error message plugin to class.
35
public:
1228.1.9 by Monty Taylor
Replication and error messages.
36
  Error_message_stderr()
37
   : drizzled::plugin::ErrorMessage("Error_message_stderr") {}
942.1.16 by Monty Taylor
Converted error message plugin to class.
38
  virtual bool errmsg(Session *, int , const char *format, va_list ap)
39
  {
40
    char msgbuf[MAX_MSG_LEN];
41
    int prv, wrv;
42
43
    prv= vsnprintf(msgbuf, MAX_MSG_LEN, format, ap);
44
    if (prv < 0) return true;
45
46
    /* a single write has a OS level thread lock
47
       so there is no need to have mutexes guarding this write,
48
    */
49
    wrv= write(2, msgbuf, prv);
50
    if ((wrv < 0) || (wrv != prv)) return true;
51
52
    return false;
53
  }
54
};
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
55
971.1.51 by Monty Taylor
New-style plugin registration now works.
56
static Error_message_stderr *handler= NULL;
1110.1.5 by Monty Taylor
Renamed PluginRegistry to plugin::Registry.
57
static int errmsg_stderr_plugin_init(drizzled::plugin::Registry &registry)
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
58
{
971.1.51 by Monty Taylor
New-style plugin registration now works.
59
  handler= new Error_message_stderr();
1130.1.8 by Monty Taylor
Added polymorphic add/remove methods around slot add/remove methods.
60
  registry.add(handler);
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
61
62
  return 0;
63
}
64
1110.1.5 by Monty Taylor
Renamed PluginRegistry to plugin::Registry.
65
static int errmsg_stderr_plugin_deinit(drizzled::plugin::Registry &registry)
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
66
{
67
942.1.16 by Monty Taylor
Converted error message plugin to class.
68
  if (handler)
971.1.52 by Monty Taylor
Did the finalizers. Renamed plugin_registry.
69
  {
1130.1.8 by Monty Taylor
Added polymorphic add/remove methods around slot add/remove methods.
70
    registry.remove(handler);
942.1.16 by Monty Taylor
Converted error message plugin to class.
71
    delete handler;
971.1.52 by Monty Taylor
Did the finalizers. Renamed plugin_registry.
72
  }
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
73
  return 0;
74
}
75
1228.1.5 by Monty Taylor
Merged in some naming things.
76
DRIZZLE_DECLARE_PLUGIN
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
77
{
1241.10.2 by Monty Taylor
Added support for embedding the drizzle version number in the plugin file.
78
  DRIZZLE_VERSION_ID,
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
79
  "errmsg_stderr",
80
  "0.1",
81
  "Mark Atwood <mark@fallenpegasus.com>",
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
82
  N_("Error Messages to stderr"),
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
83
  PLUGIN_LICENSE_GPL,
84
  errmsg_stderr_plugin_init,
85
  errmsg_stderr_plugin_deinit,
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
86
  NULL, /* status variables */
87
  NULL, /* system variables */
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
88
  NULL
89
}
1228.1.5 by Monty Taylor
Merged in some naming things.
90
DRIZZLE_DECLARE_PLUGIN_END;