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 |
*
|
1010
by Brian Aker
Replacing Sun employee copyright headers (aka... anything done by a Sun |
4 |
* Copyright (C) 2008 Sun Microsystems
|
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 |
||
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
20 |
#include <drizzled/server_includes.h> |
21 |
#include <drizzled/errmsg.h> |
|
549
by Monty Taylor
Took gettext.h out of header files. |
22 |
#include <drizzled/gettext.h> |
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
23 |
#include "drizzled/plugin_registry.h" |
24 |
||
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. |
25 |
#include <vector> |
26 |
||
27 |
using namespace std; |
|
28 |
||
29 |
static vector<Error_message_handler *> all_errmsg_handler; |
|
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
30 |
|
602.1.1
by Mark Atwood
hook up the errmsg plugin to the sql_print_error function |
31 |
static bool errmsg_has= false; |
32 |
||
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
33 |
void add_errmsg_handler(Error_message_handler *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. |
34 |
{
|
35 |
all_errmsg_handler.push_back(handler); |
|
971.1.51
by Monty Taylor
New-style plugin registration now works. |
36 |
errmsg_has= true; |
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. |
37 |
}
|
38 |
||
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
39 |
void remove_errmsg_handler(Error_message_handler *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. |
40 |
{
|
41 |
all_errmsg_handler.erase(find(all_errmsg_handler.begin(), |
|
42 |
all_errmsg_handler.end(), handler)); |
|
43 |
}
|
|
44 |
||
45 |
||
46 |
class ErrorMessagePrint : public unary_function<Error_message_handler *, bool> |
|
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
47 |
{
|
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. |
48 |
Session *session; |
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
49 |
int priority; |
50 |
const char *format; |
|
51 |
va_list 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. |
52 |
public: |
53 |
ErrorMessagePrint(Session *session_arg, int priority_arg, |
|
54 |
const char *format_arg, va_list ap_arg) : |
|
55 |
unary_function<Error_message_handler *, bool>(), session(session_arg), |
|
56 |
priority(priority_arg), format(format_arg) |
|
57 |
{
|
|
58 |
va_copy(ap, ap_arg); |
|
59 |
}
|
|
60 |
||
61 |
~ErrorMessagePrint() { va_end(ap); } |
|
62 |
||
63 |
inline result_type operator()(argument_type handler) |
|
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
64 |
{
|
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. |
65 |
if (handler->errmsg(session, priority, format, ap)) |
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
66 |
{
|
67 |
/* 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. |
68 |
so we can't trust the errmsg api to emit our error messages
|
69 |
so we will emit error messages to stderr */
|
|
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
70 |
/* TRANSLATORS: The leading word "errmsg" is the name
|
71 |
of the plugin api, and so should not be translated. */
|
|
72 |
fprintf(stderr, |
|
942.1.16
by Monty Taylor
Converted error message plugin to class. |
73 |
_("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. |
74 |
handler->getName().c_str()); |
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
75 |
return true; |
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
76 |
}
|
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 |
return false; |
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
78 |
}
|
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. |
79 |
};
|
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
80 |
|
942.1.16
by Monty Taylor
Converted error message plugin to class. |
81 |
bool errmsg_vprintf (Session *session, int priority, |
82 |
char const *format, va_list ap) |
|
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
83 |
{
|
499.2.2
by Mark Atwood
va_list handing and other fixes for errmsg plugin |
84 |
|
602.1.1
by Mark Atwood
hook up the errmsg plugin to the sql_print_error function |
85 |
/* check to see if any errmsg plugin has been loaded
|
86 |
if not, just fall back to emitting the message to stderr */
|
|
87 |
if (!errmsg_has) |
|
88 |
{
|
|
89 |
/* if it turns out that the vfprintf doesnt do one single write
|
|
90 |
(single writes are atomic), then this needs to be rewritten to
|
|
91 |
vsprintf into a char buffer, and then write() that char buffer
|
|
92 |
to stderr */
|
|
93 |
vfprintf(stderr, format, ap); |
|
94 |
return false; |
|
95 |
}
|
|
96 |
||
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. |
97 |
/* Use find_if instead of foreach so that we can collect return codes */
|
98 |
vector<Error_message_handler *>::iterator iter= |
|
99 |
find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(), |
|
100 |
ErrorMessagePrint(session, priority, format, ap)); |
|
101 |
/* If iter is == end() here, that means that all of the plugins returned
|
|
102 |
* false, which in this case means they all succeeded. Since we want to
|
|
103 |
* return false on success, we return the value of the two being !=
|
|
104 |
*/
|
|
105 |
return iter != all_errmsg_handler.end(); |
|
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
106 |
}
|
499.2.2
by Mark Atwood
va_list handing and other fixes for errmsg plugin |
107 |
|
722.4.1
by Mark Atwood
integrate errmsg plugin into sql_print_* functions |
108 |