GNU Radio 3.6.5 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2005 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 /* 00023 * This code is based on error.hh from the "Click Modular Router". 00024 * Original copyright follows: 00025 */ 00026 /* 00027 * error.{cc,hh} -- flexible classes for error reporting 00028 * Eddie Kohler 00029 * 00030 * Copyright (c) 1999-2000 Massachusetts Institute of Technology 00031 * 00032 * Permission is hereby granted, free of charge, to any person obtaining a 00033 * copy of this software and associated documentation files (the "Software"), 00034 * to deal in the Software without restriction, subject to the conditions 00035 * listed in the Click LICENSE file. These conditions include: you must 00036 * preserve this copyright notice, and you cannot mention the copyright 00037 * holders in advertising related to the Software without their permission. 00038 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This 00039 * notice is a summary of the Click LICENSE file; the license in that file is 00040 * legally binding. 00041 */ 00042 00043 #ifndef INCLUDED_GR_ERROR_HANDLER_H 00044 #define INCLUDED_GR_ERROR_HANDLER_H 00045 00046 #include <gr_core_api.h> 00047 #include <stdarg.h> 00048 #include <string> 00049 #include <cstdio> // for FILE 00050 00051 /*! 00052 * \brief abstract error handler 00053 * \ingroup base 00054 */ 00055 class GR_CORE_API gr_error_handler { 00056 public: 00057 enum seriousness { 00058 ERR_DEBUG = 0x00000000, 00059 ERR_MESSAGE = 0x00010000, 00060 ERR_WARNING = 0x00020000, 00061 ERR_ERROR = 0x00030000, 00062 ERR_FATAL = 0x00040000 00063 }; 00064 00065 gr_error_handler() {} 00066 virtual ~gr_error_handler(); 00067 00068 static gr_error_handler *default_handler(); 00069 static gr_error_handler *silent_handler(); 00070 00071 static bool has_default_handler(); 00072 static void set_default_handler(gr_error_handler *errh); 00073 00074 void debug(const char *format, ...); 00075 void message(const char *format, ...); 00076 void warning(const char *format, ...); 00077 void error(const char *format, ...); 00078 void fatal(const char *format, ...); 00079 00080 virtual int nwarnings() const = 0; 00081 virtual int nerrors() const = 0; 00082 virtual void reset_counts() = 0; 00083 00084 void verror(seriousness s, const char *format, va_list); 00085 void verror_text(seriousness s, const std::string &text); 00086 00087 protected: 00088 virtual void count_error(seriousness s) = 0; 00089 virtual void handle_text(seriousness s, const std::string &str) = 0; 00090 std::string make_text(seriousness s, const char *format, va_list); 00091 }; 00092 00093 00094 class GR_CORE_API gr_base_error_handler : public gr_error_handler { 00095 int d_nwarnings; 00096 int d_nerrors; 00097 00098 public: 00099 gr_base_error_handler() : d_nwarnings(0), d_nerrors(0) {} 00100 int nwarnings() const { return d_nwarnings; } 00101 int nerrors() const { return d_nerrors; } 00102 void reset_counts() { d_nwarnings = d_nerrors = 0; } 00103 void count_error(seriousness s); 00104 }; 00105 00106 class GR_CORE_API gr_file_error_handler : public gr_base_error_handler { 00107 FILE *d_file; 00108 int d_fd; 00109 public: 00110 gr_file_error_handler(FILE *file); 00111 gr_file_error_handler(int file_descriptor); 00112 ~gr_file_error_handler(); 00113 00114 void handle_text(seriousness s, const std::string &str); 00115 }; 00116 00117 #endif /* INCLUDED_GR_ERROR_HANDLER_H */