1pub mod proto {
2 #![allow(clippy::derive_partial_eq_without_eq)]
3
4 include!(concat!(env!("OUT_DIR"), "/ya_runtime_api.rs"));
5
6 impl response::Error {
7 pub fn msg<D: std::fmt::Display>(msg: D) -> Self {
8 let mut e = Self::default();
9 e.set_code(response::ErrorCode::Internal);
10 e.message = msg.to_string();
11 e
12 }
13 }
14}
15mod codec;
16
17#[cfg(feature = "codec")]
18pub use codec::Codec;
19pub use proto::request::{CreateNetwork, KillProcess, RunProcess};
20pub use proto::response::create_network::Endpoint as NetworkEndpoint;
21pub use proto::response::runtime_status::Counter as RuntimeCounter;
22pub use proto::response::runtime_status::Kind as RuntimeStatusKind;
23pub use proto::response::runtime_status::State as RuntimeState;
24pub use proto::response::CreateNetwork as CreateNetworkResp;
25pub use proto::response::Error as ErrorResponse;
26pub use proto::response::RunProcess as RunProcessResp;
27pub use proto::response::{ErrorCode, ProcessStatus, RuntimeStatus};
28pub use proto::{Network, NetworkInterface};
29
30use futures::future::{BoxFuture, LocalBoxFuture};
31use futures::prelude::*;
32use std::process::{ExitStatus, Stdio};
33use std::sync::Arc;
34use tokio::process;
35
36pub type AsyncResponse<'a, T> = LocalBoxFuture<'a, Result<T, ErrorResponse>>;
37
38pub trait RuntimeService {
40 fn hello(&self, version: &str) -> AsyncResponse<'_, String>;
42 fn run_process(&self, run: RunProcess) -> AsyncResponse<'_, RunProcessResp>;
44 fn kill_process(&self, kill: KillProcess) -> AsyncResponse<'_, ()>;
46 fn create_network(&self, network: CreateNetwork) -> AsyncResponse<'_, CreateNetworkResp>;
48 fn shutdown(&self) -> AsyncResponse<'_, ()>;
50}
51
52pub trait RuntimeHandler {
54 fn on_process_status<'a>(&self, status: ProcessStatus) -> BoxFuture<'a, ()>;
56 fn on_runtime_status<'a>(&self, status: RuntimeStatus) -> BoxFuture<'a, ()>;
58}
59
60pub trait RuntimeControl {
62 fn id(&self) -> u32;
64 fn stop(&self);
66 fn stopped(&self) -> BoxFuture<'_, i32>;
68}
69
70mod client;
71mod service;
72
73pub use client::spawn;
74pub use service::{run, run_async};