15 #include <QNetworkInterface> 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.";
virtual void setConnectionInfo(ConnectionInfo info)
thread-safe
CX_SOCKETCONNECTION_STATE
bool sendData(const char *data, qint64 maxSize)
not thread-safe
SNW_DEFINE_ENUM_STRING_CONVERTERS_BEGIN(cx, CX_SOCKETCONNECTION_STATE, scsCOUNT)
bool socketReceive(void *packPointer, int packSize) const
bool enoughBytesAvailableOnSocket(int bytes) const
CX_SOCKETCONNECTION_STATE getState()
thread-safe
ConnectionInfo mNextConnectionInfo
info to be used for the next connect(), mutexed.
void stateChange(CX_SOCKETCONNECTION_STATE newState)
CX_SOCKETCONNECTION_STATE mCurrentState
void stateChanged(CX_SOCKETCONNECTION_STATE status)
virtual void requestDisconnect()
not thread-safe: use invoke
ConnectionInfo getConnectionInfo()
thread-safe
SocketConnection(QObject *parent=0)
virtual void requestConnect()
not thread-safe: use invoke
QString getDescription() const
SocketConnectorPtr createConnector(ConnectionInfo info)
bool isLocalhostConnection() const
QMutex mNextConnectionInfoMutex
virtual void setProtocol(QString protocolname)=0
void connectionInfoChanged()
boost::shared_ptr< class SocketConnector > SocketConnectorPtr
void stateChanged(CX_SOCKETCONNECTION_STATE)
#define assertRunningInObjectThread()
CX_SOCKETCONNECTION_STATE computeState()
SocketConnectorPtr mConnector
bool operator==(const ConnectionInfo &rhs) const
SNW_DEFINE_ENUM_STRING_CONVERTERS_END(cx, ORIENTATION_TYPE, otCOUNT)
Namespace for all CustusX production code.