GNU Radio 2.x: gr_error_handler.h Source File

Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

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