1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Monty Taylor
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.
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.
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
22
#include <cstdio> /* for vsnprintf */
23
#include <stdarg.h> /* for va_list */
24
#include <unistd.h> /* for write(2) */
25
#include <libnotifymm.h>
30
#include <drizzled/plugin/error_message.h>
31
#include <drizzled/gettext.h>
32
#include <drizzled/plugin.h>
33
#include <drizzled/plugin/registry.h>
36
/* todo, make this dynamic as needed */
37
#define MAX_MSG_LEN 8192
39
using namespace drizzled;
43
class Error_message_notify : public plugin::ErrorMessage
45
vector<string> errmsg_tags;
47
Error_message_notify()
48
: plugin::ErrorMessage("Error_message_notify"),
51
errmsg_tags.push_back("Unknown");
52
errmsg_tags.push_back("Debug");
53
errmsg_tags.push_back("Info");
54
errmsg_tags.push_back("Warn");
55
errmsg_tags.push_back("Error");
58
virtual bool errmsg(Session *, int priority, const char *format, va_list ap)
60
char msgbuf[MAX_MSG_LEN];
63
prv= vsnprintf(msgbuf, MAX_MSG_LEN, format, ap);
64
if (prv < 0) return true;
66
Notify::Notification n(errmsg_tags[priority].c_str(), msgbuf);
68
* @TODO: Make this timeout a system variable
72
#ifdef GLIBMM_EXCEPTIONS_ENABLED
77
auto_ptr<Glib::Error> error;
81
fprintf(stderr, _("Failed to send error message to libnotify\n"));
84
#ifdef GLIBMM_EXCEPTIONS_ENABLED
86
catch (Glib::Error& err)
88
fprintf(stderr, err.what().c_str());
97
static Error_message_notify *handler= NULL;
98
static int plugin_init(plugin::Registry ®istry)
100
Notify::init("Drizzled");
101
handler= new Error_message_notify();
102
registry.add(handler);
107
static int plugin_deinit(plugin::Registry ®istry)
112
registry.remove(handler);
118
DRIZZLE_PLUGIN(plugin_init, plugin_deinit, NULL, NULL);