// The main-thread face of the RPC client. Lane GUI. // // Everything the rest of the GUI touches. It owns a worker QThread with an RpcConnection // on it; calls are marshalled onto that thread and their replies come back as a callback // invoked on the main thread. Server notifications are re-emitted as typed Qt signals. // // On reaching Connected it issues the one-shot download.list itself and emits // taskListReset — the table never re-fetches after that, it is maintained from events // (docs/03-gui-spec.md §1). #pragma once #include #include #include #include #include #include #include #include "rpc/Protocol.hpp" namespace velox::gui::rpc { class RpcConnection; class RpcClient : public QObject { Q_OBJECT public: explicit RpcClient(QString socketPath, QObject *parent = nullptr); ~RpcClient() override; ConnectionState state() const noexcept { return state_; } /// Fire a JSON-RPC call. `cb` runs on the main thread; it always runs exactly once, /// with reply.ok() == false if the socket was down or the daemon returned an error. void call(const QString &methodName, const QJsonObject ¶ms, std::function cb = {}); public slots: void start(); void stop(); signals: void stateChanged(velox::gui::rpc::ConnectionState state); /// Full replacement of the table's contents (initial load / reconnect resync). void taskListReset(const QJsonArray &items); void taskAdded(const QJsonObject &summary); void taskProgress(const QJsonArray &tasks); void taskStateChanged(const QJsonObject ¶ms); void taskRemoved(const QString &taskId); void speedGlobal(const QJsonObject ¶ms); void notify(const QJsonObject ¶ms); private slots: void onConnectionState(int state); void onNotification(const QString &methodName, const QJsonObject ¶ms); void onCallCompleted(quint64 tag, const QJsonObject &envelope); private: void requestInitialList(); QThread thread_; RpcConnection *conn_ = nullptr; // owned by thread_ affinity, deleted on thread finish ConnectionState state_ = ConnectionState::Disconnected; quint64 nextTag_ = 1; QHash> callbacks_; }; } // namespace velox::gui::rpc