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
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #ifndef SCV_DEBUG_H
00069 #define SCV_DEBUG_H
00070
00071 #include "scv/scv_config.h"
00072
00073 #include <stdio.h>
00074
00075 #include "scv/scv_object_if.h"
00076 #include "scv/scv_util.h"
00077
00078 #define _scv_trace(arg) if ((arg)) \
00079 scv_out << "_scv_trace at file " << __FILE__ << " line " << __LINE__ << " "
00080
00081
00082
00083 #define SCV_DEBUG_ON
00084
00085
00086 #ifdef SCV_DEBUG_ON
00087
00088
00089
00090 #define SCV_DEBUG(object_p, level, arg1) \
00091 if ( scv_debug::check((object_p)->get_debug(),(level)) ) \
00092 scv_debug::record_data((__FILE__), (__LINE__), (object_p), (level), (arg1))
00093
00094
00095
00096 #define SCV_DEBUG_CHECK(item, level) _scv_debug_check((item),(level))
00097
00098 #else
00099
00100 #define SCV_DEBUG(object_p, level, arg1)
00101 #define SCV_DEBUG_CHECK(object_p, level) 0
00102 #endif
00103
00104
00105 class scv_debug : public scv_object_if {
00106 public:
00107
00108
00109
00110 enum debug_facilities {
00111 ALL = 0,
00112 DATA_STRUCTURES,
00113 INTROSPECTION,
00114 MESSAGES,
00115 RANDOMIZATION,
00116 RECORDING,
00117 SIGNALS,
00118 TRANSACTORS,
00119 LAST
00120 };
00121 static const int INITIAL_DEBUG_LEVEL = -1;
00122 static const int SUSPENDED_DEBUG_LEVEL = -1;
00123
00124 private:
00125 scv_debug(const char *filename = 0);
00126
00127 public:
00128 virtual ~scv_debug();
00129
00130 public:
00131
00132
00133 static int check(int actual_level, int target_level);
00134
00135
00136 static void record_data(
00137 const char *filename,
00138 int lineno,
00139 scv_object_if *object_p,
00140 int target_level,
00141 const char *data);
00142
00143
00144 static void open_trace_file(const char *filename);
00145 static void close_trace_file();
00146
00147
00148 static void open_stdout();
00149 static void close_stdout();
00150
00151
00152 static void set_level(debug_facilities facility, int level = 0);
00153 static void set_level(const char *facility_name, int level = 0);
00154
00155
00156 static void set_facility_level(debug_facilities facility, int level = 0);
00157
00158
00159 static void resume(int facility);
00160 static void suspend(int facility);
00161
00162 static void indent(ostream& os, int indent);
00163
00164
00165 const char *get_name() const { return kind(); }
00166 const char *kind() const { return _kind; }
00167 void print(ostream& o=scv_out, int details=0, int indent=0) const;
00168 void show(int details=0, int indent=0) const { print(scv_out,details,indent); }
00169 static int get_debug() { return _debug; }
00170 static void set_debug(int);
00171
00172 private:
00173 static void set_level_for_classes(int, int);
00174
00175 private:
00176 FILE *file_p;
00177 int facility_levels[LAST];
00178 int send_to_stdout;
00179 static int _debug;
00180 static int local_origination;
00181 static scv_debug *scv_debug_p;
00182 static const char* facility_names[];
00183 static const char *_kind;
00184
00185 void send_to_log(const char *theString);
00186 };
00187
00188 template<typename T>
00189 bool _scv_debug_check(T *object_p, int target_level)
00190 { return scv_debug::check(object_p->get_debug(),target_level); }
00191
00192 inline bool _scv_debug_check(int actual_level, int target_level)
00193 { return scv_debug::check(actual_level,target_level); }
00194
00195 #endif