w_rc.cpp

00001 /* -*- mode:C++; c-basic-offset:4 -*-
00002      Shore-MT -- Multi-threaded port of the SHORE storage manager
00003    
00004                        Copyright (c) 2007-2009
00005       Data Intensive Applications and Systems Labaratory (DIAS)
00006                Ecole Polytechnique Federale de Lausanne
00007    
00008                          All Rights Reserved.
00009    
00010    Permission to use, copy, modify and distribute this software and
00011    its documentation is hereby granted, provided that both the
00012    copyright notice and this permission notice appear in all copies of
00013    the software, derivative works or modified versions, and any
00014    portions thereof, and that both notices appear in supporting
00015    documentation.
00016    
00017    This code is distributed in the hope that it will be useful, but
00018    WITHOUT ANY WARRANTY; without even the implied warranty of
00019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
00020    DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
00021    RESULTING FROM THE USE OF THIS SOFTWARE.
00022 */
00023 
00024 /*<std-header orig-src='shore'>
00025 
00026  $Id: w_rc.cpp,v 1.30 2010/12/09 15:20:12 nhall Exp $
00027 
00028 SHORE -- Scalable Heterogeneous Object REpository
00029 
00030 Copyright (c) 1994-99 Computer Sciences Department, University of
00031                       Wisconsin -- Madison
00032 All Rights Reserved.
00033 
00034 Permission to use, copy, modify and distribute this software and its
00035 documentation is hereby granted, provided that both the copyright
00036 notice and this permission notice appear in all copies of the
00037 software, derivative works or modified versions, and any portions
00038 thereof, and that both notices appear in supporting documentation.
00039 
00040 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
00041 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
00042 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
00043 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00044 
00045 This software was developed with support by the Advanced Research
00046 Project Agency, ARPA order number 018 (formerly 8230), monitored by
00047 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
00048 Further funding for this work was provided by DARPA through
00049 Rome Research Laboratory Contract No. F30602-97-2-0247.
00050 
00051 */
00052 
00053 #include "w_defines.h"
00054 
00055 /*  -- do not edit anything above this line --   </std-header>*/
00056 
00057 #ifdef __GNUC__
00058 #pragma implementation "w_rc.h"
00059 #endif
00060 
00061 #include <w_base.h>
00062 #include <vector>
00063 #include <sstream>
00064 
00065 bool w_rc_t::do_check = true; // default is on but it does nothing
00066 // if W_DEBUG_RC is not defined.
00067 bool w_rc_t::unchecked_is_fatal = true; 
00068 
00069 const w_rc_t w_rc_t::rc_ok(w_error_t::no_error);
00070 
00071 void
00072 w_rc_t::set_return_check(bool on_off, bool is_fatal)
00073 {
00074     do_check = on_off;
00075     unchecked_is_fatal = is_fatal;
00076 }
00077 
00078 NORET
00079 w_rc_t::w_rc_t(
00080     const char* const    filename,
00081     w_base_t::uint4_t    line_num,
00082     w_rc_t::errcode_t    err_num)
00083     : _err( w_error_t::make(filename, line_num, err_num) )
00084 {
00085   set_unchecked();
00086 }
00087 
00088 NORET
00089 w_rc_t::w_rc_t(
00090     const char* const    filename,
00091     w_base_t::uint4_t    line_num,
00092     w_rc_t::errcode_t    err_num,
00093     w_base_t::int4_t     sys_err)
00094 : _err( w_error_t::make(filename, line_num, err_num, sys_err) )
00095 {
00096   set_unchecked();
00097 }
00098 
00099 w_rc_t&
00100 w_rc_t::push(
00101     const char* const    filename,
00102     w_base_t::uint4_t    line_num,
00103     w_rc_t::errcode_t    err_num)
00104 {
00105     _err = w_error_t::make(filename, line_num,
00106                    err_num, ptr());
00107     set_unchecked();
00108     return *this;
00109 }
00110 
00111 void
00112 w_rc_t::fatal()
00113 {
00114     stringstream s;
00115     s << *this << endl;
00116     fprintf(stderr, "FATAL ERROR: %s\n", s.str().c_str());
00117     w_base_t::abort();
00118 }
00119 
00120 w_rc_t&
00121 w_rc_t::add_trace_info(
00122     const char* const   filename,
00123     w_base_t::uint4_t   line_num)
00124 {
00125     ptr()->add_trace_info(filename, line_num);
00126     set_unchecked();
00127     return *this;
00128 }
00129 
00130 void 
00131 w_rc_t::error_not_checked()
00132 {
00133     cerr << "Error not checked: rc=" << (*this) << endl;
00134     if(unchecked_is_fatal)
00135         W_FATAL(fcINTERNAL);
00136 }
00137 
00138 ostream&
00139 operator<<(
00140     ostream&            o,
00141     const w_rc_t&       obj)
00142 {
00143     return o << *obj;
00144 }
00145 
00146 // The result of a clone will be used to initialize
00147 // w_rc_t in a copy operator.
00148 w_error_t *w_rc_t::_clone() const 
00149 {
00150     // w_rc_t::clone() should enforce this
00151     w_assert2( ptr() != w_error_t::no_error );
00152 
00153     // need a deep copy
00154 
00155     std::vector<w_error_t const*> trace;
00156     w_rc_i it(*this);
00157     while(w_error_t const* e = it.next()) {
00158 #if W_DEBUG_LEVEL > 2
00159         (void) e->get_more_info_msg(); // Just for assertion checking
00160 #endif
00161         trace.push_back(e);
00162     }
00163 
00164     w_error_t* head = 0;
00165     while(!trace.empty()) {
00166         w_error_t const* e = trace.back();
00167         trace.pop_back();
00168         // creates a new w_error_t that points to head, returns the new one
00169         head = w_error_t::make(e->file, e->line, e->err_num, e->sys_err_num, head);
00170 
00171         for(unsigned int t=0; t<e->_trace_cnt; t++) {
00172             head->_trace_file[t] = e->_trace_file[t];
00173             head->_trace_line[t] = e->_trace_line[t];
00174         }
00175         head->_trace_cnt = e->_trace_cnt;
00176 
00177         head->clear_more_info_msg();
00178         const char *c=e->get_more_info_msg();
00179         if(c) head->append_more_info_msg(c);
00180     }
00181 
00182     return head;
00183 }

Generated on Thu Dec 9 08:42:27 2010 for Shore Storage Manager by  doxygen 1.4.7