Reinserts original comments
This commit is contained in:
112 files changed
+7113
-5131
No files matched your search
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvSocketThread
|
||||
// **************************************************************************
|
||||
|
||||
#include "PrtCnvSocketThread.hpp"
|
||||
#include <utility>
|
||||
@@ -25,9 +25,9 @@
|
||||
namespace PrtCnv
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Constructor with pointer to thread-starter as parameter
|
||||
// ---------------------------------------------------------------
|
||||
PrtCnvSocketThread::PrtCnvSocketThread(PrtCnv::PrtCnvThreadStarter* a_parent, const char *loggerName)
|
||||
: PrtCnvThread(a_parent, loggerName)
|
||||
, m_ConnectionTimer(nullptr)
|
||||
@@ -54,9 +54,9 @@ PrtCnvSocketThread::~PrtCnvSocketThread()
|
||||
cleanup();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Creates all subcomponents and connects signals to slots
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvSocketThread::create(NGL::Settings *settings)
|
||||
{
|
||||
PrtCnvThread::create(settings);
|
||||
@@ -76,10 +76,10 @@ int32_t PrtCnvSocketThread::create(NGL::Settings *settings)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Creates a new socket to avoid getting old stuff from the
|
||||
// former socket when reconnecting
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::createNewSocket()
|
||||
{
|
||||
INFO_LOG(m_logger) << "createNewSocket m_oldSocket=" << m_Socket;
|
||||
@@ -87,11 +87,11 @@ void PrtCnvSocketThread::createNewSocket()
|
||||
|
||||
if (m_Socket)
|
||||
{
|
||||
m_Socket->disconnectFromHost();
|
||||
m_Socket->disconnect();
|
||||
m_Socket->disconnectFromHost(); // Falls noch connected
|
||||
m_Socket->disconnect(); // Alle Signals/Slots aufräumen
|
||||
if (m_Socket->state() != QAbstractSocket::UnconnectedState)
|
||||
m_Socket->waitForDisconnected();
|
||||
m_Socket->deleteLater();
|
||||
m_Socket->deleteLater(); // und weg damit
|
||||
}
|
||||
|
||||
m_Socket = new QTcpSocket(this);
|
||||
@@ -106,9 +106,9 @@ void PrtCnvSocketThread::createNewSocket()
|
||||
connect(m_Socket, &QTcpSocket::readyRead, this, &PrtCnvSocketThread::readyRead, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Deallocates subcomponents.
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvSocketThread::destroy()
|
||||
{
|
||||
PrtCnvThread::destroy();
|
||||
@@ -124,9 +124,9 @@ void PrtCnvSocketThread::cleanup()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Initializes the variables.
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvSocketThread::init()
|
||||
{
|
||||
INFO_LOG(m_logger) << "PrtCnvSocketThread::init()";
|
||||
@@ -140,10 +140,10 @@ int32_t PrtCnvSocketThread::init()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Connect as client to a TCP-server on ip-address configured
|
||||
// as HostName and Port configured as Port
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::connectSocket()
|
||||
{
|
||||
int sockState = m_Socket ? m_Socket->state() : -1;
|
||||
@@ -152,7 +152,7 @@ void PrtCnvSocketThread::connectSocket()
|
||||
{
|
||||
if (m_Socket)
|
||||
{
|
||||
m_Socket->disconnectFromHost();
|
||||
m_Socket->disconnectFromHost(); // Falls noch connected
|
||||
if (m_Socket->state() != QAbstractSocket::UnconnectedState)
|
||||
m_Socket->waitForDisconnected();
|
||||
}
|
||||
@@ -175,9 +175,9 @@ void PrtCnvSocketThread::connectSocket()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Disconnects from TCP-server
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::disconnectSocket()
|
||||
{
|
||||
m_Socket->disconnectFromHost();
|
||||
@@ -186,46 +186,46 @@ void PrtCnvSocketThread::disconnectSocket()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Qt-Framework when we have connected to
|
||||
// TCP-server
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::connected()
|
||||
{
|
||||
INFO_LOG(m_logger) << "connected (implement connected() in inherited class, if you want use this signal...)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Qt-Framework when we have disconnected
|
||||
// to TCP-server
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::disconnected()
|
||||
{
|
||||
INFO_LOG(m_logger) << "got signal 'disconnected' (implement disconnected() in inherited class, if you want use this signal...)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Qt-Framework when we have have read
|
||||
// data over socket
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::readyRead()
|
||||
{
|
||||
INFO_LOG(m_logger) << "got signal 'newData' (implement newData() in inherited class, if you want use this signal...)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// this slot is used for connection, disconnection and alive
|
||||
// timeouts
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::timeoutAliveAndConnection()
|
||||
{
|
||||
INFO_LOG(m_logger) << "got signal 'reconnectTimeout' (implement reconnectTimeout() in inherited class, if you want use this signal...)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Qt-Framework when we have a socket-error
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::error(QAbstractSocket::SocketError a_socketError)
|
||||
{
|
||||
switch (a_socketError)
|
||||
@@ -237,7 +237,7 @@ void PrtCnvSocketThread::error(QAbstractSocket::SocketError a_socketError)
|
||||
ERROR_LOG(m_logger) << getName() << ": RemoteHostClosedError";
|
||||
break;
|
||||
case QAbstractSocket::HostNotFoundError:
|
||||
|
||||
//ERROR_LOG(m_logger) << getName() << ": HostNotFoundError";
|
||||
break;
|
||||
default:
|
||||
ERROR_LOG(m_logger) << getName() << ": got signal 'error(QAbstractSocket::SocketError=" << a_socketError << ")'";
|
||||
@@ -245,28 +245,28 @@ void PrtCnvSocketThread::error(QAbstractSocket::SocketError a_socketError)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Qt-Framework when the host was found
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::hostFound()
|
||||
{
|
||||
|
||||
// INFO_LOG(m_logger) << "got signal 'hostFound' (implement hostFound() in inherited class, if you want use this signal...)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Qt-Framework when socket-state has
|
||||
// changed
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::stateChanged(QAbstractSocket::SocketState a_socketState)
|
||||
{
|
||||
Q_UNUSED(a_socketState);
|
||||
|
||||
// INFO_LOG(m_logger) << "got signal 'stateChanged(" << ao_socketState << ")' (implement stateChanged() in inherited class, if you want use this signal...)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// calls storeRadioTelegram of DbThread, see there
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::storeRadioTelegram(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_telegram,
|
||||
const uint32_t a_readCounter)
|
||||
{
|
||||
@@ -274,9 +274,9 @@ void PrtCnvSocketThread::storeRadioTelegram(const std::shared_ptr<N_CoPrtCnv::Co
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// used to check whether the other side is still alive
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::startAliveTimer()
|
||||
{
|
||||
m_ConnectionTimer->setInterval(m_AliveTimeout);
|
||||
@@ -284,9 +284,9 @@ void PrtCnvSocketThread::startAliveTimer()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// used to retry connection
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::startConnectionTimer()
|
||||
{
|
||||
m_ConnectionTimer->setInterval(m_ConnectTimeout);
|
||||
@@ -294,10 +294,10 @@ void PrtCnvSocketThread::startConnectionTimer()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// used to abort connection, when normal disconnection is not
|
||||
// successful
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::startDisconnectionTimer()
|
||||
{
|
||||
m_ConnectionTimer->setInterval(m_DisconnectTimeout);
|
||||
@@ -305,36 +305,36 @@ void PrtCnvSocketThread::startDisconnectionTimer()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// used for periodically ticks (i.e. for acks or sending
|
||||
// nachforderungen)
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::startTickTimer()
|
||||
{
|
||||
|
||||
// INFO_LOG(m_logger) << "start timer";
|
||||
m_TickTimer->setInterval(m_TickTimeout);
|
||||
m_TickTimer->start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// The counter will be set to a_startCounter if a_maxCounter
|
||||
// is reached
|
||||
// returns true if receive-counter is ok
|
||||
// returns false if a telegram is repeated or lost
|
||||
// ---------------------------------------------------------------
|
||||
bool PrtCnvSocketThread::checkAndUpdateReceiveCounter(const uint32_t a_counter, const uint32_t a_maxCounter, const uint32_t a_startCounter)
|
||||
{
|
||||
TRACE_LOG(m_logger) << "checkAndUpdateReceiveCounter: " << a_counter << ", " << m_ReceiveCounter;
|
||||
|
||||
// check for wrap
|
||||
if (a_maxCounter == ++m_ReceiveCounter)
|
||||
{
|
||||
m_ReceiveCounter = a_startCounter;
|
||||
}
|
||||
|
||||
// has the counter the expected value?
|
||||
if (m_ReceiveCounter != a_counter)
|
||||
{
|
||||
|
||||
//if (m_ReceiveCounter != 1)
|
||||
{
|
||||
if (m_ReceiveCounter > a_counter)
|
||||
{
|
||||
@@ -349,13 +349,13 @@ bool PrtCnvSocketThread::checkAndUpdateReceiveCounter(const uint32_t a_counter,
|
||||
}
|
||||
#if 0
|
||||
m_ReceiveCounter--;
|
||||
return false;
|
||||
return false; // failure
|
||||
#else
|
||||
m_ReceiveCounter = a_counter;
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
return true; // all ok
|
||||
}
|
||||
|
||||
void PrtCnvSocketThread::readHostAdresses()
|
||||
@@ -380,4 +380,4 @@ void PrtCnvSocketThread::readHostAdresses()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
Reference in new issue
Block a user