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.28 2010/05/26 01:20:25 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 #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; // default is on but it does nothing
00069 // if W_DEBUG_RC is not defined.
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 // The result of a clone will be used to initialize
00150 // w_rc_t in a copy operator.
00151 w_error_t *w_rc_t::_clone() const 
00152 {
00153     // w_rc_t::clone() should enforce this
00154     w_assert2( ptr() != w_error_t::no_error );
00155 
00156     // need a deep copy
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(); // Just for assertion checking
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         // creates a new w_error_t that points to head, returns the new one
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 }

Generated on Wed Jul 7 17:22:32 2010 for Shore Storage Manager by  doxygen 1.4.7