QXRD  0.11.16
Public Slots | Signals | Public Member Functions | Protected Member Functions | Properties | Private Attributes | List of all members
QxrdSimpleServer Class Reference

#include <qxrdsimpleserver.h>

Inheritance diagram for QxrdSimpleServer:
Inheritance graph
[legend]
Collaboration diagram for QxrdSimpleServer:
Collaboration graph
[legend]

Public Slots

void runModeChanged ()
 
void serverPortChanged ()
 
void openNewConnection ()
 
void connectionClosed ()
 
void clientRead ()
 
void shutdown ()
 
void finishedCommand (QScriptValue result)
 

Signals

void executeCommand (QString cmd)
 

Public Member Functions

 QxrdSimpleServer (QcepSettingsSaverWPtr saver, QxrdExperimentWPtr doc, QString name)
 
virtual ~QxrdSimpleServer ()
 
void startServer (QHostAddress addr, int port)
 
void stopServer ()
 
virtual void readSettings (QSettings *settings, QString section)
 
virtual void writeSettings (QSettings *settings, QString section)
 

Protected Member Functions

void printMessage (QString msg, QDateTime ts=QDateTime::currentDateTime())
 
void criticalMessage (QString msg)
 

Properties

int runSimpleServer
 
int simpleServerPort
 

Private Attributes

QxrdExperimentWPtr m_Experiment
 
QString m_Name
 
int m_Port
 
QTcpSocket * m_Socket
 

Detailed Description

Definition at line 13 of file qxrdsimpleserver.h.

Constructor & Destructor Documentation

QxrdSimpleServer::QxrdSimpleServer ( QcepSettingsSaverWPtr  saver,
QxrdExperimentWPtr  doc,
QString  name 
)

Definition at line 10 of file qxrdsimpleserver.cpp.

References DEBUG_CONSTRUCTORS, openNewConnection(), qcepDebug(), runModeChanged(), serverPortChanged(), and QcepIntProperty::valueChanged().

10  :
11  QTcpServer(NULL),
12  m_RunSimpleServer(saver, this,"runSimpleServer", 1, "Run Simple Socket Server?"),
13  m_SimpleServerPort(saver, this,"simpleServerPort", 1234, "Port for Simple Socket Server"),
14  m_Experiment(doc),
15  m_Name(name)
16 {
18  printf("QxrdSimpleServer::QxrdSimpleServer(%p)\n", this);
19  }
20 
21  connect(prop_RunSimpleServer(), &QcepIntProperty::valueChanged, this, &QxrdSimpleServer::runModeChanged);
22  connect(prop_SimpleServerPort(), &QcepIntProperty::valueChanged, this, &QxrdSimpleServer::serverPortChanged);
23 
24  connect(this, &QTcpServer::newConnection, this, &QxrdSimpleServer::openNewConnection);
25 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
void valueChanged(int val, int index)
QxrdExperimentWPtr m_Experiment

Here is the call graph for this function:

QxrdSimpleServer::~QxrdSimpleServer ( )
virtual

Definition at line 27 of file qxrdsimpleserver.cpp.

References DEBUG_CONSTRUCTORS, qcepDebug(), and stopServer().

28 {
30  printf("QxrdSimpleServer::~QxrdSimpleServer(%p)\n", this);
31  }
32 
33  stopServer();
34 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26

Here is the call graph for this function:

Member Function Documentation

void QxrdSimpleServer::clientRead ( )
slot

Definition at line 135 of file qxrdsimpleserver.cpp.

References DEBUG_SERVER, executeCommand(), m_Socket, printMessage(), qcepDebug(), and str.

Referenced by openNewConnection().

