w_error.h

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' incl-file-exclusion='W_ERROR_H'>
00025 
00026  $Id: w_error.h,v 1.59 2010/06/24 17:08:08 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 #ifndef W_ERROR_H
00054 #define W_ERROR_H
00055 
00056 #include "w_defines.h"
00057 
00058 /*  -- do not edit anything above this line --   </std-header>*/
00059 
00060 
00061 #ifdef __GNUG__
00062 #pragma interface
00063 #endif
00064 
00065 #include "fc_error_enum_gen.h"
00066 #include "tls.h"
00067 #include "w_base.h"
00068 
00069 #define USE_BLOCK_ALLOC_FOR_W_ERROR_T 0
00070 #if USE_BLOCK_ALLOC_FOR_W_ERROR_T
00071 DECLARE_TLS_SWATCHZ(w_error_alloc);
00072 #endif
00073 
00074 /**\brief Error code and associated string.
00075  *
00076  * used by w_error_t.
00077  */
00078 struct w_error_info_t {
00079     w_base_t::uint4_t        err_num;
00080     const char                *errstr;
00081 };
00082 
00083 
00084 /**\brief These are pushed onto a stack(list) hanging off a w_rc_t, q.v.
00085  *
00086  * \attention Not for direct use. Included in documentation only for completeness.
00087  */
00088 class w_error_t : public w_base_t {
00089 public:
00090     typedef w_error_info_t info_t;
00091     /**\brief Integer-valued error code
00092      *
00093      * The domain for this type is a set of numbers
00094      * generated by Perl scripts, and found in header files of the
00095      * form *_gen.h
00096      *
00097      */
00098     typedef uint4_t        err_num_t;
00099 
00100     // kludge: make err_num come first:
00101     const err_num_t              err_num;
00102 
00103     const char* const            file;
00104     const uint4_t                line;
00105     const int4_t                 sys_err_num;
00106 
00107     w_error_t*                   next() { return _next; }
00108     w_error_t const*             next() const { return _next; }
00109 
00110     w_error_t&                   add_trace_info(
00111         const char* const             filename,
00112         uint4_t                       line_num);
00113 
00114     w_error_t&                   clear_more_info_msg();
00115     w_error_t&                   append_more_info_msg(const char* more_info);
00116     const char*                  get_more_info_msg() const;
00117     void                         claim();
00118     void                         verify_owner() const;
00119     
00120     ostream                      &print_error(ostream &o) const;
00121 
00122 #if USE_BLOCK_ALLOC_FOR_W_ERROR_T
00123     void operator delete(void* p);
00124 #endif
00125     
00126     static w_error_t*            make(
00127         const char* const            filename,
00128         uint4_t                      line_num,
00129         err_num_t                    err_num,
00130         w_error_t*                   list = 0,
00131         const char*                  more_info = 0);
00132     static w_error_t*            make(
00133         const char* const             filename,
00134         uint4_t                       line_num,
00135         err_num_t                     err_num,
00136         uint4_t                       sys_err,
00137         w_error_t*                    list = 0,
00138         const char*                   more_info = 0);
00139 
00140     static bool                  insert(
00141         const char                    *modulename,
00142         const info_t                  info[],
00143         uint4_t                       count);
00144 
00145     static const w_error_t       no_error_instance;
00146     static w_error_t* const      no_error;
00147     static const char*           error_string(err_num_t err_num);
00148     static const char*           module_name(err_num_t err_num);
00149 
00150     NORET                        ~w_error_t();
00151 
00152 private:
00153     enum { max_range = 10, max_trace = 10 };
00154     
00155     
00156 private:
00157     const char*                  more_info_msg;
00158 
00159     friend class w_rc_t;
00160                                      
00161     uint4_t                      _trace_cnt;
00162     w_error_t*                   _next;
00163     const char*                  _trace_file[max_trace];
00164     uint4_t                      _trace_line[max_trace];
00165 #ifdef SM_THREAD_SAFE_ERRORS
00166     pthread_t                    _owner;
00167 #endif
00168 
00169     NORET                        w_error_t(
00170         const char* const            filename,
00171         uint4_t                      line_num,
00172         err_num_t                    err_num,
00173         w_error_t*                   list,
00174         const char*                  more_info);
00175     NORET                        w_error_t(
00176         const char* const             filename,
00177         uint4_t                       line_num,
00178         err_num_t                     err_num,
00179         uint4_t                       sys_err,
00180         w_error_t*                    list,
00181         const char*                    more_info);
00182 
00183     // disabled. 
00184     NORET                        w_error_t(const w_error_t&);
00185     w_error_t&                   operator=(const w_error_t&);
00186 
00187     static const info_t*         _range_start[max_range];
00188     static uint4_t               _range_cnt[max_range];
00189     static const char *          _range_name[max_range];
00190     static uint4_t               _nreg;
00191 
00192     static inline uint4_t        classify(int err_num);
00193 public:
00194         // make public so it  can be exported to client side
00195     static const info_t          error_info[];
00196     static ostream &             print(ostream &out);
00197 private:
00198     // disabled
00199     static void init_errorcodes(); 
00200 
00201 };
00202 
00203 extern ostream  &operator<<(ostream &o, const w_error_t &obj);
00204 
00205 #ifdef SM_THREAD_SAFE_ERRORS 
00206 #include <pthread.h>
00207 #include <stdlib.h>
00208 inline void w_error_t::claim() {
00209   _owner = pthread_self();
00210 }
00211 inline void w_error_t::verify_owner() const {
00212   w_assert1(pthread_equal(_owner, pthread_self()));
00213 }
00214 #else
00215 inline void w_error_t::claim() { /* do nothing */ }
00216 inline void w_error_t::verify_owner() const { /* do nothing */ }
00217 #endif
00218 
00219 inline NORET
00220 w_error_t::~w_error_t()
00221 {
00222     delete[] more_info_msg;
00223     more_info_msg = NULL;
00224     delete _next;
00225 }
00226 
00227 /*<std-footer incl-file-exclusion='W_ERROR_H'>  -- do not edit anything below this line -- */
00228 
00229 #endif          /*</std-footer>*/

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