#pragma once // VeloxDispatcher implements the generated velox::proto::Dispatcher — one virtual per RPC // method. The generated dispatch() does the envelope, the transport check and the param // parse; a method here only ever sees a validated, typed params struct and returns a // typed result. // // Scope of this drop (AGENT-DAEMON.md build order): the transports are real and the store // is behind download.add / download.list / download.get. session.hello / session.pair / // session.subscribe are handled in the server layer (connection- and transport-stateful) // and never reach this class in the running daemon. Everything else still returns // "not implemented in this build" (-> -32603) until its handler and the scheduler land; // see daemon/docs/deferrals.md. #include #include "rpc/event_hub.hpp" #include "rpc/task_action_port.hpp" #include "store/sqlite.hpp" #include "velox_proto.hpp" namespace velox::daemon::rpc { class VeloxDispatcher final : public velox::proto::Dispatcher { public: // `actions` drives download.pause/resume/start/cancel and queue.start/stop // immediately (D4b) — those cannot wait for the next tick(), unlike download.add's // on_mutation nudge. Optional so existing tests that only exercise download.add/list/ // get keep building with no scheduler at hand; a null actions_ makes those methods // answer "not implemented" instead of crashing. See rpc/task_action_port.hpp for why // this is an interface owned by rpc/ rather than a direct sched::Scheduler* (avoids a // veloxd_rpc <-> veloxd_sched circular library dependency). VeloxDispatcher(velox::daemon::store::Db& db, EventHub& hub, TaskActionPort* actions = nullptr) : db_(db), hub_(hub), actions_(actions) {} // Called after a handler mutates task state (download.add for now). main.cpp wires it // to nudge the scheduler; unset in tests. void set_on_mutation(std::function fn) { on_mutation_ = std::move(fn); } velox::proto::HandlerResult on_capture_getRules(const velox::proto::CaptureGetRulesParams&) override; velox::proto::HandlerResult on_capture_offer(const velox::proto::CaptureOfferParams&) override; velox::proto::HandlerResult on_category_list(const velox::proto::CategoryListParams&) override; velox::proto::HandlerResult on_category_remove(const velox::proto::CategoryRemoveParams&) override; velox::proto::HandlerResult on_category_upsert(const velox::proto::CategoryUpsertParams&) override; velox::proto::HandlerResult on_download_add(const velox::proto::DownloadSpec&) override; velox::proto::HandlerResult on_download_addBatch(const velox::proto::DownloadAddBatchParams&) override; velox::proto::HandlerResult on_download_cancel(const velox::proto::DownloadCancelParams&) override; velox::proto::HandlerResult on_download_get(const velox::proto::DownloadGetParams&) override; velox::proto::HandlerResult on_download_list(const velox::proto::DownloadListParams&) override; velox::proto::HandlerResult on_download_pause(const velox::proto::DownloadPauseParams&) override; velox::proto::HandlerResult on_download_probe(const velox::proto::DownloadProbeParams&) override; velox::proto::HandlerResult on_download_provideAuth(const velox::proto::DownloadProvideAuthParams&) override; velox::proto::HandlerResult on_download_refreshUrl(const velox::proto::DownloadRefreshUrlParams&) override; velox::proto::HandlerResult on_download_remove(const velox::proto::DownloadRemoveParams&) override; velox::proto::HandlerResult on_download_resume(const velox::proto::DownloadResumeParams&) override; velox::proto::HandlerResult on_download_start(const velox::proto::DownloadStartParams&) override; velox::proto::HandlerResult on_download_update(const velox::proto::DownloadUpdateParams&) override; velox::proto::HandlerResult on_grabber_harvest(const velox::proto::GrabberHarvestParams&) override; velox::proto::HandlerResult on_grabber_start(const velox::proto::GrabberStartParams&) override; velox::proto::HandlerResult on_grabber_status(const velox::proto::GrabberStatusParams&) override; velox::proto::HandlerResult on_limiter_get(const velox::proto::LimiterGetParams&) override; velox::proto::HandlerResult on_limiter_set(const velox::proto::Limiter&) override; velox::proto::HandlerResult on_media_addVariant(const velox::proto::MediaAddVariantParams&) override; velox::proto::HandlerResult on_media_listVariants(const velox::proto::MediaListVariantsParams&) override; velox::proto::HandlerResult on_queue_list(const velox::proto::QueueListParams&) override; velox::proto::HandlerResult on_queue_reorder(const velox::proto::QueueReorderParams&) override; velox::proto::HandlerResult on_queue_start(const velox::proto::QueueStartParams&) override; velox::proto::HandlerResult on_queue_stop(const velox::proto::QueueStopParams&) override; velox::proto::HandlerResult on_queue_upsert(const velox::proto::QueueUpsertParams&) override; velox::proto::HandlerResult on_rules_list(const velox::proto::RulesListParams&) override; velox::proto::HandlerResult on_rules_upsert(const velox::proto::RulesUpsertParams&) override; velox::proto::HandlerResult on_schedule_get(const velox::proto::ScheduleGetParams&) override; velox::proto::HandlerResult on_schedule_set(const velox::proto::ScheduleSetParams&) override; velox::proto::HandlerResult on_session_hello(const velox::proto::SessionHelloParams&) override; velox::proto::HandlerResult on_session_pair(const velox::proto::SessionPairParams&) override; velox::proto::HandlerResult on_session_subscribe(const velox::proto::SessionSubscribeParams&) override; velox::proto::HandlerResult on_settings_get(const velox::proto::SettingsGetParams&) override; velox::proto::HandlerResult on_settings_set(const velox::proto::SettingsSetParams&) override; private: // The whole of download.add's body; on_download_add and on_download_addBatch (each // item merged against DownloadAddBatchParams.defaults first) both call this — exactly // one place turns a DownloadSpec into a stored, admitted task. velox::proto::HandlerResult add_one( const velox::proto::DownloadSpec& spec); velox::daemon::store::Db& db_; EventHub& hub_; TaskActionPort* actions_; std::function on_mutation_; }; } // namespace velox::daemon::rpc