~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/errmsg_notify/errmsg_notify.cc

  • Committer: lbieber
  • Date: 2010-10-02 04:02:25 UTC
  • mfrom: (1806.1.1 build)
  • Revision ID: lbieber@orisndriz08-20101002040225-w8mn2h0nh5587a6f
Merge Andrew: fix bug 652966 - Drizzledump migration code doesn't handle YEAR type

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) 2010 Monty Taylor
 
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
 
 
20
#include "config.h"
 
21
 
 
22
#include <cstdio>  /* for vsnprintf */
 
23
#include <stdarg.h>  /* for va_list */
 
24
#include <unistd.h>  /* for write(2) */
 
25
#include <libnotifymm.h>
 
26
 
 
27
#include <string>
 
28
#include <vector>
 
29
 
 
30
#include <drizzled/plugin/error_message.h>
 
31
#include <drizzled/gettext.h>
 
32
#include <drizzled/plugin.h>
 
33
 
 
34
 
 
35
/* todo, make this dynamic as needed */
 
36
#define MAX_MSG_LEN 8192
 
37
 
 
38
using namespace drizzled;
 
39
using namespace std;
 
40
 
 
41
 
 
42
class Error_message_notify : public plugin::ErrorMessage
 
43
{
 
44
  vector<string> errmsg_tags;
 
45
public:
 
46
  Error_message_notify()
 
47
   : plugin::ErrorMessage("Error_message_notify"),
 
48
     errmsg_tags()
 
49
  {
 
50
    errmsg_tags.push_back("Unknown");
 
51
    errmsg_tags.push_back("Debug");
 
52
    errmsg_tags.push_back("Info");
 
53
    errmsg_tags.push_back("Warn");
 
54
    errmsg_tags.push_back("Error");
 
55
  }
 
56
 
 
57
  virtual bool errmsg(Session *, int priority, const char *format, va_list ap)
 
58
  {
 
59
    char msgbuf[MAX_MSG_LEN];
 
60
    int prv;
 
61
 
 
62
    prv= vsnprintf(msgbuf, MAX_MSG_LEN, format, ap);
 
63
    if (prv < 0) return true;
 
64
 
 
65
    Notify::Notification n(errmsg_tags[priority].c_str(), msgbuf);
 
66
    /**
 
67
     * @TODO: Make this timeout a system variable
 
68
     */
 
69
    n.set_timeout(3000);
 
70
 
 
71
#ifdef GLIBMM_EXCEPTIONS_ENABLED
 
72
    try
 
73
    {
 
74
      if (!n.show())
 
75
#else
 
76
      auto_ptr<Glib::Error> error;
 
77
      if (!n.show(error))
 
78
#endif
 
79
      {
 
80
        fprintf(stderr, _("Failed to send error message to libnotify\n"));
 
81
        return true;
 
82
      }
 
83
#ifdef GLIBMM_EXCEPTIONS_ENABLED
 
84
     }
 
85
     catch (Glib::Error& err)
 
86
     {
 
87
        fprintf(stderr, err.what().c_str());
 
88
     }
 
89
#endif
 
90
 
 
91
  return false;
 
92
  
 
93
  }
 
94
};
 
95
 
 
96
static Error_message_notify *handler= NULL;
 
97
static int plugin_init(module::Context &context)
 
98
{
 
99
  Notify::init("Drizzled");
 
100
  handler= new Error_message_notify();
 
101
  context.add(handler);
 
102
 
 
103
  return 0;
 
104
}
 
105
 
 
106
DRIZZLE_PLUGIN(plugin_init, NULL, NULL);