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);
82 void (QTcpSocket::* errorOverloaded)(QAbstractSocket::SocketError) = &QTcpSocket::error;
84 connect(
mSocket, errorOverloaded,
this, &SocketConnection::internalError);
163 qint64 writtenBytes =
mSocket->write(data, maxSize);
164 if(writtenBytes != maxSize)
169 void SocketConnection::internalConnected()
175 void SocketConnection::internalDisconnected()
181 void SocketConnection::internalError(QAbstractSocket::SocketError socketError)
183 CX_LOG_ERROR() << QString(
"[%1] Socket error [code=%2]: %3")
185 .arg(QString::number(socketError))
191 void SocketConnection::internalDataAvailable()
204 return mSocket->state() == QAbstractSocket::ConnectedState;
209 bool enoughBytes =
mSocket->bytesAvailable() >= bytes;
220 char* charPointer =
reinterpret_cast<char*
>(packPointer);
221 int r =
mSocket->read(charPointer, packSize);
224 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
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)
DEFINE_ENUM_STRING_CONVERTERS_BEGIN(cx, CX_SOCKETCONNECTION_STATE, scsCOUNT)
virtual void requestConnect()
not thread-safe: use invoke
DEFINE_ENUM_STRING_CONVERTERS_END(cx, ORIENTATION_TYPE, otCOUNT)
QString getDescription() const
SocketConnectorPtr createConnector(ConnectionInfo info)
bool isLocalhostConnection() const
QMutex mNextConnectionInfoMutex
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
virtual void setProtocol(QString protocolname)
Namespace for all CustusX production code.