5#include <QCoreApplication>
6#include <QLoggingCategory>
8#include "RabbitCommonTools.h"
10static Q_LOGGING_CATEGORY(log,
"Channel")
12QSharedPointer<QTranslator> g_Translator =
nullptr;
23 qDebug(log) <<
"CChannel::CChannel";
29 qDebug(log) <<
"CChannel::~CChannel";
32qint64 CChannel::readData(
char *data, qint64 maxlen)
39 nRet = m_pSocket->read(data, maxlen);
41 setErrorString(m_pSocket->errorString());
46qint64 CChannel::writeData(
const char *data, qint64 len)
49 if(
nullptr == data || 0 >= len) {
50 qCritical(log) <<
"writeData fail. len:" << len;
56 nRet = m_pSocket->write(data, len);
58 setErrorString(m_pSocket->errorString());
62bool CChannel::isSequential()
const
67void CChannel::slotError(QAbstractSocket::SocketError e)
71 szError = m_pSocket->errorString();
82 if(!m_pSocket)
return false;
84 check = connect(m_pSocket, SIGNAL(readyRead()),
85 this, SIGNAL(readyRead()));
87 check = connect(m_pSocket, SIGNAL(connected()),
90 check = connect(m_pSocket, SIGNAL(disconnected()),
93 check = connect(m_pSocket,
94 #
if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
95 SIGNAL(errorOccurred(QAbstractSocket::SocketError)),
97 SIGNAL(error(QAbstractSocket::SocketError)),
99 this, SLOT(slotError(QAbstractSocket::SocketError)));
101 return QIODevice::open(mode);
104void CChannel::close()
111QString CChannel::GetDetails()
116int CChannel::InitTranslation()
119 g_Translator = RabbitCommon::CTools::Instance()->InstallTranslator(
120 "Channel", RabbitCommon::CTools::TranslationType::Library);
124int CChannel::RemoveTranslation()
127 RabbitCommon::CTools::Instance()->RemoveTranslator(g_Translator);
The channel interface class.
void sigConnected()
emit when the channel is connected.
void sigDisconnected()
emit when the channel is disconnected
void sigError(int nErr, const QString &szErr)
emit when the channel is error
virtual bool open(OpenMode mode) override
CChannel(QTcpSocket *pSocket, QObject *parent=nullptr)
CChannel.