// Shared RPC vocabulary for the GUI client. Lane GUI. // // The wire is JSON-RPC 2.0 over the Unix socket, newline-delimited (one object per line) — // exactly what tools/mockd and the real veloxd speak on the UDS transport. This header // carries only the small enums and structs the rpc/ layer passes around; the payload // *types* live in libveloxproto and are parsed at the model boundary. #pragma once #include #include #include #include namespace velox::gui::rpc { /// Where the connection is, for the status-bar dot and the offline banner. Anything other /// than Connected means the table is stale and toolbar actions should be disabled. enum class ConnectionState { Disconnected, ///< start() not called yet, or stop() was called Connecting, ///< TCP/UDS connect in flight Handshaking, ///< socket up; session.hello / session.subscribe in flight Connected, ///< handshake done, events flowing Reconnecting, ///< lost the socket, backing off before the next attempt }; /// Bare label for the status bar. Not tr()'d here — callers wrap it. inline const char *toString(ConnectionState s) noexcept { switch (s) { case ConnectionState::Disconnected: return "Disconnected"; case ConnectionState::Connecting: return "Connecting"; case ConnectionState::Handshaking: return "Connecting"; case ConnectionState::Connected: return "Connected"; case ConnectionState::Reconnecting: return "Reconnecting"; } return "Unknown"; } /// A JSON-RPC error object, or the absence of one (code == 0). struct RpcError { int code = 0; QString message; QJsonValue data; bool isError() const noexcept { return code != 0; } }; /// The outcome of one call: exactly one of result / error is meaningful. struct RpcReply { QJsonValue result; RpcError error; bool ok() const noexcept { return !error.isError(); } }; // --- method names --------------------------------------------------------------------- namespace method { inline constexpr auto kSessionHello = "session.hello"; inline constexpr auto kSessionSubscribe = "session.subscribe"; inline constexpr auto kDownloadList = "download.list"; inline constexpr auto kDownloadGet = "download.get"; inline constexpr auto kDownloadStart = "download.start"; inline constexpr auto kDownloadPause = "download.pause"; inline constexpr auto kDownloadResume = "download.resume"; inline constexpr auto kDownloadCancel = "download.cancel"; inline constexpr auto kDownloadRemove = "download.remove"; inline constexpr auto kDownloadProbe = "download.probe"; inline constexpr auto kDownloadAdd = "download.add"; inline constexpr auto kDownloadAddBatch = "download.addBatch"; inline constexpr auto kCategoryList = "category.list"; inline constexpr auto kQueueList = "queue.list"; inline constexpr auto kQueueUpsert = "queue.upsert"; inline constexpr auto kQueueReorder = "queue.reorder"; inline constexpr auto kQueueStart = "queue.start"; inline constexpr auto kQueueStop = "queue.stop"; inline constexpr auto kScheduleGet = "schedule.get"; inline constexpr auto kScheduleSet = "schedule.set"; inline constexpr auto kSettingsGet = "settings.get"; inline constexpr auto kSettingsSet = "settings.set"; inline constexpr auto kLimiterGet = "limiter.get"; inline constexpr auto kLimiterSet = "limiter.set"; inline constexpr auto kGrabberStart = "grabber.start"; inline constexpr auto kGrabberStatus = "grabber.status"; inline constexpr auto kGrabberHarvest = "grabber.harvest"; } // namespace method // --- event names --------------------------------------------------------------------- namespace event { inline constexpr auto kTaskAdded = "event.task.added"; inline constexpr auto kTaskRemoved = "event.task.removed"; inline constexpr auto kTaskState = "event.task.state"; inline constexpr auto kTaskProgress = "event.task.progress"; inline constexpr auto kSpeedGlobal = "event.speed.global"; inline constexpr auto kNotify = "event.notify"; inline constexpr auto kSettingsChanged = "event.settings.changed"; inline constexpr auto kGrabberProgress = "event.grabber.progress"; } // namespace event } // namespace velox::gui::rpc Q_DECLARE_METATYPE(velox::gui::rpc::RpcReply) Q_DECLARE_METATYPE(velox::gui::rpc::ConnectionState)