~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/error_message.cc

  • Committer: Brian Aker
  • Date: 2011-02-12 08:20:19 UTC
  • mto: This revision was merged to the branch mainline in revision 2161.
  • Revision ID: brian@tangent.org-20110212082019-09gs5y1b0pxoaesb
Merge in optimizer pieces.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
{
31
31
 
32
32
std::vector<plugin::ErrorMessage *> all_errmsg_handler;
33
 
bool errmsg_has= false;
34
 
 
35
33
 
36
34
bool plugin::ErrorMessage::addPlugin(plugin::ErrorMessage *handler)
37
35
{
38
36
  all_errmsg_handler.push_back(handler);
39
 
  errmsg_has= true;
40
37
  return false;
41
38
}
42
39
 
43
 
void plugin::ErrorMessage::removePlugin(plugin::ErrorMessage *handler)
 
40
void plugin::ErrorMessage::removePlugin(plugin::ErrorMessage *)
44
41
{
45
 
  all_errmsg_handler.erase(std::find(all_errmsg_handler.begin(),
46
 
                                     all_errmsg_handler.end(), handler));
 
42
  all_errmsg_handler.clear();
47
43
}
48
44
 
49
45
 
50
46
class Print : public std::unary_function<plugin::ErrorMessage *, bool>
51
47
{
52
 
  Session *session;
53
 
  int priority;
 
48
  error::level_t priority;
54
49
  const char *format;
55
50
  va_list ap;
56
51
 
57
52
public:
58
 
  Print(Session *session_arg, int priority_arg,
 
53
  Print(error::level_t priority_arg,
59
54
        const char *format_arg, va_list ap_arg) : 
60
55
    std::unary_function<plugin::ErrorMessage *, bool>(),
61
 
    session(session_arg),
62
56
    priority(priority_arg), format(format_arg)
63
57
  {
64
58
    va_copy(ap, ap_arg);
70
64
  {
71
65
    va_list handler_ap;
72
66
    va_copy(handler_ap, ap);
73
 
    if (handler->errmsg(session, priority, format, handler_ap))
 
67
    if (handler->errmsg(priority, format, handler_ap))
74
68
    {
75
69
      /* we're doing the errmsg plugin api,
76
70
         so we can't trust the errmsg api to emit our error messages
89
83
}; 
90
84
 
91
85
 
92
 
bool plugin::ErrorMessage::vprintf(Session *session, int priority,
93
 
                                   char const *format, va_list ap)
 
86
bool plugin::ErrorMessage::vprintf(error::level_t priority, char const *format, va_list ap)
94
87
{
95
88
 
96
 
  /* check to see if any errmsg plugin has been loaded
97
 
     if not, just fall back to emitting the message to stderr */
98
 
  if (!errmsg_has)
 
89
  /* 
 
90
    Check to see if any errmsg plugin has been loaded
 
91
    if not, just fall back to emitting the message to stderr.
 
92
  */
 
93
  if (not all_errmsg_handler.size())
99
94
  {
100
95
    /* if it turns out that the vfprintf doesnt do one single write
101
96
       (single writes are atomic), then this needs to be rewritten to
102
97
       vsprintf into a char buffer, and then write() that char buffer
103
98
       to stderr */
104
99
    vfprintf(stderr, format, ap);
 
100
    fputc('\n', stderr);
105
101
    return false;
106
102
  }
107
103
 
108
104
  /* Use find_if instead of foreach so that we can collect return codes */
109
105
  std::vector<plugin::ErrorMessage *>::iterator iter=
110
106
    std::find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(),
111
 
                 Print(session, priority, format, ap)); 
 
107
                 Print(priority, format, ap)); 
112
108
 
113
109
  /* If iter is == end() here, that means that all of the plugins returned
114
110
   * false, which in this case means they all succeeded. Since we want to