Common/IPC/IPCProvider.rs
1//! # IPCProvider Trait
2//!
3//! Defines the abstract service trait for inter-process communication (IPC)
4//! capabilities.
5
6use async_trait::async_trait;
7use serde_json::Value;
8
9use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
10
11/// An abstract service contract for an environment component that can
12/// communicate with external sidecar processes (like `Cocoon`).
13///
14/// This trait is implemented by `MountainEnvironment` and typically uses gRPC
15/// as the underlying transport mechanism to send and receive messages.
16#[async_trait]
17pub trait IPCProvider: Environment + Send + Sync {
18 /// Sends a notification (a fire-and-forget message) to a specified
19 /// sidecar. This method does not wait for a response.
20 ///
21 /// # Parameters
22 /// * `SideCarIdentifier`: The unique ID of the target sidecar process.
23 /// * `Method`: The name of the notification method to be invoked on the
24 /// sidecar.
25 /// * `Parameters`: A `serde_json::Value` containing the parameters for the
26 /// notification.
27 async fn SendNotificationToSideCar(
28 &self,
29
30 SideCarIdentifier:String,
31
32 Method:String,
33
34 Parameters:Value,
35 ) -> Result<(), CommonError>;
36
37 /// Sends a request to a specified sidecar and awaits a response.
38 ///
39 /// # Parameters
40 /// * `SideCarIdentifier`: The unique ID of the target sidecar process.
41 /// * `Method`: The name of the RPC method to be invoked on the sidecar.
42 /// * `Parameters`: A `serde_json::Value` containing the parameters for the
43 /// request.
44 /// * `TimeoutMilliseconds`: The maximum time to wait for a response before
45 /// failing.
46 ///
47 /// # Returns
48 /// A `Result` containing the `serde_json::Value` response from the
49 /// sidecar.
50 async fn SendRequestToSideCar(
51 &self,
52
53 SideCarIdentifier:String,
54
55 Method:String,
56
57 Parameters:Value,
58
59 TimeoutMilliseconds:u64,
60 ) -> Result<Value, CommonError>;
61}