00001 #ifndef SCTCALIBRATIONCONTROLLER_SCTAPICALL_H
00002 #define SCTCALIBRATIONCONTROLLER_SCTAPICALL_H
00003
00004 #include "SctApiException.h"
00005 #include "SctApiAccessException.h"
00006
00007 #ifndef __Sct_SctApi_H_
00008 #include "Sct_SctApi/SctApi.hh"
00009 #endif
00010
00011 #include "Sct/LogicErrors.h"
00012 #include "Sct/CorbaExceptionWrapper.h"
00013 #include <string>
00014
00015 namespace SctCalibrationController {
00016
00026 inline SctApiAccessException raiseSctApiException(const CORBA::Exception & exception,
00027 const char* extraErrorText,
00028 const char* file,
00029 unsigned int line) {
00030 std::string text;
00031 text += "CORBA::Exception&Information[";
00032 text += Sct::CorbaExceptionWrapper::whatDoesThisCORBAExceptionTellUs(exception);
00033 text += "] Context[";
00034 text += extraErrorText;
00035 text += "]";
00036 return SctApiAccessException(exception, text.c_str(), file, line);
00037 }
00038
00039 inline SctApiAccessException raiseLongSctApiException(const Sct_SctApi::SctApiException & exception,
00040 const char* extraErrorText,
00041 const char* file,
00042 unsigned int line) {
00043 std::string text;
00044 text += "Name[";
00045 text += exception._name();
00046 text += "] Detail[";
00047 text += exception.detail;
00048 text += "] Context[";
00049 text += extraErrorText;
00050 text += "]";
00051 return SctApiAccessException(exception, text.c_str(), file, line);
00052 }
00053
00054 #define APICALL( api, call, errorText ) { \
00055 if (CORBA::is_nil(api)) { throw InvalidArgumentError("Null pointer to SctApi", __FILE__, __LINE__); } \
00056 try { \
00057 (api)->call; \
00058 } catch (const Sct_SctApi::SctApiException & exe) { \
00059 std::cerr << "APICALL caught an Sct_SctApi::SctApiException with name [" << exe._name() << "] and detail [" << exe.detail << "] therefore [" << errorText << "]" << std::endl; \
00060 throw raiseLongSctApiException(exe, errorText, __FILE__, __LINE__);\
00061 } catch (const CORBA::Exception & exe) { \
00062 std::cerr << "APICALL caught unknown type of CORBA::Exception with name [" << exe._name() << "] therefore [" << errorText << "]" << std::endl; \
00063 throw raiseSctApiException(exe, errorText, __FILE__, __LINE__);\
00064 } \
00065 }
00066
00067 #define APIRETCALL( api, ret, call, errorText ) { \
00068 if (CORBA::is_nil(api)) throw InvalidArgumentError("Null pointer to SctApi", __FILE__, __LINE__); \
00069 try { \
00070 ret=(api)->call; \
00071 } catch (const Sct_SctApi::SctApiException & exe) { \
00072 std::cerr << "APICALL caught an Sct_SctApi::SctApiException with name [" << exe._name() << "] and detail [" << exe.detail << "] therefore [" << errorText << "]" << std::endl; \
00073 throw raiseLongSctApiException(exe, errorText, __FILE__, __LINE__);\
00074 } catch (const CORBA::Exception & exe) { \
00075 std::cerr << "APIRETCALL caught unknown type of CORBA::Exception with name [" << exe._name() << "] therefore [" << errorText << "]" << std::endl; \
00076 throw raiseSctApiException(exe, errorText, __FILE__, __LINE__);\
00077 } \
00078 }
00079
00080 }
00081
00082 #endif //SCTCALIBRATIONCONTROLLER_SCTAPICALL_H