1use rill_protocol::config::ConfigPatch;
4use rill_protocol::io::provider::{EntryId, StreamType};
5use serde::Deserialize;
6
7pub static NODE: ConfigPatch<String> = ConfigPatch::new("RR_NODE");
10
11pub static NAME: ConfigPatch<EntryId> = ConfigPatch::new("RR_NAME");
13
14#[derive(Deserialize, Debug, Clone)]
16pub struct EngineConfig {
17 pub node: Option<String>,
20 pub name: Option<EntryId>,
23 pub provider_type: StreamType,
25}
26
27impl EngineConfig {
28 pub fn new(provider_type: StreamType) -> Self {
30 Self {
31 node: None,
32 name: None,
33 provider_type,
34 }
35 }
36}
37
38impl EngineConfig {
39 pub fn is_node_specified(&self) -> bool {
41 NODE.env_var().transpose().is_some() || self.node.is_some()
42 }
43
44 pub fn node_url(&self) -> String {
46 let host = NODE.get(|| self.node.clone(), || "localhost:1636".into());
47 format!("ws://{}/live/provider", host)
48 }
49
50 pub fn provider_name(&self) -> EntryId {
52 NAME.get(
53 || self.name.clone(),
54 || {
55 std::env::current_exe()
56 .ok()
57 .as_ref()
58 .and_then(|path| path.as_path().file_name())
59 .and_then(|path| path.to_str().map(EntryId::from))
60 .unwrap_or_else(|| "rillrate".into())
61 },
62 )
63 }
64
65 pub fn provider_type(&self) -> StreamType {
67 self.provider_type.clone()
68 }
69}