~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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
499.2.10 by Mark Atwood
add editor format hints, and other useful metadata comments
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <config.h>
2187.2.3 by Brian Aker
This cleans up the the error message system by providing for the ability to
21
22
#include <drizzled/error.h>
23
#include <drizzled/gettext.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
24
#include <drizzled/plugin/error_message.h>
971.1.46 by Monty Taylor
Made plugin registration go through Plugin_registry.
25
1502.3.1 by iwamatsu at nigauri
Add cstdio include to files needing it. Fixes the build on some debian
26
#include <cstdio>
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
27
#include <algorithm>
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
28
#include <vector>
29
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
30
namespace drizzled
31
{
32
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
33
std::vector<plugin::ErrorMessage *> all_errmsg_handler;
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
34
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
35
bool plugin::ErrorMessage::addPlugin(plugin::ErrorMessage *handler)
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
36
{
37
  all_errmsg_handler.push_back(handler);
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
38
  return false;
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
39
}
40
2139.3.11 by Brian Aker
Error log messages from Inno, most, not all are sent to the correct error
41
void plugin::ErrorMessage::removePlugin(plugin::ErrorMessage *)
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
42
{
2139.3.11 by Brian Aker
Error log messages from Inno, most, not all are sent to the correct error
43
  all_errmsg_handler.clear();
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
44
}
45
46
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
47
class Print : public std::unary_function<plugin::ErrorMessage *, bool>
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
48
{
2440.4.3 by Brian Aker
Update naming convention for priority.
49
  error::priority_t priority;
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
50
  const char *format;
51
  va_list ap;
1966.2.12 by Brian Aker
More std!
52
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
53
public:
2440.4.3 by Brian Aker
Update naming convention for priority.
54
  Print(error::priority_t priority_arg,
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
55
        const char *format_arg, va_list ap_arg) : 
1966.2.12 by Brian Aker
More std!
56
    std::unary_function<plugin::ErrorMessage *, bool>(),
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
57
    priority(priority_arg), format(format_arg)
1966.2.12 by Brian Aker
More std!
58
  {
59
    va_copy(ap, ap_arg);
60
  }
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
61
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
62
  ~Print()  { va_end(ap); }
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
63
64
  inline result_type operator()(argument_type handler)
499.2.1 by Mark Atwood
add hooks for errmsg plugin type
65
  {
1271.1.3 by Monty Taylor
va_lists need to be copied when you use them more than once.
66
    va_list handler_ap;
67
    va_copy(handler_ap, ap);
2126.3.2 by Brian Aker
Merge in removal/need for session in error message plugins.
68
    if (handler->errmsg(priority, format, handler_ap))
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
69
    {
70
      /* we're doing the errmsg plugin api,
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
71
         so we can't trust the errmsg api to emit our error messages
72
         so we will emit error messages to stderr */
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
73
      /* TRANSLATORS: The leading word "errmsg" is the name
74
         of the plugin api, and so should not be translated. */
75
      fprintf(stderr,
942.1.16 by Monty Taylor
Converted error message plugin to class.
76
              _("errmsg plugin '%s' errmsg() failed"),
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
77
              handler->getName().c_str());
1271.1.3 by Monty Taylor
va_lists need to be copied when you use them more than once.
78
      va_end(handler_ap);
2440.4.2 by Brian Aker
Fix level_t to be more inline with syslog
79
499.2.1 by Mark Atwood
add hooks for errmsg plugin type
80
      return true;
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
81
    }
1271.1.3 by Monty Taylor
va_lists need to be copied when you use them more than once.
82
    va_end(handler_ap);
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
83
    return false;
499.2.1 by Mark Atwood
add hooks for errmsg plugin type
84
  }
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
85
}; 
86
87
2440.4.3 by Brian Aker
Update naming convention for priority.
88
bool plugin::ErrorMessage::vprintf(error::priority_t priority, char const *format, va_list ap)
499.2.1 by Mark Atwood
add hooks for errmsg plugin type
89
{
2440.4.2 by Brian Aker
Fix level_t to be more inline with syslog
90
  if (priority > error::verbosity())
91
  {
2187.2.3 by Brian Aker
This cleans up the the error message system by providing for the ability to
92
    return false;
2440.4.2 by Brian Aker
Fix level_t to be more inline with syslog
93
  }
499.2.2 by Mark Atwood
va_list handing and other fixes for errmsg plugin
94
2139.3.11 by Brian Aker
Error log messages from Inno, most, not all are sent to the correct error
95
  /* 
96
    Check to see if any errmsg plugin has been loaded
97
    if not, just fall back to emitting the message to stderr.
98
  */
2440.4.2 by Brian Aker
Fix level_t to be more inline with syslog
99
  if (all_errmsg_handler.size() == 0)
602.1.1 by Mark Atwood
hook up the errmsg plugin to the sql_print_error function
100
  {
101
    /* if it turns out that the vfprintf doesnt do one single write
2440.4.2 by Brian Aker
Fix level_t to be more inline with syslog
102
      (single writes are atomic), then this needs to be rewritten to
103
      vsprintf into a char buffer, and then write() that char buffer
104
      to stderr 
105
    */
106
    vfprintf(stderr, format, ap);
107
    fputc('\n', stderr);
108
602.1.1 by Mark Atwood
hook up the errmsg plugin to the sql_print_error function
109
    return false;
110
  }
111
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
112
  /* Use find_if instead of foreach so that we can collect return codes */
1966.2.6 by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing
113
  std::vector<plugin::ErrorMessage *>::iterator iter=
1966.2.12 by Brian Aker
More std!
114
    std::find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(),
2126.3.2 by Brian Aker
Merge in removal/need for session in error message plugins.
115
                 Print(priority, format, ap)); 
2087.4.1 by Brian Aker
Merge in schema identifier.
116
968.2.36 by Monty Taylor
Removed configvar and parser plugin types. They are not being used and they are just one more type to be converted. We can/will add them back once we have a place for them to be used.
117
  /* If iter is == end() here, that means that all of the plugins returned
118
   * false, which in this case means they all succeeded. Since we want to 
119
   * return false on success, we return the value of the two being != 
120
   */
121
  return iter != all_errmsg_handler.end();
499.2.1 by Mark Atwood
add hooks for errmsg plugin type
122
}
499.2.2 by Mark Atwood
va_list handing and other fixes for errmsg plugin
123
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
124
} /* namespace drizzled */