~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/errmsg_notify/errmsg_notify.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

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