~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/error_message.cc

  • Committer: Brian Aker
  • Date: 2011-01-06 05:17:09 UTC
  • Revision ID: brian@tangent.org-20110106051709-oa0se8ur02uc6i9o
Added native functions into the function table.

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