Drizzled Public API Documentation

error.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 
00021 #pragma once
00022 
00023 #include <string>
00024 #include <boost/unordered_map.hpp>
00025 
00026 #include <drizzled/common_fwd.h>
00027 #include <drizzled/definitions.h>
00028 #include <drizzled/error/priority_t.h>
00029 #include <drizzled/error_t.h>
00030 #include <drizzled/identifier.h>
00031 #include <drizzled/visibility.h>
00032 
00033 namespace drizzled {
00034 
00035 /* Max width of screen (for error messages) */
00036 #define SC_MAXWIDTH 256
00037 #define ERRMSGSIZE  (SC_MAXWIDTH) /* Max length of a error message */
00038 #define MY_FILE_ERROR ((size_t) -1)
00039 #define ME_FATALERROR   1024    /* Fatal statement error */
00040 
00041 /*
00042  * Provides a mapping from the error enum values to std::strings.
00043  */
00044 class ErrorMap : boost::noncopyable
00045 {
00046 public:
00047   typedef std::pair<std::string, std::string> value_type;
00048   typedef boost::unordered_map<error_t, value_type> ErrorMessageMap;
00049 
00050   ErrorMap();
00051 
00052   // Insert the message for the error.  If the error already has an existing
00053   // mapping, an error is logged, but the function continues.
00054   void add(error_t error_num, const std::string &error_name, const std::string &message);
00055 
00056   const std::string* find(error_t error_num) const;
00057 
00058   static const ErrorMessageMap& get_error_message_map();
00059 private:
00060   ErrorMessageMap mapping_;
00061 };
00062 
00063 typedef void (*error_handler_func)(error_t my_err,
00064                                    const char *str,
00065                                    myf MyFlags);
00066 extern error_handler_func error_handler_hook;
00067 
00068 // TODO: kill this method. Too much to do with this branch.
00069 // This is called through the ER(x) macro.
00070 DRIZZLED_API const char * error_message(error_t err_index);
00071 
00072 // Adds the message to the global error dictionary.
00073 void add_error_message(error_t error_code, const std::string &error_name,
00074                        const std::string& message);
00075 #define DRIZZLE_ADD_ERROR_MESSAGE(code, msg) add_error_message(code, STRINGIFY_ARG(code), msg)
00076 
00077 namespace error {
00078 
00079 void access(const identifier::User&);
00080 void access(const identifier::User&, const identifier::Schema&);
00081 void access(const identifier::User&, const identifier::Table&);
00082 
00083 const std::string &verbose_string();
00084 error::priority_t &verbosity();
00085 void check_verbosity(const std::string &arg);
00086 
00087 } // namespace error
00088 
00089 
00090 DRIZZLED_API void my_error(const std::string &ref, error_t nr, myf MyFlags= MYF(0));
00091 DRIZZLED_API void my_error(error_t nr, const Identifier&, myf MyFlags= MYF(0));
00092 DRIZZLED_API void my_error(error_t nr);
00093 DRIZZLED_API void my_error(error_t nr, myf MyFlags, ...);
00094 void my_message(error_t my_err, const char *str, myf MyFlags);
00095 void my_printf_error(error_t my_err, const char *format,
00096                      myf MyFlags, ...)
00097                      __attribute__((format(printf, 2, 4)));
00098 
00099 } /* namespace drizzled */
00100