From 2422bdef687ec0a011ed5fbc12df5187676f2033 Mon Sep 17 00:00:00 2001 From: Elisabetta Ronchieri Date: Wed, 21 Jul 2004 18:16:57 +0000 Subject: [PATCH] Moved out exception from org.glite.wms.common/src/utilitiesY --- org.glite.wms-utils.exception/Makefile.am | 64 ++++++ org.glite.wms-utils.exception/bootstrap | 9 + org.glite.wms-utils.exception/build.xml | 100 +++++++++ org.glite.wms-utils.exception/configure.ac | 95 ++++++++ .../interface/Makefile.am | 15 ++ .../glite/wmsutils/exception/Exceptions.h | 165 ++++++++++++++ .../glite/wmsutils/exception/exception_codes.h | 47 ++++ .../glite/wmsutils/exception/result_codes.h | 54 +++++ .../project/build.properties | 0 .../project/configure.properties.xml | 9 + .../project/properties.xml | 67 ++++++ .../project/version.properties | 3 + org.glite.wms-utils.exception/src/Exceptions.cpp | 171 ++++++++++++++ org.glite.wms-utils.exception/src/Makefile.am | 26 +++ org.glite.wms-utils.exception/src/utils.cpp | 249 +++++++++++++++++++++ org.glite.wms-utils.exception/src/utils.h | 86 +++++++ 16 files changed, 1160 insertions(+) create mode 100755 org.glite.wms-utils.exception/Makefile.am create mode 100755 org.glite.wms-utils.exception/bootstrap create mode 100755 org.glite.wms-utils.exception/build.xml create mode 100755 org.glite.wms-utils.exception/configure.ac create mode 100755 org.glite.wms-utils.exception/interface/Makefile.am create mode 100755 org.glite.wms-utils.exception/interface/glite/wmsutils/exception/Exceptions.h create mode 100755 org.glite.wms-utils.exception/interface/glite/wmsutils/exception/exception_codes.h create mode 100755 org.glite.wms-utils.exception/interface/glite/wmsutils/exception/result_codes.h create mode 100755 org.glite.wms-utils.exception/project/build.properties create mode 100644 org.glite.wms-utils.exception/project/configure.properties.xml create mode 100755 org.glite.wms-utils.exception/project/properties.xml create mode 100755 org.glite.wms-utils.exception/project/version.properties create mode 100755 org.glite.wms-utils.exception/src/Exceptions.cpp create mode 100755 org.glite.wms-utils.exception/src/Makefile.am create mode 100755 org.glite.wms-utils.exception/src/utils.cpp create mode 100755 org.glite.wms-utils.exception/src/utils.h diff --git a/org.glite.wms-utils.exception/Makefile.am b/org.glite.wms-utils.exception/Makefile.am new file mode 100755 index 0000000..5e30d1b --- /dev/null +++ b/org.glite.wms-utils.exception/Makefile.am @@ -0,0 +1,64 @@ +## ********************************************************************* +## * +## * Copyright (c) 2002 CERN and INFN on behalf of the EU DataGrid. +## * For license conditions see LICENSE file or +## * http://www.edg.org/license.html +## * +## ********************************************************************* + +## Process this file with automake to produce Makefile.in + +## Subdirectories list +SUBDIRS = src + +## Default flags to run aclocal +ACLOCAL_AMFLAGS = -I project + +stage: + @set fnord $(MAKEFLAGS); amf=$$2; \ + dot_seen=no; \ + target="install"; \ + prefix_arg="@prefix@"; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target $$prefix_arg in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target $$prefix_arg) \ + || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" $$prefix_arg || exit 1; \ + fi; test -z "$$fail" + +distsrc: dist + mv $(distdir).tar.gz $(DISTTAR)/$(distdir)_src.tar.gz + +distbin: + @set fnord $(MAKEFLAGS); amf=$$2; \ + dot_seen=no; \ + target="install"; \ + tmpdistbin="$(WORKDIR)/dist_bin"; \ + prefix_arg="prefix=$$tmpdistbin"; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target $$prefix_arg in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target $$prefix_arg) \ + || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" $$prefix_arg || exit 1; \ + fi; test -z "$$fail"; \ + pushd $$tmpdistbin; \ + $(AMTAR) -zcf $(DISTTAR)/$(distdir)_bin.tar.gz .; \ + popd; \ + rm -rf $$tmpdistbin + diff --git a/org.glite.wms-utils.exception/bootstrap b/org.glite.wms-utils.exception/bootstrap new file mode 100755 index 0000000..ceeb099 --- /dev/null +++ b/org.glite.wms-utils.exception/bootstrap @@ -0,0 +1,9 @@ +#! /bin/sh + +mkdir -p src/autogen +set -x +aclocal -I project +libtoolize --force +autoheader +automake --foreign --add-missing --copy +autoconf diff --git a/org.glite.wms-utils.exception/build.xml b/org.glite.wms-utils.exception/build.xml new file mode 100755 index 0000000..4061536 --- /dev/null +++ b/org.glite.wms-utils.exception/build.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.glite.wms-utils.exception/configure.ac b/org.glite.wms-utils.exception/configure.ac new file mode 100755 index 0000000..86623ca --- /dev/null +++ b/org.glite.wms-utils.exception/configure.ac @@ -0,0 +1,95 @@ +# +# Copyright (c) 2004 on behalf of the EU EGEE Project: +# The European Organization for Nuclear Research (CERN), +# Istituto Nazionale di Fisica Nucleare (INFN), Italy +# Datamat Spa, Italy +# Centre National de la Recherche Scientifique (CNRS), France +# CS Systeme d'Information (CSSI), France +# Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden +# Universiteit van Amsterdam (UvA), Netherlands +# University of Helsinki (UH.HIP), Finland +# University of Bergen (UiB), Norway +# Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom +# +# Common configure.ac file for the GLite WMS Common module +# +# Authors: Alberto Di Meglio +# Version info: $Id$ +# Release: $Name$ +# +# Revision history: +# $Log$ +# +# + +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.57) +AC_INIT([GLite WMS Utils Exception], [0.0.0]) +AC_CONFIG_AUX_DIR([./project]) +AM_INIT_AUTOMAKE([1.6.3 subdir-objects]) +AC_CONFIG_SRCDIR([src/cjobid.h]) + +# Notices. +AC_COPYRIGHT([Copyright (c) 2004 The EU EGEE Project +See LICENCE file for details +]) +AC_REVISION([$Revision$]) + +#Environment. +WORKDIR=`pwd` +AC_SUBST(WORKDIR) + +# Checks for programs. +AC_PROG_CC +AC_PROG_CPP +AC_PROG_CXX +AC_PROG_CXXCPP +AM_PROG_CC_C_O +AC_PROG_LIBTOOL + +# Checks for libraries. + +# Checks for header files. +AC_CHECK_HEADERS([fcntl.h mntent.h sys/vfs.h syslog.h unistd.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_HEADER_STDBOOL +AC_C_CONST +AC_C_INLINE +AC_TYPE_OFF_T +AC_TYPE_SIZE_T +AC_CHECK_MEMBERS([struct stat.st_rdev]) +AC_TYPE_UID_T +AC_CHECK_TYPES([ptrdiff_t]) + +# Checks for library functions. +AC_HEADER_STDC +AC_FUNC_ERROR_AT_LINE +AC_FUNC_GETMNTENT +AC_FUNC_MEMCMP +AC_FUNC_STAT +AC_FUNC_STRFTIME +AC_FUNC_VPRINTF +AC_CHECK_FUNCS([bzero endpwent ftruncate getmntent memset mkdir pow strerror strtol]) + +have_globus=no + +AC_GLOBUS([], have_globus=yes, have_globus=no) +AC_MSG_RESULT(["GLOBUS found $have_globus"]) + +#have_glite_wmsutils_exception=no + +AC_GLITE + +#AC_GLITE_WMSUTILS_EXCEPTION([], have_glite_wmsutils_exception=yes, have_glite_wmsutils_exception=no) +#AC_MSG_RESULT(["GLITE_WMSUTILS_EXCEPTION found $have_glite_wmsutils_exception"]) + +# Configuration items +AC_PREFIX_DEFAULT([/opt/glite]) +AM_CONFIG_HEADER([src/autogen/config.h]) +AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([src/Makefile]) +AC_CONFIG_FILES([interface/Makefile]) + +AC_OUTPUT diff --git a/org.glite.wms-utils.exception/interface/Makefile.am b/org.glite.wms-utils.exception/interface/Makefile.am new file mode 100755 index 0000000..5f552a2 --- /dev/null +++ b/org.glite.wms-utils.exception/interface/Makefile.am @@ -0,0 +1,15 @@ +## ********************************************************************* +## * +## * Copyright (c) 2002 CERN and INFN on behalf of the EU DataGrid. +## * For license conditions see LICENSE file or +## * http://www.edg.org/license.html +## * +## ********************************************************************* + +exceptiondir = $(includedir) +nobase_exception_HEADERS = \ + glite/wmsutils/exception/exception_codes.h \ + glite/wmsutils/exception/Exceptions.h \ + glite/wmsutils/exception/result_codes.h + +MAINTAINERCLEANFILES = Makefile.in diff --git a/org.glite.wms-utils.exception/interface/glite/wmsutils/exception/Exceptions.h b/org.glite.wms-utils.exception/interface/glite/wmsutils/exception/Exceptions.h new file mode 100755 index 0000000..30ada55 --- /dev/null +++ b/org.glite.wms-utils.exception/interface/glite/wmsutils/exception/Exceptions.h @@ -0,0 +1,165 @@ +#ifndef GLITE_WMSUTILS_EXCEPTION_EXCEPTIONS_H +#define GLITE_WMSUTILS_EXCEPTION_EXCEPTIONS_H + +/* + * Exceptions.h + * Copyright (c) 2001 The European Datagrid Project - IST programme, all rights reserved. + * Contributors are mentioned in the code where appropriate. + */ + +#include +#include +//#include +#include // For logging exceptions to log file +#include // list the exception codes +#include +#include // base ancestor + +#include "glite/wmsutils/exception/result_codes.h" //base result codes + +namespace glite { +namespace wmsutils { +namespace exception { + +extern pthread_mutex_t METHOD_MUTEX; // used in order to store info into a file (rather then syslog) +#define EDG_STACK_TRY(method_name) std::string METHOD = method_name ; try { +#define EDG_STACK_CATCH() } catch (glite::wms::common::utilities::Exception &exc){ throw glite::wms::common::utilities::Exception ( __FILE__ , METHOD , &exc) ; } + +/** + * The Exception classes contains attributes into which are placed exception information and provides + * constructors that beyond the error code take parameters specifying the source file and line number + * (e.g. through __FILE__ and __LINE__) where the error has been generated and string messages, + * allowing an easy way of storing the origin of the exception. + * Moreover it provides methods for getting all the exception information and for logging them either + * in a log file or to the syslog daemon. + * Each of the derived types may contain its private attributes describing the actual error instance in detail. + * For example a JdlSyntaxException thrown when parsing the job description could contain additional + * details indicating exactly on which attributes the error occurred. + * Moreover each exception has an attribute representing the exception identifier that is set by the + * class constructor and allows the identification of the original exception. + * + * @ingroup Common + * @version 0.1 + * @date 15 April 2002 + * @author Alessandro Maraschini +*/ + +class Exception : public std::exception{ + public: + Exception ( const std::string& source, + const std::string& method, + Exception *e); + /** + * Constructor Update all mandatory fields + * @param code the code representing the thrown exception + * @param exception the name of the thrown exception + * @param method the name of the method that raised the exception + * @param source The source that raised the exception (could be the file path, the class Name, etc etc) + * @param line_number the number of the line in the file that raised the exception(if the source has been given as a file) */ + + Exception ( const std::string& source, + const std::string& method, + int code, + const std::string& exception); + + /** + * Constructor Update all mandatory fields + * @param source the path of the file that raised the exception + * @param line_number the number of the line in the file that raised the exception + * @param method the name of the method that raised the exception + * @param code the code representing the thrown exception + * @param exception the name of the thrown exception */ + Exception (const std::string& source, + int line_number, + const std::string& method, + int code, + const std::string& exception); + + /** + * Destructor + */ + virtual ~Exception() throw (); + /** + * Return a string debug message containing information about Exception thrown + */ + virtual std::string dbgMessage(); + /** + * Return the Code number + */ + virtual int getCode(); + + /** + * return the Error Message associated to the Exception + */ + virtual const char* what() const throw (); + + /** + * Print Exception error information into a log file + */ + virtual void log(const std::string& logfile = ""); + /** + * Return the name of the Exception raised + */ + virtual std::string getExceptionName(); + + /** + * Return the list of methods that caused the Exception + */ + virtual std::string printStackTrace() ; + + protected: + /** + * Empty Default Constructor + */ + Exception(); + //Mandatory Information: + int error_code; + std::string error_message ; + int line; + std::string source_file; + std::string exception_name; + std::string method_name ; + std::string stack; + std::string ancestor ; + // Exception* exc ; +}; //End Exception Class + +/** + * This Exception is thrown when a unespected fatal error is found + */ +class FatalErrorException : public Exception { +public: + FatalErrorException(const std::string& file, + int line, + const std::string& method); +};//End CLass FatalErrorException + +/** + * StdException remap the Exception thrown by std::exception class into the JSUI WL standard format + */ +class StdException : public Exception { +public: + StdException(const std::string& file, + int line, + const std::string& method, + int code, + const std::string& exception_name); +};//End CLass StdException + +/** + * StdException remap the Exception thrown by std::exception class into the JSUI WL standard format + */ +class ThreadException : public Exception { +public: + ThreadException(const std::string& file, + int line, + const std::string& method, + int code, + int jobNumber); +};//End CLass StdException + +} // exception namespace +} // wmsutils namespace +} // glite namespace + +#endif diff --git a/org.glite.wms-utils.exception/interface/glite/wmsutils/exception/exception_codes.h b/org.glite.wms-utils.exception/interface/glite/wmsutils/exception/exception_codes.h new file mode 100755 index 0000000..e784833 --- /dev/null +++ b/org.glite.wms-utils.exception/interface/glite/wmsutils/exception/exception_codes.h @@ -0,0 +1,47 @@ +#ifndef GLITE_WMSUTILS_EXCEPTION_CODES_H +#define GLITE_WMSUTILS_EXCEPTION_CODES_H + +// pure C-style code: +#define GLITE_WMS_COMMON_ERROR_BASE 900 +#define GLITE_WMS_USERINTERFACE_ERROR_BASE 1000 +#define GLITE_WMS_NETWORKSERVER_ERROR_BASE 1200 +#define GLITE_WMS_SOCKET_ERROR_BASE 1300 +#define GLITE_WMS_LDAP_ERROR_BASE 1350 +#define GLITE_WMS_LOGGING_ERROR_BASE 1400 +#define GLITE_WMS_REQUESTAD_ERROR_BASE 1500 +#define GLITE_WMS_CHECKPOINT_ERROR_BASE 1600 +#define GLITE_WMS_CONFIGURATION_ERROR_BASE 1800 + +#ifdef __cplusplus + +namespace glite { +namespace wmsutils { +namespace exception { + +/** + * The Error Code +*/ +enum { + WMS_COMMON_BASE = GLITE_WMS_COMMON_ERROR_BASE, + THREAD_INIT , // pthread_attr_init method failed + THREAD_DETACH , // pthread_attr_setdetachstate method failed + THREAD_CREATE , // pthread_create method failed + THREAD_JOIN, + THREAD_SSL, + WMS_FATAL_ERROR, + WMS_UI_ERROR_BASE = GLITE_WMS_USERINTERFACE_ERROR_BASE, + WMS_NS_ERROR_BASE = GLITE_WMS_NETWORKSERVER_ERROR_BASE, + WMS_SOCKET_ERROR_BASE = GLITE_WMS_SOCKET_ERROR_BASE, + WMS_LDAP_ERROR_BASE = GLITE_WMS_LDAP_ERROR_BASE, + WMS_LB_ERROR_BASE = GLITE_WMS_LOGGING_ERROR_BASE , + WMS_REQUESTAD_ERROR_BASE = GLITE_WMS_REQUESTAD_ERROR_BASE, + WMS_CHKPT_ERROR_BASE = GLITE_WMS_CHECKPOINT_ERROR_BASE, + WMS_CONFIGURATION_ERROR_BASE = GLITE_WMS_CONFIGURATION_ERROR_BASE +}; + +} // exception namespace +} // wmsutils namespace +} // glite namespace + +#endif //ifdef c++ +#endif diff --git a/org.glite.wms-utils.exception/interface/glite/wmsutils/exception/result_codes.h b/org.glite.wms-utils.exception/interface/glite/wmsutils/exception/result_codes.h new file mode 100755 index 0000000..ace9326 --- /dev/null +++ b/org.glite.wms-utils.exception/interface/glite/wmsutils/exception/result_codes.h @@ -0,0 +1,54 @@ +#ifndef GLITE_WMSUTILS_EXCEPTION_RESULT_CODES_H +#define GLITE_WMSUTILS_EXCEPTION_RESULT_CODES_H + +namespace glite { +namespace wmsutils { +namespace exception { +/* + * exception_codes.h + * Copyright (c) 2001 The European Datagrid Project - IST programme, all rights reserved. + * Contributors are mentioned in the code where appropriate. + */ + + +/** + * Result Code +*/ +enum ResultCode { + SUCCESS, // The requested operation has been completed successfully + ACCEPTED, // The requested operation has been accepted + + SUBMISSION_FAILURE, // API failed, general RB Exc remapping + CANCEL_FAILURE, // API failed, general RB Exc remapping + GETOUTPUT_FAILURE, // API failed, general RB Exc remapping + STATUS_FAILURE, // API failed, general RB Exc remapping + + GETOUTPUT_FORBIDDEN, //When trying to retrieve output from a not submitted job + CANCEL_FORBIDDEN, //When trying to cancel a not submitted job + STATUS_FORBIDDEN, //When trying to retrieve status from a not submitted job + ALREADY_SUBMITTED, //submit skipped because Job has been already submitted + + JOIN_FAILED, //When a pthread_join is waiting for a cored thread + + OUTPUT_NOT_READY, //JobNotDoneException + FILE_TRANSFER_ERROR, //SandboxIOException + JOB_NOT_FOUND, //JobNotFoundException + + MARKED_FOR_REMOVAL, //Cancel Method Result + GENERIC_FAILURE, //Cancel Method Result + CONDOR_FAILURE, //Cancel Method Result + + GLOBUS_JOBMANAGER_FAILURE, + + JOB_ALREADY_DONE, + JOB_ABORTED, + JOB_CANCELLING, + JOB_NOT_OWNER + +}; + +} // exception namespace +} // wmsutils namespace +} // glite namespace + +#endif diff --git a/org.glite.wms-utils.exception/project/build.properties b/org.glite.wms-utils.exception/project/build.properties new file mode 100755 index 0000000..e69de29 diff --git a/org.glite.wms-utils.exception/project/configure.properties.xml b/org.glite.wms-utils.exception/project/configure.properties.xml new file mode 100644 index 0000000..c813e7d --- /dev/null +++ b/org.glite.wms-utils.exception/project/configure.properties.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/org.glite.wms-utils.exception/project/properties.xml b/org.glite.wms-utils.exception/project/properties.xml new file mode 100755 index 0000000..7f6e118 --- /dev/null +++ b/org.glite.wms-utils.exception/project/properties.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.glite.wms-utils.exception/project/version.properties b/org.glite.wms-utils.exception/project/version.properties new file mode 100755 index 0000000..c2a4b32 --- /dev/null +++ b/org.glite.wms-utils.exception/project/version.properties @@ -0,0 +1,3 @@ +module.version=0.0.0 +module.build=0 +module.age=0 \ No newline at end of file diff --git a/org.glite.wms-utils.exception/src/Exceptions.cpp b/org.glite.wms-utils.exception/src/Exceptions.cpp new file mode 100755 index 0000000..30a19cc --- /dev/null +++ b/org.glite.wms-utils.exception/src/Exceptions.cpp @@ -0,0 +1,171 @@ +/* ************************************************************************** +* filename : Exceptions.cpp +* author : Alessandro Maraschini +* copyright : (C) 2002 by DATAMAT +***************************************************************************/ + +#include "glite/wmsutils/exception/Exceptions.h" +#include "glite/wmsutils/exception/exception_codes.h" +#include "utils.h" + +namespace glite { +namespace wmsutils { +namespace exception { + +using namespace std ; +using namespace glite::wmsutils::exception ; + +pthread_mutex_t METHOD_MUTEX ; // This mutex is used in order to lock the file for writing log infornation +/* ********************************* +* Exception Class Implementation +************************************/ +//Constructor/Destructor + +Exception::Exception () { + //exc = NULL ; + stack= ""; + line = 0; +} ; + +Exception::~Exception() throw(){ } +/** +* Exception chainig +*/ +Exception::Exception ( const string& source, + const string& method, + Exception *e){ + source_file = source ; + method_name = method; + error_message = ""; + stack= e->printStackTrace(); + ancestor = e->what() ; + line = 0; + error_code= 0; +}; +Exception::Exception( const std::string& file, + int line_number, + const std::string& method, + int code, + const std::string& name) + : error_code(code), exception_name(name){ + source_file = file; + line = line_number; + method_name = method; + stack= ""; +}; +Exception::Exception (const string& source, + const string& method, + int code, + const string& exception) + : error_code(code), exception_name(exception){ + source_file = source; + method_name = method; + stack= ""; + line = 0; +}; +int Exception::getCode(){ + if (error_code != 0) + return error_code ; + else + return WMS_COMMON_BASE; +}; +const char* Exception::what() const throw(){ + if (!ancestor.empty() ) + return ancestor.c_str() ; + if ( error_message != "") + return error_message.c_str() ; + else + return "" ; + +}; +string Exception::getExceptionName(){ + if (exception_name!= "") + return exception_name; + else + return "" ; +}; +void Exception::log(const std::string& logfile) +{ + if ( logfile == "") + syslog ( LOG_PERROR, (char *) (dbgMessage()).c_str() ); + else{ + pthread_mutex_lock( &METHOD_MUTEX); // LOCK + //TBD : test if file exist-->>Create HEADER ?? + ofstream fout ((char *) logfile.c_str() , ios::app ); //Open the file for writing (if it doesn't exist then it will be created) + fout << "\n" << dbgMessage() ; //write (append) the message + fout.close(); //close the file + pthread_mutex_unlock( &METHOD_MUTEX); // UNLOCK + } +}; +string Exception::printStackTrace(){ +return stack + "\n" + dbgMessage(); +}; +string Exception::dbgMessage(){ + // cout << "\nDBM callded for :" << this; + string result ; + //Adding exception Name + if ( exception_name!="") + result = exception_name ; + //Adding error msg + if (error_message!="") + result +=": " + string(what()); + if (result != "") + result+="\n"; + //Adding Source + result +=" at " + source_file ; + //Adding line number + if (line!=0) + result += " Line: " + inTo(line); + result +=" " ; + //Adding Method Name + if (method_name != "") + result += "Method: " +method_name ; + return result; +} +FatalErrorException::FatalErrorException(const std::string& file, + int line, + const std::string& method) + : Exception(file, line, method, WMS_FATAL_ERROR, "FatalErrorException") +{ + error_message = "Fatal Error found: system is unable to continue"; +} +StdException::StdException(const std::string& file, + int line, + const std::string& method, + int code, + const std::string& exception_name) + : Exception(file, line, method, code, "StdException") +{ + error_message = "std::exception Fatal Error thrown: " + exception_name; +} +ThreadException::ThreadException(const std::string& file, + int line, + const std::string& method, + int code, + int jobNumber) + : Exception(file, line, method, code, "ThreadException") +{ + + switch (code){ + case THREAD_INIT: + error_message = "pthread_attr_init"; + break; + case THREAD_DETACH : + error_message = "pthread_attr_setdetachstate"; + break; + case THREAD_SSL : + error_message = "SSL multi thread procedure"; + break; + case THREAD_CREATE : + error_message = "pthread_create"; + break; + default: //THREAD_JOIN + error_message = "pthread_join"; + break; + } + error_message += "pthread Fatal Error thrown for: " + error_message ; +} + +} // exception namespace +} // wmsutils namespace +} // glite namespace diff --git a/org.glite.wms-utils.exception/src/Makefile.am b/org.glite.wms-utils.exception/src/Makefile.am new file mode 100755 index 0000000..7ad6672 --- /dev/null +++ b/org.glite.wms-utils.exception/src/Makefile.am @@ -0,0 +1,26 @@ +## ********************************************************************* +## * +## * Copyright (c) 2002 CERN and INFN on behalf of the EU DataGrid. +## * For license conditions see LICENSE file or +## * http://www.edg.org/license.html +## * +## ********************************************************************* + +lib_LTLIBRARIES = libglite_wms_exceptions.la + +libglite_wms_exceptions_la_SOURCES = \ + Exceptions.cpp \ + utils.cpp + +utilitiesincludedir = $(includedir)/glite/wmsutils/exception +utilitiesinclude_HEADERS = \ + utils.h + +AM_CPPFLAGS = -I$(top_srcdir)/interface \ + -I$(top_srcdir)/src \ + $(GLOBUS_THR_CFLAGS) \ + $(BOOST_CFLAGS) \ + $(CLASSAD_CFLAGS) \ + -DB_THREAD_SAFE + +MAINTAINERCLEANFILES = Makefile.in *.*~ diff --git a/org.glite.wms-utils.exception/src/utils.cpp b/org.glite.wms-utils.exception/src/utils.cpp new file mode 100755 index 0000000..75016ac --- /dev/null +++ b/org.glite.wms-utils.exception/src/utils.cpp @@ -0,0 +1,249 @@ +/* ************************************************************************** +* filename : utils.cpp +* author : Alessandro Maraschini +* copyright : (C) 2002 by DATAMAT +***************************************************************************/ +#include "utils.h" +#include +#include + +using namespace std; + +namespace glite { +namespace wmsutils { +namespace exception { + +/****************************************************************** + method : isInt + field: integer & string class + check if str is an integer +*******************************************************************/ +int isInt (const string& str) +{ + int len, bCode,eCode; + char code ; + const char * strCh ; + len = str.size() ; + strCh = str.c_str(); + bCode= '0'; + eCode= '9'; + for (int i=0; ieCode) ) //It's not a digit number + return 1; + } + return 0; +} + + +/****************************************************************** + methods : toInt , toHex + field: integer & string class + Converts a string str to an Integer value sum + returns 0/1 ---> success/failure + STRING--->INTEGER +*******************************************************************/ +int toHex (const string& str,int &sum) +{ + int len, bCode,eCode,dec=1; + char code ; + const char * strCh ; + + len = str.size() ; + strCh = str.c_str(); + bCode= '0'; + eCode= '9'; + sum=0; + for (int i=0; i= bCode) && (code <=eCode) ){ //It's a digit number + sum = sum + dec * (code-bCode) ; + //cout << dec <<" Int added\n" ; + } + else if ( (code >= 'A') && (code <= 'F') ){ //It's a hex allowed char + sum = sum + dec * (code- 'A' +10) ; + //cout << dec << " Hex Added\n" ; + } + else { + return 1; + //cout << sum << " Azz Added\n" ; + } + } + return 0; + +}; + +int toInt (const string& str,int &sum) +{ + int len, bCode,eCode,dec=1; + char code ; + const char * strCh ; + + len = str.size() ; + strCh = str.c_str(); + bCode= '0'; + eCode= '9'; + sum=0; + for (int i=0; ieCode) ) //It's not a digit number + return 1; + else + sum = sum + dec * (code-bCode) ; + } + return 0; +} +/****************************************************************** + method : inTo + field: integer & string class + Converts an integer to a string + INTEGER --->STRING +*******************************************************************/ +string inTo(const int number){ + char buffer [CHAR_BUFFER_SIZE] ; + sprintf (buffer, "%i" , number) ; + return std::string(buffer); +}; + +/****************************************************************** + method : count + field: string class + Counts number of sub-string occurrences in str +*******************************************************************/ +int count(const string& strMain,const string& sep){ + int n=0,found ; + int l; + //string str=strMain ; + l = sep.length(); + found = strMain.find(sep) ; + while (found!= -1){ + found = strMain.find(sep , found + l) ; + ++n ; + } + return n ; +}; + +/****************************************************************** + method : split + field: string class + Splits a string into a vector of substring + maxLenght: max dimension of vector (the last item of the vector will be the lasting part) + trough: if trough == 1 the separator will be copied at the end of the left-substring +*******************************************************************/ +vector split(const string& str, const string& sep, int maxLength, int trough) +{ + vector strList ; + int n,l,end, begin; + string tmpStr=str ; + l= sep.length(); + // Optional trough variable indicates that the separator + // string remain in the array string + if (trough) trough = l ; + n = count(tmpStr,sep); + if (n>maxLength) n = maxLength ; + //n (or maxLength) is the number of separator to be found + begin = 0; + //cout << "->"<< str << " <--------> " << sep << ":\n"; + end = tmpStr.find(sep); + for (int i=0; ibeg>end>" << tmpStr.length() ; + strList.push_back(tmpStr.substr(begin, tmpStr.length() - begin ) ) ; + //cout << "||"<< tmpStr.substr( begin,tmpStr.length() - begin )<<"||\n" ; + return strList ; + +}; + +/****************************************************************** + method : sp + field: string class + used to create a checkString +*******************************************************************/ +string sp(const string& separator) + { + const string sep = "_SEP_" ; + return sep + separator + sep ; + } + +/****************************************************************** + method : checkFormat + field: string class + Chek the format of a string + The format should be given as: + TYPE+sep+SEPARATOR+sep+TYPE+sep+SEPARATOR+sep+ TYPE +... + Returns: 0 No Error + 1 Error Found +*******************************************************************/ +int checkFormat (const string& format, const string& str) +{ + string type , separator, tmpStr=str ; + vector form ; + int len, pos, i; + const string sep = "_SEP_" ; + const string sepStr = "$STR$" ; + const string sepInt = "$INT$" ; + form =split (format,sep); + len=form.size(); + for (i =1;i +#endif + +#ifdef HAVE_STRINGSTREAM +#include +#else +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#define CHAR_BUFFER_SIZE 1024 + +namespace glite { +namespace wmsutils { +namespace exception { + +/** + * std:string useful JSUI common utilized methods + * + * @ingroup Common + * @version 0.1 + * @date 15 April 2002 + * @author Alessandro Maraschini +*/ + +/** +* Check if a string can be converted into an integer +* @ingroup Common +*/ +int isInt (const std::string& str); +/** +* Converts a string into an Integer value +* @ingroup Common +*/ +int toInt (const std::string& str, int &sum); +/** +* Converts a string into an Hexasdecimal value +* @ingroup Common +*/ +int toHex (const std::string& str, int &sum); +/** +* Converts an integer into a string +* @ingroup Common +*/ +std::string inTo(int i); +/** +* Counts number of sub-string occurrences in a string +* @ingroup Common +*/ +int count(const std::string& strMain, const std::string& sep); +/** +* Splits a string into a vector of substring +* @param str - The string to be parsed +* @param sep - The separator to be found +* @param maxLength - max dimension of vector (the last item of the vector will be the lasting part) +* @param trough - if trough == 1 the separator will be copied at the end of the left-substring +* @ingroup Common +*/ +std::vector split(const std::string& str, const std::string& sep, int maxLength =1000, int trough = 0); +std::string sp(const std::string& separator); +int checkFormat (const std::string& format, const std::string& str); + +void +replace(std::string& where, const std::string& what, const std::string& with); + +} // exception namespace +} // wmsglite namespace +} // glite namespace + +#endif -- 1.8.2.3