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
This commit is contained in:
Edson W. R. Pereira 2013-05-01 12:21:19 +00:00
parent 69ee577c11
commit 1987b94685
4 changed files with 35 additions and 116 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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 <typeinfo>
# 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 <math.h>
# endif
# undef exception
# define exception builtin_exception
# if HAVE_GPP_BUILTIN_H
# include <gpp/builtin.h>
# elif HAVE_GXX_BUILTIN_H
# include <g++/builtin.h>
# else
# include <builtin.h>
# endif
# undef exception
# endif
#elif defined (__SUNPRO_CC)
# include <generic.h>
# include <string.h>
#else
# include <string.h>
#endif
extern "C" {
#if HAVE_VALUES_H
# include <values.h>
#endif
#include <assert.h>
#include <errno.h>
}
#include <iostream>
#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