From 1987b94685bcf89a8f2167181d933e57eaa2fa1b Mon Sep 17 00:00:00 2001 From: "Edson W. R. Pereira" Date: Wed, 1 May 2013 12:21:19 +0000 Subject: [PATCH] Cleaned up remaining exception related code in rigclass.h and .cpp git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3249 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- devsetup.cpp | 7 +++- mainwindow.cpp | 7 +++- rigclass.cpp | 28 +++++++++---- rigclass.h | 109 ++----------------------------------------------- 4 files changed, 35 insertions(+), 116 deletions(-) diff --git a/devsetup.cpp b/devsetup.cpp index efdcdfbb0..9faa4c482 100644 --- a/devsetup.cpp +++ b/devsetup.cpp @@ -414,7 +414,12 @@ void DevSetup::on_testCATButton_clicked() delete rig; m_bRigOpen=false; } - rig = new Rig(m_rig); + rig = new Rig(); + if (!rig->init(m_rig)) { + msgBox("Rig init failure"); + return; + } + rig->setConf("rig_pathname", m_catPort.toAscii().data()); char buf[80]; sprintf(buf,"%d",m_serialRate); diff --git a/mainwindow.cpp b/mainwindow.cpp index a736ca533..d47a73202 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2762,7 +2762,12 @@ void MainWindow::rigOpen() QString t; int ret; - rig = new Rig(m_rig); + rig = new Rig(); + if (!rig->init(m_rig)) { + msgBox("Rig init failure"); + return; + } + rig->setConf("rig_pathname", m_catPort.toAscii().data()); char buf[80]; sprintf(buf,"%d",m_serialRate); diff --git a/rigclass.cpp b/rigclass.cpp index 87e8cd8e1..424c4f122 100644 --- a/rigclass.cpp +++ b/rigclass.cpp @@ -48,16 +48,9 @@ static int hamlibpp_freq_event(RIG *rig, vfo_t vfo, freq_t freq, rig_ptr_t arg) return ((Rig*)rig->state.obj)->FreqEvent(vfo, freq, arg); } -Rig::Rig(rig_model_t rig_model) { +Rig::Rig() +{ rig_set_debug_level( RIG_DEBUG_WARN); - - theRig = rig_init(rig_model); - if (!theRig) - THROW(new RigException ("Rig initialization error")); - - caps = theRig->caps; - theRig->callbacks.freq_event = &hamlibpp_freq_event; - theRig->state.obj = (rig_ptr_t)this; } Rig::~Rig() { @@ -66,6 +59,23 @@ Rig::~Rig() { caps = NULL; } +int Rig::init(rig_model_t rig_model) +{ + int initOk; + + theRig = rig_init(rig_model); + if (!theRig) + initOk = false; + else + initOk = true; + + caps = theRig->caps; + theRig->callbacks.freq_event = &hamlibpp_freq_event; + theRig->state.obj = (rig_ptr_t)this; + + return initOk; +} + int Rig::open(void) { return rig_open(theRig); } diff --git a/rigclass.h b/rigclass.h index 295ae5000..3568d2131 100644 --- a/rigclass.h +++ b/rigclass.h @@ -32,12 +32,14 @@ private: protected: public: - Rig(rig_model_t rig_model); - + Rig(); virtual ~Rig(); const struct rig_caps *caps; + // Initialize rig + int init(rig_model_t rig_model); + // This method open the communication port to the rig int open(void); @@ -73,110 +75,7 @@ public: virtual int DCDEvent(vfo_t, dcd_t, rig_ptr_t) const { return RIG_OK; } - - }; - -#ifdef __GNUG__ -# if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8)) -# if HAVE_TYPEINFO -# include -# endif -# endif -#endif - -#if defined(__GNUG__) -# if HAVE_BUILTIN_H || HAVE_GXX_BUILTIN_H || HAVE_GPP_BUILTIN_H -# if ETIP_NEEDS_MATH_H -# if ETIP_NEEDS_MATH_EXCEPTION -# undef exception -# define exception math_exception -# endif -# include -# endif -# undef exception -# define exception builtin_exception -# if HAVE_GPP_BUILTIN_H -# include -# elif HAVE_GXX_BUILTIN_H -# include -# else -# include -# endif -# undef exception -# endif -#elif defined (__SUNPRO_CC) -# include -# include -#else -# include -#endif - - -extern "C" { -#if HAVE_VALUES_H -# include -#endif - -#include -#include -} - -#include -#if !(defined(__GNUG__)||defined(__SUNPRO_CC)) - extern "C" void exit(int); -#endif - -// Forward Declarations - -class BACKEND_IMPEXP RigException -{ -public: - const char *message; - int errorno; - - RigException (const char* msg, int err) - : message(msg), errorno (err) - {}; - - RigException (int err) - : message(rigerror(err)), errorno (err) - {}; - - RigException (const char* msg) - : message(msg), errorno (-RIG_EINTERNAL) - {}; - - virtual ~RigException() - {}; - - void print() const { - std::cerr << "Rig exception: " << message << std::endl; - } - virtual const char *classname() const { - return "Rig"; - } -}; - -inline void THROW(const RigException *e) { -#if defined(__GNUG__) -# if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8)) - (*lib_error_handler)(e?e->classname():"",e?e->message:""); -#else - throw *e; -#endif -#elif defined(__SUNPRO_CC) - genericerror(1, ((e != 0) ? (char *)(e->message) : "")); -#else - if (e) - std::cerr << e->message << endl; - exit(0); -#endif -} - -#define THROWS(s) - - #endif // _RIGCLASS_H