diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-19 22:31:16 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-19 22:31:16 +0100 |
| commit | 364430e417600c68133673254b58b4d35608777a (patch) | |
| tree | 3b4e3471f19239780a2df23ced27c84de266bf95 /src/BobinkClient.h | |
| parent | 5fe029fd127dd70079a01eb6dfbd347954bba9de (diff) | |
| download | BobinkQtOpcUa-364430e417600c68133673254b58b4d35608777a.tar.gz BobinkQtOpcUa-364430e417600c68133673254b58b4d35608777a.zip | |
Reorganize BobinkClient by domain and make s_instance private
Group header and source by domain (Connection, Discovery, PKI) so
properties, methods, and signal handlers live together. Move enums
before constructor, move s_instance to private, and add a public
instance() accessor used by BobinkNode.
Diffstat (limited to 'src/BobinkClient.h')
| -rw-r--r-- | src/BobinkClient.h | 98 |
1 files changed, 54 insertions, 44 deletions
diff --git a/src/BobinkClient.h b/src/BobinkClient.h index 3f36e75..2b41e05 100644 --- a/src/BobinkClient.h +++ b/src/BobinkClient.h @@ -28,16 +28,19 @@ class BobinkClient : public QObject QML_SINGLETON QML_NAMED_ELEMENT (Bobink) + /* -- Connection -- */ Q_PROPERTY (bool connected READ connected NOTIFY connectedChanged) Q_PROPERTY (QString serverUrl READ serverUrl WRITE setServerUrl NOTIFY serverUrlChanged) Q_PROPERTY (BobinkAuth *auth READ auth WRITE setAuth NOTIFY authChanged) + /* -- Discovery -- */ Q_PROPERTY (QString discoveryUrl READ discoveryUrl WRITE setDiscoveryUrl NOTIFY discoveryUrlChanged) Q_PROPERTY (bool discovering READ discovering NOTIFY discoveringChanged) Q_PROPERTY (QVariantList servers READ servers NOTIFY serversChanged) + /* -- PKI -- */ Q_PROPERTY (QString pkiDir READ pkiDir WRITE setPkiDir NOTIFY pkiDirChanged) Q_PROPERTY ( QString certFile READ certFile WRITE setCertFile NOTIFY certFileChanged) @@ -45,46 +48,6 @@ class BobinkClient : public QObject QString keyFile READ keyFile WRITE setKeyFile NOTIFY keyFileChanged) public: - BobinkClient (QObject *parent = nullptr); - // ~BobinkClient () override; - - static inline BobinkClient *s_instance = nullptr; - - // static BobinkClient *instance (); - - /** - * @brief QML singleton factory. - * @note CppOwnership — lives for the process lifetime. - */ - // static BobinkClient *create (QQmlEngine *qmlEngine, QJSEngine *jsEngine); - - bool connected () const; - - QString serverUrl () const; - void setServerUrl (const QString &url); - - BobinkAuth *auth () const; - void setAuth (BobinkAuth *auth); - - QOpcUaClient *opcuaClient () const; - - QString discoveryUrl () const; - void setDiscoveryUrl (const QString &url); - - bool discovering () const; - - const QList<QOpcUaApplicationDescription> &discoveredServers () const; - QVariantList servers () const; - - QString pkiDir () const; - void setPkiDir (const QString &path); - - QString certFile () const; - void setCertFile (const QString &path); - - QString keyFile () const; - void setKeyFile (const QString &path); - enum SecurityMode { SignAndEncrypt = 3, @@ -101,6 +64,18 @@ public: }; Q_ENUM (SecurityPolicy) + BobinkClient (QObject *parent = nullptr); + + /* -- Connection -- */ + + bool connected () const; + + QString serverUrl () const; + void setServerUrl (const QString &url); + + BobinkAuth *auth () const; + void setAuth (BobinkAuth *auth); + /** @brief Discover endpoints, pick the most secure, connect. */ Q_INVOKABLE void connectToServer (); /** @brief Connect directly without endpoint discovery. */ @@ -112,19 +87,45 @@ public: /** @brief Reject the pending server certificate. */ Q_INVOKABLE void rejectCertificate (); + /* -- Discovery -- */ + + QString discoveryUrl () const; + void setDiscoveryUrl (const QString &url); + + bool discovering () const; + + const QList<QOpcUaApplicationDescription> &discoveredServers () const; + QVariantList servers () const; + Q_INVOKABLE void startDiscovery (); Q_INVOKABLE void stopDiscovery (); + /* -- PKI -- */ + + QString pkiDir () const; + void setPkiDir (const QString &path); + + QString certFile () const; + void setCertFile (const QString &path); + + QString keyFile () const; + void setKeyFile (const QString &path); + /** @brief Auto-detect cert/key from the PKI directory and apply. */ Q_INVOKABLE void autoDetectPki (); /** @brief Apply PKI dirs and cert/key. Call before connecting. */ Q_INVOKABLE void applyPki (); + /* -- C++ only -- */ + + static BobinkClient *instance (); + QOpcUaClient *opcuaClient () const; + signals: + /* -- Connection -- */ void connectedChanged (); void serverUrlChanged (); void authChanged (); - /** * @brief Emitted when the server presents an untrusted cert. * @@ -135,20 +136,26 @@ signals: void connectionError (const QString &message); void statusMessage (const QString &message); + /* -- Discovery -- */ void discoveryUrlChanged (); void discoveringChanged (); void serversChanged (); + + /* -- PKI -- */ void pkiDirChanged (); void certFileChanged (); void keyFileChanged (); private slots: + /* -- Connection -- */ void handleStateChanged (QOpcUaClient::ClientState state); void handleEndpointsReceived (const QList<QOpcUaEndpointDescription> &endpoints, QOpcUa::UaStatusCode statusCode, const QUrl &requestUrl); void handleConnectError (QOpcUaErrorState *errorState); + + /* -- Discovery -- */ void handleFindServersFinished ( const QList<QOpcUaApplicationDescription> &servers, QOpcUa::UaStatusCode statusCode, const QUrl &requestUrl); @@ -157,26 +164,29 @@ private slots: private: void setupClient (); + /* -- Connection -- */ QOpcUaProvider *m_provider = nullptr; QOpcUaClient *m_client = nullptr; BobinkAuth *m_auth = nullptr; QString m_serverUrl; bool m_connected = false; - - // Certificate trust event loop — see handleConnectError(). QEventLoop *m_certLoop = nullptr; bool m_certAccepted = false; + /* -- Discovery -- */ QString m_discoveryUrl; qint32 m_discoveryInterval = 30000; // ms QTimer m_discoveryTimer; bool m_discovering = false; QList<QOpcUaApplicationDescription> m_discoveredServers; + QVariantList m_serversCache; + /* -- PKI -- */ QString m_pkiDir; QString m_certFile; QString m_keyFile; - QVariantList m_serversCache; + + static inline BobinkClient *s_instance = nullptr; }; #endif // BOBINKCLIENT_H |
