aboutsummaryrefslogtreecommitdiffstats
path: root/src/Xpl2Client.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xpl2Client.h')
-rw-r--r--src/Xpl2Client.h35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/Xpl2Client.h b/src/Xpl2Client.h
index 838c344..44edb65 100644
--- a/src/Xpl2Client.h
+++ b/src/Xpl2Client.h
@@ -11,17 +11,19 @@
#include <QHash>
#include <QObject>
#include <QQmlEngine>
-#include <QTcpSocket>
+#include <QTcpServer>
#include <functional>
+class QTcpSocket;
+
class Xpl2Client : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
- Q_PROPERTY (QString host READ host WRITE setHost NOTIFY hostChanged)
+ Q_PROPERTY (bool listening READ isListening NOTIFY listeningChanged)
Q_PROPERTY (bool connected READ isConnected NOTIFY connectedChanged)
Q_PROPERTY (int controllerId READ controllerId NOTIFY jcVersionReceived)
Q_PROPERTY (
@@ -33,9 +35,7 @@ class Xpl2Client : public QObject
public:
explicit Xpl2Client (QObject *parent = nullptr);
- QString host () const;
- void setHost (const QString &host);
-
+ bool isListening () const;
bool isConnected () const;
int controllerId () const;
@@ -45,8 +45,8 @@ public:
static void enableWireDebug ();
- Q_INVOKABLE void connectToServer ();
- Q_INVOKABLE void disconnectFromServer ();
+ Q_INVOKABLE void startListening ();
+ Q_INVOKABLE void stopListening ();
/** Get the just connected Jetting Controller ID and Software Version. */
Q_INVOKABLE void getJcVersion ();
/** Query the specified printhead's version info. */
@@ -177,7 +177,7 @@ public:
Q_INVOKABLE void imageCount ();
signals:
- void hostChanged ();
+ void listeningChanged ();
void connectedChanged ();
void errorOccurred (const QString &error);
void statusMessage (const QString &message);
@@ -286,18 +286,20 @@ signals:
void imagingStopResult (bool success);
private slots:
- void onSocketConnected ();
+ void onNewConnection ();
void onSocketDisconnected ();
void onSocketMessageReady ();
void onSocketError (QAbstractSocket::SocketError error);
private:
- void sendCommand (QTcpSocket &socket, const QByteArray &command,
+ void setupServer (QTcpServer &server, quint16 port);
+ QTcpSocket *&socketForServer (QTcpServer *server);
+ void sendCommand (QTcpSocket *socket, const QByteArray &command,
const QVariantList &params = {});
void dispatchCommandMessage (const Xpl2Protocol::ParsedMessage &msg);
void dispatchImagingMessage (const Xpl2Protocol::ParsedMessage &msg);
void dispatchStatusMessage (const Xpl2Protocol::ParsedMessage &msg);
- void handleKaPing (QTcpSocket &socket);
+ void handleKaPing (QTcpSocket *socket);
void handleGsJcVersion (const QVariantList &params);
void handleGsPhVersion (const QVariantList &params);
enum class ResponseShape
@@ -335,13 +337,16 @@ private:
void updateConnectedState ();
QString logTag (const QTcpSocket *socket) const;
- QTcpSocket m_commandSocket;
- QTcpSocket m_imagingSocket;
- QTcpSocket m_statusSocket;
- QString m_host = QStringLiteral ("127.0.0.1");
+ QTcpServer m_commandServer;
+ QTcpServer m_imagingServer;
+ QTcpServer m_statusServer;
+ QTcpSocket *m_commandSocket = nullptr;
+ QTcpSocket *m_imagingSocket = nullptr;
+ QTcpSocket *m_statusSocket = nullptr;
quint16 m_commandPort = 9110;
quint16 m_imagingPort = 9111;
quint16 m_statusPort = 9112;
+ bool m_listening = false;
bool m_connected = false;
static bool s_wireDebug;
int m_controllerId = 0;