00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef _SCV_REPORT_H
00041 #define _SCV_REPORT_H
00042
00043 #include "scv/scv_config.h"
00044
00045
00046 #ifdef _SCV_USE_SC_REPORT
00047
00048 typedef sc_actions scv_actions;
00049 typedef sc_report scv_report;
00050 typedef sc_report_handler scv_report_handler;
00051 typedef sc_severity scv_severity;
00052 typedef const char *scv_msg_type;
00053
00054 #define SCV_INFO SC_INFO
00055 #define SCV_WARNING SC_WARNING
00056 #define SCV_ERROR SC_ERROR
00057 #define SCV_FATAL SC_FATAL
00058
00059 #define SCV_UNSPECIFIED SC_UNSPECIFIED
00060 #define SCV_DO_NOTHING SC_DO_NOTHING
00061 #define SCV_THROW SC_THROW
00062 #define SCV_LOG SC_LOG
00063 #define SCV_DISPLAY SC_DISPLAY
00064 #define SCV_CACHE_REPORT SC_CACHE_REPORT
00065 #define SCV_INTERRUPT SC_INTERRUPT
00066 #define SCV_STOP SC_STOP
00067 #define SCV_ABORT SC_ABORT
00068
00069 #define SCV_DEFAULT_INFO_ACTIONS SC_DEFAULT_INFO_ACTIONS
00070 #define SCV_DEFAULT_WARNING_ACTIONS SC_DEFAULT_WARNING_ACTIONS
00071 #define SCV_DEFAULT_ERROR_ACTIONS SC_DEFAULT_ERROR_ACTIONS
00072 #define SCV_DEFAULT_FATAL_ACTIONS SC_DEFAULT_FATAL_ACTIONS
00073
00074 #define SCV_REPORT_INFO SC_REPORT_INFO
00075 #define SCV_REPORT_WARNING SC_REPORT_WARNING
00076 #define SCV_REPORT_ERROR SC_REPORT_ERROR
00077 #define SCV_REPORT_FATAL SC_REPORT_FATAL
00078
00079 #else
00080
00081
00082 #include <string>
00083
00084 #include "scv/scv_object_if.h"
00085 #include "scv/scv_util.h"
00086 #include "scv/scv_debug.h"
00087
00088 #ifdef set_handler
00089 # undef set_handler
00090 #endif
00091
00092 #ifdef _MSC_VER
00093 #ifdef DELETE
00094 #undef DELETE
00095 #endif
00096 #ifdef ERROR
00097 #undef ERROR
00098 #endif
00099 #endif
00100
00101
00102
00103
00104
00105
00106
00107 #define SCV_REPORT_INFO(msg_type,msg) \
00108 scv_report_handler::report(SCV_INFO,(msg_type),(msg),__FILE__,__LINE__)
00109
00110 #define SCV_REPORT_WARNING(msg_type,msg) \
00111 scv_report_handler::report(SCV_WARNING,(msg_type),(msg),__FILE__,__LINE__)
00112
00113 #define SCV_REPORT_ERROR(msg_type,msg) \
00114 scv_report_handler::report(SCV_ERROR,(msg_type),(msg),__FILE__,__LINE__)
00115
00116 #define SCV_REPORT_FATAL(msg_type,msg) \
00117 scv_report_handler::report(SCV_FATAL,(msg_type),(msg),__FILE__,__LINE__)
00118
00119
00120 enum scv_severity {
00121 SCV_INFO = 0,
00122 SCV_WARNING,
00123 SCV_ERROR,
00124 SCV_FATAL
00125 };
00126
00127
00128 typedef unsigned scv_actions;
00129
00130 const scv_actions SCV_UNSPECIFIED = 0x0000;
00131 const scv_actions SCV_DO_NOTHING = 0x0001;
00132 const scv_actions SCV_THROW = 0x0002;
00133 const scv_actions SCV_LOG = 0x0004;
00134 const scv_actions SCV_DISPLAY = 0x0008;
00135 const scv_actions SCV_CACHE_REPORT = 0x0010;
00136 const scv_actions SCV_INTERRUPT = 0x0020;
00137 const scv_actions SCV_STOP = 0x0040;
00138 const scv_actions SCV_ABORT = 0x0080;
00139
00140
00141 typedef const char *scv_msg_type;
00142
00143
00144 class scv_report : public scv_object_if {
00145 public:
00146
00147 scv_report(
00148 scv_severity severity, scv_msg_type msg_type,
00149 const char *msg,
00150 const char *file_name, int line_number,
00151 sc_time time, const char *_process_name
00152 );
00153
00154 scv_report(const scv_report&);
00155
00156 virtual ~scv_report() {}
00157
00158 scv_report& operator=(const scv_report&);
00159
00160
00161 operator const char *() const;
00162
00163 scv_severity get_severity() const
00164 { return _severity; }
00165 scv_msg_type get_msg_type() const
00166 { return _msg_type.c_str(); }
00167 const char *get_msg() const
00168 { return _msg.c_str(); }
00169 const char *get_file_name() const
00170 { return _file_name.c_str(); }
00171 int get_line_number() const
00172 { return _line_number; }
00173
00174 sc_time get_time() const
00175 { return _time; }
00176 const char *get_process_name() const
00177 { return _process_name.c_str(); }
00178
00179 const char *get_name() const
00180 { return _msg_type.c_str(); }
00181 const char *kind() const
00182 { return _kind; }
00183 void print(ostream& o=cout, int details=0, int indent=0) const;
00184
00185 private:
00186
00187 scv_severity _severity;
00188 string _msg_type;
00189 string _msg;
00190 string _file_name;
00191 int _line_number;
00192 sc_time _time;
00193 string _process_name;
00194
00195 static const char *_kind;
00196 };
00197
00198
00199 class scv_report_handler {
00200 public:
00201
00202 scv_report_handler() {}
00203 virtual ~scv_report_handler() {}
00204
00205
00206
00207
00208
00209
00210
00211 static void set_handler(
00212 void (*handler)(const scv_report&, const scv_actions&) = 0
00213 );
00214
00215
00216
00217 static scv_actions set_actions(
00218 scv_severity severity,
00219 scv_actions actions = SCV_UNSPECIFIED
00220 );
00221 static scv_actions set_actions(
00222 scv_msg_type msg_type,
00223 scv_actions actions = SCV_UNSPECIFIED
00224 );
00225 static scv_actions set_actions(
00226 scv_msg_type msg_type, scv_severity severity,
00227 scv_actions actions = SCV_UNSPECIFIED
00228 );
00229
00230
00231
00232 static int stop_after(
00233 scv_severity severity,
00234 int limit = -1
00235 );
00236 static int stop_after(
00237 scv_msg_type msg_type,
00238 int limit = -1
00239 );
00240 static int stop_after(
00241 scv_msg_type msg_type, scv_severity severity,
00242 int limit = -1
00243 );
00244
00245
00246 static scv_actions suppress(scv_actions actions = 0U);
00247 static scv_actions force(scv_actions actions = 0U);
00248
00249
00250 static void register_cb(void (*f)(const scv_report *));
00251
00252
00253 static scv_actions get_new_action_id();
00254
00255
00256 static const char *get_log_file_name();
00257 static void set_log_file_name(const char *name);
00258
00259
00260 static int get_debug() { return _debug; }
00261 static void set_debug(int debug) { _debug = debug; }
00262
00263
00264
00265
00266
00267
00268 static void report(
00269 scv_severity severity, scv_msg_type msg_type,
00270 const char *msg,
00271 const char *file_name, int line_number
00272 );
00273
00274
00275 static void default_handler(const scv_report&, const scv_actions&);
00276
00277 static const scv_report *get_cached_report();
00278 static void clear_cached_report();
00279
00280 private:
00281
00282
00283 static void initialize();
00284
00285 static int _debug;
00286 };
00287
00288
00289 const scv_actions SCV_DEFAULT_INFO_ACTIONS
00290 = SCV_LOG | SCV_DISPLAY;
00291 const scv_actions SCV_DEFAULT_WARNING_ACTIONS
00292 = SCV_LOG | SCV_DISPLAY;
00293 const scv_actions SCV_DEFAULT_ERROR_ACTIONS
00294 = SCV_LOG | SCV_DISPLAY | SCV_CACHE_REPORT | SCV_THROW;
00295 const scv_actions SCV_DEFAULT_FATAL_ACTIONS
00296 = SCV_LOG | SCV_DISPLAY | SCV_CACHE_REPORT | SCV_THROW;
00297
00298
00299 #endif // ! _SCV_USE_SC_REPORT
00300
00301
00302
00303
00304
00305
00306
00307 class _scv_message_desc {
00308 public:
00309 _scv_message_desc(
00310 string tag, string format, scv_severity severity, scv_actions actions
00311 ) : _tag(tag), _format(format), _severity(severity), _actions(actions) {}
00312 const char *get_tag() const { return _tag.c_str(); }
00313 const char *get_format() const { return _format.c_str(); }
00314 scv_severity get_severity() const { return _severity; }
00315 unsigned get_actions() const { return _actions; }
00316 private:
00317 string _tag;
00318 string _format;
00319 scv_severity _severity;
00320 scv_actions _actions;
00321 };
00322
00323
00324 class _scv_message {
00325 friend class scv_report_core;
00326 public:
00327
00328 enum severity_level { INFO, WARNING, ERROR, FATAL };
00329
00330 enum response_level {
00331 NONE_SPECIFIED, ENABLE_MESSAGE, SUPPRESS_MESSAGE
00332 };
00333
00334
00335 #define _SCV_DEFERR(code, number, string, severity, actions) \
00336 static _scv_message_desc *code##_base; \
00337 static _scv_message_desc **code;
00338 #include "scv/scv_messages.h"
00339 #undef _SCV_DEFERR
00340
00341
00342 static void message(_scv_message_desc **desc_pp, ... );
00343 static scv_severity xlat_severity(severity_level severity);
00344
00345 private:
00346 static void setup();
00347 };
00348
00349
00350 #endif // ! _SCV_REPORT_H