gr-baz Package
gr_error_handler.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2005 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 /*
23  * This code is based on error.hh from the "Click Modular Router".
24  * Original copyright follows:
25  */
26 /*
27  * error.{cc,hh} -- flexible classes for error reporting
28  * Eddie Kohler
29  *
30  * Copyright (c) 1999-2000 Massachusetts Institute of Technology
31  *
32  * Permission is hereby granted, free of charge, to any person obtaining a
33  * copy of this software and associated documentation files (the "Software"),
34  * to deal in the Software without restriction, subject to the conditions
35  * listed in the Click LICENSE file. These conditions include: you must
36  * preserve this copyright notice, and you cannot mention the copyright
37  * holders in advertising related to the Software without their permission.
38  * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
39  * notice is a summary of the Click LICENSE file; the license in that file is
40  * legally binding.
41  */
42 
43 #ifndef INCLUDED_GR_ERROR_HANDLER_H
44 #define INCLUDED_GR_ERROR_HANDLER_H
45 
46 #include <gr_core_api.h>
47 #include <stdarg.h>
48 #include <string>
49 #include <cstdio> // for FILE
50 
51 /*!
52  * \brief abstract error handler
53  * \ingroup base
54  */
56 public:
57  enum seriousness {
58  ERR_DEBUG = 0x00000000,
59  ERR_MESSAGE = 0x00010000,
60  ERR_WARNING = 0x00020000,
61  ERR_ERROR = 0x00030000,
62  ERR_FATAL = 0x00040000
63  };
64 
66  virtual ~gr_error_handler();
67 
68  static gr_error_handler *default_handler();
69  static gr_error_handler *silent_handler();
70 
71  static bool has_default_handler();
72  static void set_default_handler(gr_error_handler *errh);
73 
74  void debug(const char *format, ...);
75  void message(const char *format, ...);
76  void warning(const char *format, ...);
77  void error(const char *format, ...);
78  void fatal(const char *format, ...);
79 
80  virtual int nwarnings() const = 0;
81  virtual int nerrors() const = 0;
82  virtual void reset_counts() = 0;
83 
84  void verror(seriousness s, const char *format, va_list);
85  void verror_text(seriousness s, const std::string &text);
86 
87 protected:
88  virtual void count_error(seriousness s) = 0;
89  virtual void handle_text(seriousness s, const std::string &str) = 0;
90  std::string make_text(seriousness s, const char *format, va_list);
91 };
92 
93 
95  int d_nwarnings;
96  int d_nerrors;
97 
98 public:
99  gr_base_error_handler() : d_nwarnings(0), d_nerrors(0) {}
100  int nwarnings() const { return d_nwarnings; }
101  int nerrors() const { return d_nerrors; }
102  void reset_counts() { d_nwarnings = d_nerrors = 0; }
103  void count_error(seriousness s);
104 };
105 
107  FILE *d_file;
108  int d_fd;
109 public:
110  gr_file_error_handler(FILE *file);
111  gr_file_error_handler(int file_descriptor);
113 
114  void handle_text(seriousness s, const std::string &str);
115 };
116 
117 #endif /* INCLUDED_GR_ERROR_HANDLER_H */