gr_error_handler.h

Go to the documentation of this file.
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 <stdarg.h>
00047 #include <string>
00048 
00053 class gr_error_handler {
00054 public:
00055   enum seriousness {
00056     ERR_DEBUG           = 0x00000000,
00057     ERR_MESSAGE         = 0x00010000,
00058     ERR_WARNING         = 0x00020000,
00059     ERR_ERROR           = 0x00030000,
00060     ERR_FATAL           = 0x00040000
00061   };
00062 
00063   gr_error_handler() {}
00064   virtual ~gr_error_handler();
00065 
00066   static gr_error_handler *default_handler();
00067   static gr_error_handler *silent_handler();
00068 
00069   static bool has_default_handler();
00070   static void set_default_handler(gr_error_handler *errh);
00071 
00072   void debug(const char *format, ...);
00073   void message(const char *format, ...);
00074   void warning(const char *format, ...);
00075   void error(const char *format, ...);
00076   void fatal(const char *format, ...);
00077 
00078   virtual int nwarnings() const = 0;
00079   virtual int nerrors() const = 0;
00080   virtual void reset_counts() = 0;
00081 
00082   void verror(seriousness s, const char *format, va_list);
00083   void verror_text(seriousness s, const std::string &text);
00084 
00085 protected:
00086   virtual void count_error(seriousness s) = 0;
00087   virtual void handle_text(seriousness s, const std::string &str) = 0;
00088   std::string make_text(seriousness s, const char *format, va_list);
00089 };
00090 
00091 
00092 class gr_base_error_handler : public gr_error_handler {
00093   int   d_nwarnings;
00094   int   d_nerrors;
00095 
00096 public:
00097   gr_base_error_handler() : d_nwarnings(0), d_nerrors(0) {}
00098   int nwarnings() const { return d_nwarnings; }
00099   int nerrors() const   { return d_nerrors; }
00100   void reset_counts()   { d_nwarnings = d_nerrors = 0; }
00101   void count_error(seriousness s);
00102 };
00103 
00104 class gr_file_error_handler : public gr_base_error_handler {
00105   FILE          *d_file;
00106   int            d_fd;
00107 public:
00108   gr_file_error_handler(FILE *file);
00109   gr_file_error_handler(int file_descriptor);
00110   ~gr_file_error_handler();
00111 
00112   void handle_text(seriousness s, const std::string &str);
00113 };
00114 
00115 #endif /* INCLUDED_GR_ERROR_HANDLER_H */

Generated on Thu Mar 5 09:01:10 2009 for GNU Radio 3.1.3 by  doxygen 1.5.8