ATLAS Offline Software
Classes | Public Slots | Signals | Public Member Functions | Private Slots | Private Attributes | List of all members
VP1TcpServer Class Reference

#include <VP1TcpServer.h>

Inheritance diagram for VP1TcpServer:
Collaboration diagram for VP1TcpServer:

Classes

class  Imp
 

Public Slots

void close ()
 

Signals

void receivedExternalRequest (VP1ExternalRequest)
 
void listenStateChanged (bool)
 

Public Member Functions

 VP1TcpServer ()
 
virtual ~VP1TcpServer ()
 
bool listen (QString &err, const quint16 &port=4747)
 
quint16 port () const
 
bool isListening ()
 

Private Slots

void acceptConnection ()
 
void readData ()
 
void handleError (QAbstractSocket::SocketError)
 
void socketDestroyed (QObject *)
 
void listenStateMightHaveChanged ()
 

Private Attributes

Impm_d
 

Detailed Description

Definition at line 22 of file VP1TcpServer.h.

Constructor & Destructor Documentation

◆ VP1TcpServer()

VP1TcpServer::VP1TcpServer ( )

Definition at line 35 of file VP1TcpServer.cxx.

36  : QObject(), m_d(new Imp)
37 {
38  m_d->lastemit_listen=-1;
39  m_d->tcpserv=this;
40  m_d->port=0;
41  connect(&m_d->tcpserver, SIGNAL(newConnection()),this, SLOT(acceptConnection()));
42 
43  //
44  QTimer * timer = new QTimer(this);
45  timer->start(2000);
46  connect(timer, SIGNAL(timeout()),this, SLOT(listenStateMightHaveChanged()));
47 }

◆ ~VP1TcpServer()

VP1TcpServer::~VP1TcpServer ( )
virtual

Definition at line 50 of file VP1TcpServer.cxx.

51 {
52  close();
53  delete m_d; m_d=0;
54 }

Member Function Documentation

◆ acceptConnection

void VP1TcpServer::acceptConnection ( )
privateslot

Definition at line 107 of file VP1TcpServer.cxx.

108 {
109  if (!m_d->tcpserver.hasPendingConnections())
110  return;
111  QTcpSocket * socket = m_d->tcpserver.nextPendingConnection();
112  if (m_d->sockets2blocksize.contains(socket)) {
113  //we are already dealing with this one, but look back here in a
114  //short while to se if anything else is queued.
115  QTimer::singleShot(100, this, SLOT(acceptConnection()));
116  return;
117  }
118  assert(!m_d->sockets2blocksize.contains(socket));
119  m_d->sockets2blocksize.insert(socket,0);
120  connect(socket, SIGNAL(readyRead()),this, SLOT(readData()));
121  connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(handleError(QAbstractSocket::SocketError)));
122  connect(socket, SIGNAL(disconnected()),socket, SLOT(deleteLater()));
123  connect(socket, SIGNAL(destroyed(QObject*)),this,SLOT(socketDestroyed (QObject*)));
125 }

◆ close

void VP1TcpServer::close ( )
slot

Definition at line 87 of file VP1TcpServer.cxx.

88 {
89  if (!isListening())
90  return;
91  disconnect(&m_d->tcpserver, SIGNAL(newConnection()),this, SLOT(acceptConnection()));
92 
93  QMapIterator<QTcpSocket *,quint16> it(m_d->sockets2blocksize);
94  while (it.hasNext()) {
95  it.next();
96  QTcpSocket * socket = it.key();
97  delete socket;
98  }
99  m_d->sockets2blocksize.clear();
100 
101  m_d->tcpserver.close();
102  m_d->port=0;
104 }

◆ handleError

void VP1TcpServer::handleError ( QAbstractSocket::SocketError  se)
privateslot

Definition at line 128 of file VP1TcpServer.cxx.

129 {
130  if (se == QTcpSocket::RemoteHostClosedError)
131  return;
132  QTcpSocket * socket = m_d->recognisedSocket(sender());
133  if (!socket)
134  return;
135  if (socket->state()!=QAbstractSocket::UnconnectedState) {
136  socket->disconnectFromHost();
137  }
138  // std::cout << "VP1TcpServer::Error during connection:"<<m_d->tcpserver.errorString().toStdString()<<std::endl;
140 }

◆ isListening()

bool VP1TcpServer::isListening ( )

Definition at line 81 of file VP1TcpServer.cxx.

82 {
83  return m_d->tcpserver.isListening();
84 }

◆ listen()

bool VP1TcpServer::listen ( QString &  err,
const quint16 &  port = 4747 
)

Definition at line 57 of file VP1TcpServer.cxx.

57  {
58  if (isListening())
59  close();
60  bool success = m_d->tcpserver.listen(QHostAddress::LocalHost,port);
61  if (!success) {
62  err = m_d->tcpserver.errorString();
63  m_d->port=0;
65  return false;
66  }
67  m_d->port=port;
68  err.clear();
69 
71  return true;
72 }

◆ listenStateChanged

void VP1TcpServer::listenStateChanged ( bool  )
signal

◆ listenStateMightHaveChanged

void VP1TcpServer::listenStateMightHaveChanged ( )
privateslot

