1use crate::registry::InterfaceRegistry;
4use std::sync::Arc;
5use synapse_proto::{RpcRequest, RpcResponse, RpcStatus};
6use tracing::{info, warn};
7
8pub struct RpcServer {
10 registry: Arc<InterfaceRegistry>,
11}
12
13impl RpcServer {
14 pub fn new() -> Self {
15 Self {
16 registry: Arc::new(InterfaceRegistry::new()),
17 }
18 }
19
20 pub fn registry(&self) -> &Arc<InterfaceRegistry> {
21 &self.registry
22 }
23
24 pub async fn handle_request(&self, request: RpcRequest) -> RpcResponse {
26 info!(
27 "Handling RPC request: interface={:?}, method={:?}",
28 request.interface_id, request.method_id
29 );
30
31 let response = self.registry.route(request).await;
32
33 if response.status != RpcStatus::Ok as i32 {
34 warn!("RPC request failed: status={}", response.status);
35 }
36
37 response
38 }
39}
40
41impl Default for RpcServer {
42 fn default() -> Self {
43 Self::new()
44 }
45}