From fc1eda5ae954804609e4a5e614d16f8c5a840614 Mon Sep 17 00:00:00 2001 From: santi Date: Mon, 18 Aug 2014 15:52:18 +0200 Subject: [PATCH] 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. --- src/olathread.cpp | 50 ++++++++++++++++++++++++++++++++++------------- src/olathread.h | 2 ++ 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/olathread.cpp b/src/olathread.cpp index 7dd97eb..a35486d 100644 --- a/src/olathread.cpp +++ b/src/olathread.cpp @@ -1,5 +1,7 @@ #include "olathread.h" +#include + olaThread::olaThread(QObject *parent) { Q_UNUSED(parent); @@ -20,19 +22,6 @@ olaThread::olaThread(QObject *parent) 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 --- @@ -42,6 +31,23 @@ olaThread::~olaThread() { /** 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() { @@ -145,12 +151,28 @@ void olaThread::setDMXConf(dmxSetting set) { if (set.layer >= m_layersNumber) { return; } 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)) { registerUniverse(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(); +} + //////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/olathread.h b/src/olathread.h index 5155448..5133c67 100644 --- a/src/olathread.h +++ b/src/olathread.h @@ -87,6 +87,8 @@ private: // typedef Callback2 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 socketClosed(); + void init(); public slots: void stop(); // Close the connection with olad.