Added a new callback to m_client to recovery the connection on server

close.

Not tested and not registerig the real universes, only universe 1.
This commit is contained in:
santi 2014-08-18 15:52:18 +02:00
parent dd544be8dc
commit fc1eda5ae9
2 changed files with 38 additions and 14 deletions

View file

@ -1,5 +1,7 @@
#include "olathread.h" #include "olathread.h"
#include <ola/Callback.h>
olaThread::olaThread(QObject *parent) olaThread::olaThread(QObject *parent)
{ {
Q_UNUSED(parent); Q_UNUSED(parent);
@ -20,19 +22,6 @@ olaThread::olaThread(QObject *parent)
m_dmx[i][j] = 0; m_dmx[i][j] = 0;
} }
} }
// set up ola connection
m_clientWrapper = new ola::client::OlaClientWrapper;
Q_CHECK_PTR(m_clientWrapper);
if (!m_clientWrapper->Setup()) { qErrnoWarning("olaThread::olaStart| Failed Setup() in Client Wrapper"); }
m_client = m_clientWrapper->GetClient();
if (ola::InitLogging(ola::OLA_LOG_INFO , ola::OLA_LOG_STDERR)) {
qDebug() << "ola logging debug working";
} else {
qWarning() << "Can not init ola logging";
}
m_client->SetDMXCallback(ola::NewCallback(this, &olaThread::NewDmx));
m_clientWrapper->GetSelectServer()->RegisterRepeatingTimeout(4000, ola::NewCallback(this, &olaThread::CheckDataLoss));
// qDebug() << "Init olaThread";
} }
// --- DECONSTRUCTOR --- // --- DECONSTRUCTOR ---
@ -42,6 +31,23 @@ olaThread::~olaThread() {
/** Open the connection with olad and start processing data. /** Open the connection with olad and start processing data.
*/ */
// set up ola connection
void olaThread::init()
{
if (ola::InitLogging(ola::OLA_LOG_INFO , ola::OLA_LOG_STDERR)) {
qDebug() << "ola logging debug working";
} else {
qWarning() << "Can not init ola logging";
}
m_clientWrapper = new ola::client::OlaClientWrapper;
Q_CHECK_PTR(m_clientWrapper);
if (!m_clientWrapper->Setup()) { qErrnoWarning("olaThread::olaStart| Failed Setup() in Client Wrapper"); }
m_client = m_clientWrapper->GetClient();
m_client->SetDMXCallback(ola::NewCallback(this, &olaThread::NewDmx));
m_clientWrapper->GetSelectServer()->RegisterRepeatingTimeout(4000, ola::NewCallback(this, &olaThread::CheckDataLoss));
// qDebug() << "Init olaThread";
m_client->SetCloseHandler(ola::NewSingleCallback(this, &olaThread::socketClosed));
}
void olaThread::run() void olaThread::run()
{ {
@ -145,12 +151,28 @@ void olaThread::setDMXConf(dmxSetting set)
{ {
if (set.layer >= m_layersNumber) { return; } if (set.layer >= m_layersNumber) { return; }
m_settings.replace(set.layer, set); m_settings.replace(set.layer, set);
// ToDo: registro del nuevo universo si no está registrado ya // registro del nuevo universo si no está registrado ya
if (!m_universe->contains(set.universe)) { if (!m_universe->contains(set.universe)) {
registerUniverse(set.universe); registerUniverse(set.universe);
m_universe->append(set.universe); m_universe->append(set.universe);
} }
} }
void olaThread::socketClosed()
{
qDebug("ola close the connection. Trying reopening it... ");
// is needed some cleaning?
// set up ola connection
init();
// Register the universes
registerUniverse(1);
// start the thread????
run();
}
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -87,6 +87,8 @@ private:
// typedef Callback2<void, const DMXMetadata&, const DmxBuffer&> ola::client::RepeatableDMXCallback // typedef Callback2<void, const DMXMetadata&, const DmxBuffer&> ola::client::RepeatableDMXCallback
void NewDmx(const ola::client::DMXMetadata &dmx_meta, const ola::DmxBuffer &buffer); // Callback from OlaCLient when there is new dmx info void NewDmx(const ola::client::DMXMetadata &dmx_meta, const ola::DmxBuffer &buffer); // Callback from OlaCLient when there is new dmx info
void socketClosed();
void init();
public slots: public slots:
void stop(); // Close the connection with olad. void stop(); // Close the connection with olad.