|
NorMIT-nav
22.09
An IGT application
|
Go to the documentation of this file.
15 #include <QNetworkInterface>
54 if (!protocol.isEmpty())
55 postfix = QString(
"[%1]").arg(protocol);
56 return QString(
"%1:%2%3").arg(name).arg(port).arg(postfix);
68 qRegisterMetaType<boost::function<void()> >(
"boost::function<void()>");
69 qRegisterMetaType<CX_SOCKETCONNECTION_STATE>(
"CX_SOCKETCONNECTION_STATE");
76 connect(
mSocket, &QTcpSocket::connected,
this, &SocketConnection::internalConnected);
77 connect(
mSocket, &QTcpSocket::disconnected,
this, &SocketConnection::internalDisconnected);
78 connect(
mSocket, &QTcpSocket::readyRead,
this, &SocketConnection::internalDataAvailable);
81 void (QTcpSocket::* errorOverloaded)(QAbstractSocket::SocketError) = &QTcpSocket::error;
83 connect(
mSocket, errorOverloaded,
this, &SocketConnection::internalError);
162 qint64 writtenBytes =
mSocket->write(data, maxSize);
163 if(writtenBytes != maxSize)
168 void SocketConnection::internalConnected()
174 void SocketConnection::internalDisconnected()
180 void SocketConnection::internalError(QAbstractSocket::SocketError socketError)
182 CX_LOG_ERROR() << QString(
"[%1] Socket error [code=%2]: %3")
184 .arg(QString::number(socketError))
192 return mSocket->state() == QAbstractSocket::ConnectedState;
197 bool enoughBytes =
mSocket->bytesAvailable() >= bytes;
199 CX_LOG_DEBUG() <<
"Want " << bytes <<
" but only "<<
mSocket->bytesAvailable() <<
" are available on the socket atm.";
208 char* charPointer =
reinterpret_cast<char*
>(packPointer);
209 int r =
mSocket->read(charPointer, packSize);
212 CX_LOG_ERROR() <<
"Error when receiving data from socket.";
SocketConnection(QObject *parent=0)
virtual void setProtocol(QString protocolname)=0
SocketConnectorPtr mConnector
DEFINE_ENUM_STRING_CONVERTERS_BEGIN(cx, CX_SOCKETCONNECTION_STATE, scsCOUNT)
#define assertRunningInObjectThread()
CX_SOCKETCONNECTION_STATE getState()
thread-safe
Namespace for all CustusX production code.
CX_SOCKETCONNECTION_STATE mCurrentState
ConnectionInfo getConnectionInfo()
thread-safe
void stateChange(CX_SOCKETCONNECTION_STATE newState)
QString getDescription() const
bool enoughBytesAvailableOnSocket(int bytes) const
ConnectionInfo mNextConnectionInfo
info to be used for the next connect(), mutexed.
bool isLocalhostConnection() const
virtual void requestDisconnect()
not thread-safe: use invoke
virtual void requestConnect()
not thread-safe: use invoke
SocketConnectorPtr createConnector(ConnectionInfo info)
bool sendData(const char *data, qint64 maxSize)
not thread-safe
void stateChanged(CX_SOCKETCONNECTION_STATE status)
virtual void setConnectionInfo(ConnectionInfo info)
thread-safe
bool operator==(const ConnectionInfo &rhs) const
CX_SOCKETCONNECTION_STATE computeState()
void connectionInfoChanged()
QMutex mNextConnectionInfoMutex
DEFINE_ENUM_STRING_CONVERTERS_END(cx, ORIENTATION_TYPE, otCOUNT)
boost::shared_ptr< class SocketConnector > SocketConnectorPtr
bool socketReceive(void *packPointer, int packSize) const
CX_SOCKETCONNECTION_STATE
void stateChanged(CX_SOCKETCONNECTION_STATE)