diff options
Diffstat (limited to 'src/Xpl2Client.h')
| -rw-r--r-- | src/Xpl2Client.h | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/Xpl2Client.h b/src/Xpl2Client.h index 44edb65..ef29ddb 100644 --- a/src/Xpl2Client.h +++ b/src/Xpl2Client.h @@ -11,19 +11,20 @@ #include <QHash> #include <QObject> #include <QQmlEngine> -#include <QTcpServer> +#include <QTcpSocket> +#include <QTimer> #include <functional> -class QTcpSocket; - class Xpl2Client : public QObject { Q_OBJECT QML_ELEMENT QML_SINGLETON - Q_PROPERTY (bool listening READ isListening NOTIFY listeningChanged) + Q_PROPERTY (QString host READ host WRITE setHost NOTIFY hostChanged) + Q_PROPERTY (int commandPort READ commandPort WRITE setCommandPort NOTIFY + commandPortChanged) Q_PROPERTY (bool connected READ isConnected NOTIFY connectedChanged) Q_PROPERTY (int controllerId READ controllerId NOTIFY jcVersionReceived) Q_PROPERTY ( @@ -35,7 +36,10 @@ class Xpl2Client : public QObject public: explicit Xpl2Client (QObject *parent = nullptr); - bool isListening () const; + QString host () const; + void setHost (const QString &host); + int commandPort () const; + void setCommandPort (int port); bool isConnected () const; int controllerId () const; @@ -45,8 +49,10 @@ public: static void enableWireDebug (); - Q_INVOKABLE void startListening (); - Q_INVOKABLE void stopListening (); + /** Connect to the proxy on host:commandPort (+1, +2). */ + Q_INVOKABLE void connectToProxy (); + /** Disconnect from the proxy. */ + Q_INVOKABLE void disconnectFromProxy (); /** Get the just connected Jetting Controller ID and Software Version. */ Q_INVOKABLE void getJcVersion (); /** Query the specified printhead's version info. */ @@ -177,7 +183,8 @@ public: Q_INVOKABLE void imageCount (); signals: - void listeningChanged (); + void hostChanged (); + void commandPortChanged (); void connectedChanged (); void errorOccurred (const QString &error); void statusMessage (const QString &message); @@ -286,14 +293,14 @@ signals: void imagingStopResult (bool success); private slots: - void onNewConnection (); + void onSocketConnected (); void onSocketDisconnected (); void onSocketMessageReady (); void onSocketError (QAbstractSocket::SocketError error); + void retryConnection (); private: - void setupServer (QTcpServer &server, quint16 port); - QTcpSocket *&socketForServer (QTcpServer *server); + void setupSocket (QTcpSocket &socket); void sendCommand (QTcpSocket *socket, const QByteArray &command, const QVariantList ¶ms = {}); void dispatchCommandMessage (const Xpl2Protocol::ParsedMessage &msg); @@ -337,16 +344,12 @@ private: void updateConnectedState (); QString logTag (const QTcpSocket *socket) const; - 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; + QString m_host = QStringLiteral ("127.0.0.1"); + quint16 m_commandPort = 9210; + QTcpSocket m_commandSocket; + QTcpSocket m_imagingSocket; + QTcpSocket m_statusSocket; + QTimer m_retryTimer; bool m_connected = false; static bool s_wireDebug; int m_controllerId = 0; |
