1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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))
}
}
|