~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/errmsg.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

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"
21
 
#include "drizzled/plugin/error_message.h"
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/errmsg.h>
 
22
#include <drizzled/gettext.h>
22
23
#include "drizzled/plugin/registry.h"
23
24
 
24
 
#include "drizzled/gettext.h"
25
 
 
26
25
#include <vector>
27
26
 
28
27
using namespace std;
29
28
 
30
 
namespace drizzled
31
 
{
32
 
 
33
 
vector<plugin::ErrorMessage *> all_errmsg_handler;
34
 
bool errmsg_has= false;
35
 
 
36
 
 
37
 
bool plugin::ErrorMessage::addPlugin(plugin::ErrorMessage *handler)
 
29
static vector<Error_message_handler *> all_errmsg_handler;
 
30
 
 
31
static bool errmsg_has= false;
 
32
 
 
33
void add_errmsg_handler(Error_message_handler *handler)
38
34
{
39
35
  all_errmsg_handler.push_back(handler);
40
36
  errmsg_has= true;
41
 
  return false;
42
37
}
43
38
 
44
 
void plugin::ErrorMessage::removePlugin(plugin::ErrorMessage *handler)
 
39
void remove_errmsg_handler(Error_message_handler *handler)
45
40
{
46
41
  all_errmsg_handler.erase(find(all_errmsg_handler.begin(),
47
42
                                all_errmsg_handler.end(), handler));
48
43
}
49
44
 
50
45
 
51
 
class Print : public unary_function<plugin::ErrorMessage *, bool>
 
46
class ErrorMessagePrint : public unary_function<Error_message_handler *, bool>
52
47
{
53
48
  Session *session;
54
49
  int priority;
55
50
  const char *format;
56
51
  va_list ap;
57
52
public:
58
 
  Print(Session *session_arg, int priority_arg,
59
 
        const char *format_arg, va_list ap_arg)
60
 
    : unary_function<plugin::ErrorMessage *, bool>(), session(session_arg),
61
 
      priority(priority_arg), format(format_arg)
 
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)
62
57
    {
63
58
      va_copy(ap, ap_arg);
64
59
    }
65
60
 
66
 
  ~Print()  { va_end(ap); }
 
61
  ~ErrorMessagePrint()  { va_end(ap); }
67
62
 
68
63
  inline result_type operator()(argument_type handler)
69
64
  {
70
 
    va_list handler_ap;
71
 
    va_copy(handler_ap, ap);
72
 
    if (handler->errmsg(session, priority, format, handler_ap))
 
65
    if (handler->errmsg(session, priority, format, ap))
73
66
    {
74
67
      /* we're doing the errmsg plugin api,
75
68
         so we can't trust the errmsg api to emit our error messages
79
72
      fprintf(stderr,
80
73
              _("errmsg plugin '%s' errmsg() failed"),
81
74
              handler->getName().c_str());
82
 
      va_end(handler_ap);
83
75
      return true;
84
76
    }
85
 
    va_end(handler_ap);
86
77
    return false;
87
78
  }
88
 
}; 
89
 
 
90
 
 
91
 
bool plugin::ErrorMessage::vprintf(Session *session, int priority,
92
 
                                 char const *format, va_list ap)
 
79
};
 
80
 
 
81
bool errmsg_vprintf (Session *session, int priority,
 
82
                     char const *format, va_list ap)
93
83
{
94
84
 
95
85
  /* check to see if any errmsg plugin has been loaded
105
95
  }
106
96
 
107
97
  /* Use find_if instead of foreach so that we can collect return codes */
108
 
  vector<plugin::ErrorMessage *>::iterator iter=
 
98
  vector<Error_message_handler *>::iterator iter=
109
99
    find_if(all_errmsg_handler.begin(), all_errmsg_handler.end(),
110
 
            Print(session, priority, format, ap)); 
 
100
            ErrorMessagePrint(session, priority, format, ap)); 
111
101
  /* If iter is == end() here, that means that all of the plugins returned
112
102
   * false, which in this case means they all succeeded. Since we want to 
113
103
   * return false on success, we return the value of the two being != 
115
105
  return iter != all_errmsg_handler.end();
116
106
}
117
107
 
118
 
} /* namespace drizzled */
 
108