~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/error.h

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
 
20
 
20
21
#ifndef DRIZZLED_ERROR_H
21
22
#define DRIZZLED_ERROR_H
22
23
 
23
24
#include <string>
24
 
#include "drizzled/definitions.h"
 
25
#include <boost/unordered_map.hpp>
 
26
 
 
27
#include <drizzled/definitions.h>
 
28
#include <drizzled/error/level_t.h>
 
29
#include <drizzled/error_t.h>
 
30
#include <drizzled/identifier.h>
 
31
#include <drizzled/visibility.h>
25
32
 
26
33
namespace drizzled
27
34
{
29
36
/* Max width of screen (for error messages) */
30
37
#define SC_MAXWIDTH 256
31
38
#define ERRMSGSIZE      (SC_MAXWIDTH)   /* Max length of a error message */
32
 
#define NRERRBUFFS      (2)     /* Buffers for parameters */
33
39
#define MY_FILE_ERROR   ((size_t) -1)
34
40
#define ME_FATALERROR   1024    /* Fatal statement error */
35
41
 
36
 
typedef void (*error_handler_func)(uint32_t my_err,
 
42
/*
 
43
 * Provides a mapping from the error enum values to std::strings.
 
44
 */
 
45
class ErrorMap
 
46
{
 
47
public:
 
48
  typedef std::pair<std::string, std::string> value_type;
 
49
  typedef boost::unordered_map<drizzled::error_t, value_type> ErrorMessageMap;
 
50
 
 
51
  ErrorMap();
 
52
 
 
53
  // Insert the message for the error.  If the error already has an existing
 
54
  // mapping, an error is logged, but the function continues.
 
55
  void add(drizzled::error_t error_num, const std::string &error_name, const std::string &message);
 
56
 
 
57
  // If there is no error mapping for the error_num, ErrorStringNotFound is raised.
 
58
  const std::string &find(drizzled::error_t error_num) const;
 
59
 
 
60
  static const ErrorMessageMap& get_error_message_map();
 
61
private:
 
62
  // Disable copy and assignment.
 
63
  ErrorMap(const ErrorMap &e);
 
64
  ErrorMap& operator=(const ErrorMap &e);
 
65
 
 
66
  ErrorMessageMap mapping_;
 
67
};
 
68
 
 
69
typedef void (*error_handler_func)(drizzled::error_t my_err,
37
70
                                   const char *str,
38
71
                                   myf MyFlags);
39
72
extern error_handler_func error_handler_hook;
40
73
 
41
74
// TODO: kill this method. Too much to do with this branch.
42
75
// This is called through the ER(x) macro.
43
 
const char * error_message(unsigned int err_index);
 
76
DRIZZLED_API const char * error_message(drizzled::error_t err_index);
44
77
 
45
78
// Adds the message to the global error dictionary.
46
 
void add_error_message(uint32_t error_code, std::string const& message);
47
 
 
48
 
void my_error(int nr, myf MyFlags, ...);
49
 
void my_message(uint32_t my_err, const char *str, myf MyFlags);
50
 
void my_printf_error(uint32_t my_err, const char *format,
 
79
void add_error_message(drizzled::error_t error_code, const std::string &error_name,
 
80
                       const std::string& message);
 
81
#define DRIZZLE_ADD_ERROR_MESSAGE(code, msg) add_error_message(code, STRINGIFY_ARG(code), msg)
 
82
 
 
83
namespace error {
 
84
 
 
85
void access(drizzled::identifier::User::const_reference user);
 
86
void access(drizzled::identifier::User::const_reference user, drizzled::identifier::Schema::const_reference schema);
 
87
void access(drizzled::identifier::User::const_reference user, drizzled::identifier::Table::const_reference table);
 
88
 
 
89
const std::string &verbose_string();
 
90
error::level_t &verbosity();
 
91
void check_verbosity(const std::string &arg);
 
92
 
 
93
} // namespace error
 
94
 
 
95
 
 
96
DRIZZLED_API void my_error(const std::string &ref, error_t nr, myf MyFlags= MYF(0));
 
97
DRIZZLED_API void my_error(error_t nr, drizzled::Identifier::const_reference ref, myf MyFlags= MYF(0));
 
98
DRIZZLED_API void my_error(error_t nr);
 
99
DRIZZLED_API void my_error(error_t nr, myf MyFlags, ...);
 
100
void my_message(drizzled::error_t my_err, const char *str, myf MyFlags);
 
101
void my_printf_error(drizzled::error_t my_err, const char *format,
51
102
                     myf MyFlags, ...)
52
103
                     __attribute__((format(printf, 2, 4)));
53
104