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 #include "w_defines.h"
00054
00055
00056
00057 #ifdef __GNUC__
00058 #pragma implementation "w_rc.h"
00059 #endif
00060
00061 #define W_SOURCE
00062 #include <w_base.h>
00063
00064 #include <pthread.h>
00065 #include <vector>
00066 #include <sstream>
00067
00068 bool w_rc_t::do_check = true;
00069
00070 bool w_rc_t::unchecked_is_fatal = true;
00071
00072 const w_rc_t w_rc_t::rc_ok(w_error_t::no_error);
00073
00074 void
00075 w_rc_t::set_return_check(bool on_off, bool is_fatal)
00076 {
00077 do_check = on_off;
00078 unchecked_is_fatal = is_fatal;
00079 }
00080
00081 NORET
00082 w_rc_t::w_rc_t(
00083 const char* const filename,
00084 w_base_t::uint4_t line_num,
00085 w_rc_t::errcode_t err_num)
00086 : _err( w_error_t::make(filename, line_num, err_num) )
00087 {
00088 set_unchecked();
00089 }
00090
00091 NORET
00092 w_rc_t::w_rc_t(
00093 const char* const filename,
00094 w_base_t::uint4_t line_num,
00095 w_rc_t::errcode_t err_num,
00096 w_base_t::int4_t sys_err)
00097 : _err( w_error_t::make(filename, line_num, err_num, sys_err) )
00098 {
00099 set_unchecked();
00100 }
00101
00102 w_rc_t&
00103 w_rc_t::push(
00104 const char* const filename,
00105 w_base_t::uint4_t line_num,
00106 w_rc_t::errcode_t err_num)
00107 {
00108 _err = w_error_t::make(filename, line_num,
00109 err_num, ptr());
00110 set_unchecked();
00111 return *this;
00112 }
00113
00114 void
00115 w_rc_t::fatal()
00116 {
00117 stringstream s;
00118 s << *this << endl;
00119 fprintf(stderr, "FATAL ERROR: %s\n", s.str().c_str());
00120 w_base_t::abort();
00121 }
00122
00123 w_rc_t&
00124 w_rc_t::add_trace_info(
00125 const char* const filename,
00126 w_base_t::uint4_t line_num)
00127 {
00128 ptr()->add_trace_info(filename, line_num);
00129 set_unchecked();
00130 return *this;
00131 }
00132
00133 void
00134 w_rc_t::error_not_checked()
00135 {
00136 cerr << "Error not checked: rc=" << (*this) << endl;
00137 if(unchecked_is_fatal)
00138 W_FATAL(fcINTERNAL);
00139 }
00140
00141 ostream&
00142 operator<<(
00143 ostream& o,
00144 const w_rc_t& obj)
00145 {
00146 return o << *obj;
00147 }
00148
00149
00150
00151 w_error_t *w_rc_t::_clone() const
00152 {
00153
00154 w_assert2( ptr() != w_error_t::no_error );
00155
00156
00157
00158 std::vector<w_error_t const*> trace;
00159 w_rc_i it(*this);
00160 while(w_error_t const* e = it.next()) {
00161 #if W_DEBUG_LEVEL > 2
00162 (void) e->get_more_info_msg();
00163 #endif
00164 trace.push_back(e);
00165 }
00166
00167 w_error_t* head = 0;
00168 while(!trace.empty()) {
00169 w_error_t const* e = trace.back();
00170 trace.pop_back();
00171
00172 head = w_error_t::make(e->file, e->line, e->err_num, e->sys_err_num, head);
00173
00174 for(unsigned int t=0; t<e->_trace_cnt; t++) {
00175 head->_trace_file[t] = e->_trace_file[t];
00176 head->_trace_line[t] = e->_trace_line[t];
00177 }
00178 head->_trace_cnt = e->_trace_cnt;
00179
00180 head->clear_more_info_msg();
00181 const char *c=e->get_more_info_msg();
00182 if(c) head->append_more_info_msg(c);
00183 }
00184
00185 return head;
00186 }