Definition at line 206 of file VP1TcpServer.cxx.

207 {
208  bool l = isListening();
209  bool last = m_d->lastemit_listen == 1 ? true : false;
210  if (m_d->lastemit_listen==-1||(l!=last)) {
212  }
213  m_d->lastemit_listen = l ? 1 : 0;
214 }

◆ port()

quint16 VP1TcpServer::port ( ) const

Definition at line 75 of file VP1TcpServer.cxx.

76 {
77  return m_d->port;
78 }

◆ readData

void VP1TcpServer::readData ( )
privateslot

Definition at line 143 of file VP1TcpServer.cxx.

144 {
145  QTcpSocket * socket = m_d->recognisedSocket(sender());
146  if (!socket)
147  return;
148  if (socket->state()!=QAbstractSocket::ConnectedState) {
149  // assert(0&&"This should never happen...");
150  return;
151  }
152 
153  QDataStream in(socket);
154  in.setVersion(QDataStream::Qt_4_2);
155 
156  //Make sure that we can read enough to determine the data length:
157  if (m_d->sockets2blocksize[socket] == 0) {
158  if (socket->bytesAvailable() < (int)sizeof(quint16))
159  return;
160  in >> m_d->sockets2blocksize[socket];
161  }
162 
163  //Make sure that we can read all of the data:
164  if (socket->bytesAvailable() < m_d->sockets2blocksize[socket])
165  return;
166 
167  QString data;
168  in >> data;
169  // qDebug(QString("Got: "+data).toStdString().c_str());
170 
171  if (m_d->sockets2blocksize.contains(socket)) {
172  socket->disconnectFromHost();
173  }
174 
175  //Notice that we dont fire any signals unless we positively see something that we know how to handle!
176  if (data.startsWith("VP1ExternalRequest")) {
177  VP1ExternalRequest request(data);
178  if (request.isValid()) {
179  //qDebug("Got valid VP1ExternalRequest!");
180  receivedExternalRequest(request);
181  }
182  }
184 }

◆ receivedExternalRequest

void VP1TcpServer::receivedExternalRequest ( VP1ExternalRequest  )
signal

◆ socketDestroyed

void VP1TcpServer::socketDestroyed ( QObject *  obj)
privateslot

Definition at line 196 of file VP1TcpServer.cxx.

197 {
198  QTcpSocket * socket = static_cast<QTcpSocket *>(obj);
199  if (!socket)
200  return;
201  if (m_d->sockets2blocksize.contains(socket))
202  m_d->sockets2blocksize.remove(socket);
204 }

Member Data Documentation

◆ m_d

Imp* VP1TcpServer::m_d
private

Definition at line 51 of file VP1TcpServer.h.


The documentation for this class was generated from the following files:
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
VP1TcpServer::Imp::lastemit_listen
int lastemit_listen
Definition: VP1TcpServer.cxx:31
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
VP1TcpServer::Imp::sockets2blocksize
QMap< QTcpSocket *, quint16 > sockets2blocksize
Definition: VP1TcpServer.cxx:29
skel.it
it
Definition: skel.GENtoEVGEN.py:396
VP1TcpServer::readData
void readData()
Definition: VP1TcpServer.cxx:143
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
keylayer_zslicemap.se
se
Definition: keylayer_zslicemap.py:194
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:182
VP1TcpServer::receivedExternalRequest
void receivedExternalRequest(VP1ExternalRequest)
VP1TcpServer::port
quint16 port() const
Definition: VP1TcpServer.cxx:75
VP1ExternalRequest
Definition: VP1ExternalRequest.h:20
VP1TcpServer::close
void close()
Definition: VP1TcpServer.cxx:87
VP1TcpServer::m_d
Imp * m_d
Definition: VP1TcpServer.h:50
VP1TcpServer::Imp::tcpserver
QTcpServer tcpserver
Definition: VP1TcpServer.cxx:28
VP1TcpServer::acceptConnection
void acceptConnection()
Definition: VP1TcpServer.cxx:107
VP1TcpServer::listenStateChanged
void listenStateChanged(bool)
VP1TcpServer::Imp::tcpserv
VP1TcpServer * tcpserv
Definition: VP1TcpServer.cxx:26
VP1TcpServer::socketDestroyed
void socketDestroyed(QObject *)
Definition: VP1TcpServer.cxx:196
VP1TcpServer::listenStateMightHaveChanged
void listenStateMightHaveChanged()
Definition: VP1TcpServer.cxx:206
VP1TcpServer::handleError
void handleError(QAbstractSocket::SocketError)
Definition: VP1TcpServer.cxx:128
VP1TcpServer::Imp::port
quint16 port
Definition: VP1TcpServer.cxx:27
get_generator_info.error
error
Definition: get_generator_info.py:40
python.PyAthena.obj
obj
Definition: PyAthena.py:132
python.TrigInDetArtSteps.timeout
timeout
Definition: TrigInDetArtSteps.py:35
VP1TcpServer::isListening
bool isListening()
Definition: VP1TcpServer.cxx:81
VP1TcpServer::Imp::recognisedSocket
QTcpSocket * recognisedSocket(QObject *) const
Definition: VP1TcpServer.cxx:187