diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-07-20 14:18:36 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-07-20 14:18:36 +0200 |
| commit | 63a0ec3901a863fb07d18f4b814a98a813644382 (patch) | |
| tree | c94b7b501601b5df05cf654e9f9c9b5bc66a239e /crates/daemon/src/api/server/control.rs | |
| parent | chore: Commit (diff) | |
| download | atuin-63a0ec3901a863fb07d18f4b814a98a813644382.zip | |
chore: Commit
Diffstat (limited to 'crates/daemon/src/api/server/control.rs')
| -rw-r--r-- | crates/daemon/src/api/server/control.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/crates/daemon/src/api/server/control.rs b/crates/daemon/src/api/server/control.rs new file mode 100644 index 00000000..63fef340 --- /dev/null +++ b/crates/daemon/src/api/server/control.rs @@ -0,0 +1,61 @@ +use tonic::{Request, Response, Status}; +use tracing::{Level, instrument}; + +use crate::{ + api::{ + DAEMON_PROTOCOL_VERSION, DAEMON_VERSION, + generated::control::{ + ForceSyncReply, ForceSyncRequest, StatusReply, StatusRequest, + control_server::{Control, ControlServer}, + }, + }, + daemon::DaemonHandle, +}; + +/// The Control gRPC service. +/// +/// This service is used by external processes to inject events into the daemon. +/// It's not a component - it's part of the daemon's core infrastructure. +pub(crate) struct ControlService { + handle: DaemonHandle, +} + +impl ControlService { + /// Create a new control service with the given daemon handle. + pub(crate) fn new(handle: DaemonHandle) -> Self { + Self { handle } + } + + /// Get a tonic server for this service. + pub(crate) fn into_server(self) -> ControlServer<Self> { + ControlServer::new(self) + } +} + +#[tonic::async_trait] +impl Control for ControlService { + #[instrument(skip_all, level = Level::INFO)] + async fn status( + &self, + _request: Request<StatusRequest>, + ) -> Result<Response<StatusReply>, Status> { + let reply = StatusReply { + healthy: true, + version: DAEMON_VERSION.to_owned(), + pid: std::process::id(), + protocol: DAEMON_PROTOCOL_VERSION, + }; + + Ok(Response::new(reply)) + } + + #[instrument(skip_all, level = Level::INFO)] + async fn force_sync( + &self, + _request: Request<ForceSyncRequest>, + ) -> Result<Response<ForceSyncReply>, Status> { + let reply = ForceSyncReply { accepted: false }; + + Ok(Response::new(reply)) + } +} |
