Drizzled Public API Documentation

error.h
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 
21 #pragma once
22 
23 #include <string>
24 #include <boost/unordered_map.hpp>
25 
26 #include <drizzled/common_fwd.h>
27 #include <drizzled/definitions.h>
28 #include <drizzled/error/priority_t.h>
29 #include <drizzled/error_t.h>
30 #include <drizzled/identifier.h>
31 #include <drizzled/visibility.h>
32 
33 namespace drizzled {
34 
35 /* Max width of screen (for error messages) */
36 #define SC_MAXWIDTH 256
37 #define ERRMSGSIZE (SC_MAXWIDTH) /* Max length of a error message */
38 #define MY_FILE_ERROR ((size_t) -1)
39 #define ME_FATALERROR 1024 /* Fatal statement error */
40 
41 /*
42  * Provides a mapping from the error enum values to std::strings.
43  */
44 class ErrorMap : boost::noncopyable
45 {
46 public:
47  typedef std::pair<std::string, std::string> value_type;
48  typedef boost::unordered_map<error_t, value_type> ErrorMessageMap;
49 
50  ErrorMap();
51 
52  // Insert the message for the error. If the error already has an existing
53  // mapping, an error is logged, but the function continues.
54  void add(error_t error_num, const std::string &error_name, const std::string &message);
55 
56  const std::string* find(error_t error_num) const;
57 
58  static const ErrorMessageMap& get_error_message_map();
59 private:
60  ErrorMessageMap mapping_;
61 };
62 
63 typedef void (*error_handler_func)(error_t my_err,
64  const char *str,
65  myf MyFlags);
66 extern error_handler_func error_handler_hook;
67 
68 // TODO: kill this method. Too much to do with this branch.
69 // This is called through the ER(x) macro.
70 DRIZZLED_API const char * error_message(error_t err_index);
71 
72 // Adds the message to the global error dictionary.
73 void add_error_message(error_t error_code, const std::string &error_name,
74  const std::string& message);
75 #define DRIZZLE_ADD_ERROR_MESSAGE(code, msg) add_error_message(code, STRINGIFY_ARG(code), msg)
76 
77 namespace error {
78 
79 void access(const identifier::User&);
80 void access(const identifier::User&, const identifier::Schema&);
81 void access(const identifier::User&, const identifier::Table&);
82 
83 const std::string &verbose_string();
84 error::priority_t &verbosity();
85 void check_verbosity(const std::string &arg);
86 
87 } // namespace error
88 
89 
90 DRIZZLED_API void my_error(const std::string &ref, error_t nr, myf MyFlags= MYF(0));
91 DRIZZLED_API void my_error(error_t nr, const Identifier&, myf MyFlags= MYF(0));
92 DRIZZLED_API void my_error(error_t nr);
93 DRIZZLED_API void my_error(error_t nr, myf MyFlags, ...);
94 void my_message(error_t my_err, const char *str, myf MyFlags);
95 void my_printf_error(error_t my_err, const char *format,
96  myf MyFlags, ...)
97  __attribute__((format(printf, 2, 4)));
98 
99 } /* namespace drizzled */
100 
A set of Session members describing the current authenticated user.
Definition: user.h:34
TODO: Rename this file - func.h is stupid.
#define DRIZZLED_API
Definition: visibility.h:62
Visibility Control Macros.