~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/error_message.cc

  • Committer: Brian Aker
  • Date: 2010-12-24 03:44:02 UTC
  • mfrom: (2015.1.3 timestamp)
  • mto: This revision was merged to the branch mainline in revision 2028.
  • Revision ID: brian@tangent.org-20101224034402-n1hpg1yxwjz59hpw
Finish up issues with unsigned/int by fixing cast().

Show diffs side-by-side

added added

removed removed

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