136 {
137  QTextStream ts( m_Socket );
138 
139  while ( m_Socket->canReadLine() ) {
140  QString str = ts.readLine();
141 
142  if (qcepDebug(DEBUG_SERVER)) {
143  printMessage(tr("Command: %1 received").arg(str));
144  }
145 
146  emit executeCommand(str);
147  }
148 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
void executeCommand(QString cmd)
QTcpSocket * m_Socket
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
#define str(s)

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdSimpleServer::connectionClosed ( )
slot

Definition at line 128 of file qxrdsimpleserver.cpp.

References DEBUG_SERVER, printMessage(), and qcepDebug().

129 {
130  if (qcepDebug(DEBUG_SERVER)) {
131  printMessage("Client closed connection");
132  }
133 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())

Here is the call graph for this function:

void QxrdSimpleServer::criticalMessage ( QString  msg)
protected

Definition at line 83 of file qxrdsimpleserver.cpp.

References m_Experiment.

Referenced by startServer().

84 {
86 
87  if (exp) {
88  exp->criticalMessage(msg);
89  }
90 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QxrdExperimentWPtr m_Experiment

Here is the caller graph for this function:

void QxrdSimpleServer::executeCommand ( QString  cmd)
signal

Referenced by clientRead(), and QxrdExperiment::initialize().

Here is the caller graph for this function:

void QxrdSimpleServer::finishedCommand ( QScriptValue  result)
slot

Definition at line 150 of file qxrdsimpleserver.cpp.

References QxrdScriptEngine::convertToString(), DEBUG_SERVER, m_Socket, printMessage(), and qcepDebug().

Referenced by QxrdExperiment::initialize().

151 {
152  if (qcepDebug(DEBUG_SERVER)) {
153  printMessage(tr("Result: %1").arg(result.toString()));
154  }
155 
156  if (m_Socket && (m_Socket->isWritable())) {
157  m_Socket -> write(qPrintable(QxrdScriptEngine::convertToString(result)+"\n"));
158  }
159 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
QTcpSocket * m_Socket
static QString convertToString(QScriptValue result)
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdSimpleServer::openNewConnection ( )
slot

Definition at line 117 of file qxrdsimpleserver.cpp.

References clientRead(), DEBUG_SERVER, m_Socket, printMessage(), and qcepDebug().

Referenced by QxrdSimpleServer().

118 {
119  m_Socket = nextPendingConnection();
120 
121  connect(m_Socket, &QIODevice::readyRead, this, &QxrdSimpleServer::clientRead);
122 
123  if (qcepDebug(DEBUG_SERVER)) {
124  printMessage(tr("New connection from %1").arg(m_Socket->peerAddress().toString()) );
125  }
126 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
QTcpSocket * m_Socket
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdSimpleServer::printMessage ( QString  msg,
QDateTime  ts = QDateTime::currentDateTime() 
)
protected

Definition at line 74 of file qxrdsimpleserver.cpp.

References m_Experiment.

Referenced by clientRead(), connectionClosed(), finishedCommand(), openNewConnection(), and startServer().

75 {
77 
78  if (exp) {
79  exp->printMessage(msg, ts);
80  }
81 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QxrdExperimentWPtr m_Experiment

Here is the caller graph for this function:

void QxrdSimpleServer::readSettings ( QSettings *  settings,
QString  section 
)
virtual

Definition at line 36 of file qxrdsimpleserver.cpp.

References QcepProperty::readSettings(), and runModeChanged().

37 {
38  QcepProperty::readSettings(this, settings, section);
39 
41 }
static void readSettings(QObject *object, QSettings *settings, QString section)

Here is the call graph for this function:

void QxrdSimpleServer::runModeChanged ( )
slot

Definition at line 48 of file qxrdsimpleserver.cpp.

References startServer(), and stopServer().

Referenced by QxrdSimpleServer(), and readSettings().

49 {
50  if (QThread::currentThread() != thread()) {
51  QMetaObject::invokeMethod(this, "runModeChanged");
52  } else {
53  if (get_RunSimpleServer()) {
54  startServer(QHostAddress::Any, get_SimpleServerPort());
55  } else {
56  stopServer();
57  }
58  }
59 }
void startServer(QHostAddress addr, int port)

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdSimpleServer::serverPortChanged ( )
slot

Definition at line 61 of file qxrdsimpleserver.cpp.

References startServer(), and stopServer().

Referenced by QxrdSimpleServer().

62 {
63  if (QThread::currentThread() != thread()) {
64  QMetaObject::invokeMethod(this, "serverPortChanged");
65  } else {
66  stopServer();
67 
68  if (get_RunSimpleServer()) {
69  startServer(QHostAddress::Any, get_SimpleServerPort());
70  }
71  }
72 }
void startServer(QHostAddress addr, int port)

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdSimpleServer::shutdown ( )
slot

Definition at line 161 of file qxrdsimpleserver.cpp.

162 {
163  close();
164 
165  thread()->exit();
166 }
void QxrdSimpleServer::startServer ( QHostAddress  addr,
int  port 
)

Definition at line 92 of file qxrdsimpleserver.cpp.

References criticalMessage(), DEBUG_SERVER, printMessage(), and qcepDebug().

Referenced by runModeChanged(), and serverPortChanged().

93 {
94  if (qcepDebug(DEBUG_SERVER)) {
95  printMessage(tr("Starting simple server on address %1, port %2")
96  .arg(addr.toString()).arg(port));
97  }
98 
99  setMaxPendingConnections(1);
100 
101  if (isListening()) {
102  close();
103  }
104 
105  if (!listen(addr, port)) {
106  criticalMessage(tr("Failed to bind to address %1 port %2\nIs there another copy of qxrd running already?").arg(addr.toString()).arg(port));
107  }
108 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
void criticalMessage(QString msg)
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdSimpleServer::stopServer ( )

Definition at line 110 of file qxrdsimpleserver.cpp.

Referenced by runModeChanged(), serverPortChanged(), and ~QxrdSimpleServer().

111 {
112  if (isListening()) {
113  close();
114  }
115 }

Here is the caller graph for this function:

void QxrdSimpleServer::writeSettings ( QSettings *  settings,
QString  section 
)
virtual

Definition at line 43 of file qxrdsimpleserver.cpp.

References QcepProperty::writeSettings().

44 {
45  QcepProperty::writeSettings(this, settings, section);
46 }
static void writeSettings(QObject *object, QSettings *settings, QString section)

Here is the call graph for this function:

Member Data Documentation

QxrdExperimentWPtr QxrdSimpleServer::m_Experiment
private

Definition at line 52 of file qxrdsimpleserver.h.

Referenced by criticalMessage(), and printMessage().

QString QxrdSimpleServer::m_Name
private

Definition at line 53 of file qxrdsimpleserver.h.

int QxrdSimpleServer::m_Port
private

Definition at line 54 of file qxrdsimpleserver.h.

QTcpSocket* QxrdSimpleServer::m_Socket
private

Definition at line 55 of file qxrdsimpleserver.h.

Referenced by clientRead(), finishedCommand(), and openNewConnection().

Property Documentation

int QxrdSimpleServer::runSimpleServer
readwrite

Definition at line 20 of file qxrdsimpleserver.h.

int QxrdSimpleServer::simpleServerPort
readwrite

Definition at line 23 of file qxrdsimpleserver.h.


The documentation for this class was generated from the following files: