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/definitions.h>
00027 #include <drizzled/error/level_t.h>
00028 #include <drizzled/error_t.h>
00029 #include <drizzled/identifier.h>
00030 #include <drizzled/visibility.h>
00031 
00032 namespace drizzled
00033 {
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
00045 {
00046 public:
00047   typedef std::pair<std::string, std::string> value_type;
00048   typedef boost::unordered_map<drizzled::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(drizzled::error_t error_num, const std::string &error_name, const std::string &message);
00055 
00056   // If there is no error mapping for the error_num, ErrorStringNotFound is raised.
00057   const std::string &find(drizzled::error_t error_num) const;
00058 
00059   static const ErrorMessageMap& get_error_message_map();
00060 private:
00061   // Disable copy and assignment.
00062   ErrorMap(const ErrorMap &e);
00063   ErrorMap& operator=(const ErrorMap &e);
00064 
00065   ErrorMessageMap mapping_;
00066 };
00067 
00068 typedef void (*error_handler_func)(drizzled::error_t my_err,
00069                                    const char *str,
00070                                    myf MyFlags);
00071 extern error_handler_func error_handler_hook;
00072 
00073 // TODO: kill this method. Too much to do with this branch.
00074 // This is called through the ER(x) macro.
00075 DRIZZLED_API const char * error_message(drizzled::error_t err_index);
00076 
00077 // Adds the message to the global error dictionary.
00078 void add_error_message(drizzled::error_t error_code, const std::string &error_name,
00079                        const std::string& message);
00080 #define DRIZZLE_ADD_ERROR_MESSAGE(code, msg) add_error_message(code, STRINGIFY_ARG(code), msg)
00081 
00082 namespace error {
00083 
00084 void access(drizzled::identifier::User::const_reference user);
00085 void access(drizzled::identifier::User::const_reference user, drizzled::identifier::Schema::const_reference schema);
00086 void access(drizzled::identifier::User::const_reference user, drizzled::identifier::Table::const_reference table);
00087 
00088 const std::string &verbose_string();
00089 error::level_t &verbosity();
00090 void check_verbosity(const std::string &arg);
00091 
00092 } // namespace error
00093 
00094 
00095 DRIZZLED_API void my_error(const std::string &ref, error_t nr, myf MyFlags= MYF(0));
00096 DRIZZLED_API void my_error(error_t nr, drizzled::Identifier::const_reference ref, myf MyFlags= MYF(0));
00097 DRIZZLED_API void my_error(error_t nr);
00098 DRIZZLED_API void my_error(error_t nr, myf MyFlags, ...);
00099 void my_message(drizzled::error_t my_err, const char *str, myf MyFlags);
00100 void my_printf_error(drizzled::error_t my_err, const char *format,
00101                      myf MyFlags, ...)
00102                      __attribute__((format(printf, 2, 4)));
00103 
00104 } /* namespace drizzled */
00105