diff --git a/copper/src/config.rs b/copper/src/config.rs index 18799ea85..75c9c6591 100644 --- a/copper/src/config.rs +++ b/copper/src/config.rs @@ -76,37 +76,37 @@ impl From for String { #[derive(Serialize, Deserialize, Debug)] pub struct Node { - instance_name: String, - #[serde(skip_serializing_if = "Option::is_none")] - type_name: Option, + id: String, + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + type_: Option, #[serde(skip_serializing_if = "Option::is_none")] base_period_ns: Option, #[serde(skip_serializing_if = "Option::is_none")] - instance_config: Option, + config: Option, } impl Node { - pub fn new(name: &str, ptype: &str) -> Self { + pub fn new(id: &str, ptype: &str) -> Self { Node { - instance_name: name.to_string(), - type_name: Some(ptype.to_string()), + id: id.to_string(), + type_: Some(ptype.to_string()), base_period_ns: None, - instance_config: None, + config: None, } } #[allow(dead_code)] - pub fn set_type_name(mut self, type_name: Option) -> Self { - self.type_name = type_name; + pub fn set_type(mut self, name: Option) -> Self { + self.type_ = name; self } - pub fn get_type_name(&self) -> &str { - self.type_name.as_ref().unwrap() + pub fn get_type(&self) -> &str { + self.type_.as_ref().unwrap() } pub fn get_instance_config(&self) -> Option<&NodeInstanceConfig> { - self.instance_config.as_ref() + self.config.as_ref() } #[allow(dead_code)] @@ -123,16 +123,16 @@ impl Node { } pub fn get_param>(&self, key: &str) -> Option { - let pc = self.instance_config.as_ref()?; + let pc = self.config.as_ref()?; let v = pc.get(key)?; Some(T::from(v.clone())) } pub fn set_param>(&mut self, key: &str, value: T) { - if self.instance_config.is_none() { - self.instance_config = Some(HashMap::new()); + if self.config.is_none() { + self.config = Some(HashMap::new()); } - self.instance_config + self.config .as_mut() .unwrap() .insert(key.to_string(), value.into()); @@ -241,9 +241,9 @@ mod tests { #[test] fn test_base_period() { let node = Node { - instance_name: "test".to_string(), - type_name: Some("test".to_string()), - instance_config: Some(HashMap::new()), + id: "test".to_string(), + type_: Some("test".to_string()), + config: Some(HashMap::new()), base_period_ns: Some(1_000_000_000), }; assert_eq!(node.base_period(), Some(Time::new::(1.into()))); diff --git a/copper_derive/src/lib.rs b/copper_derive/src/lib.rs index d5c3e274e..985fe1b1c 100644 --- a/copper_derive/src/lib.rs +++ b/copper_derive/src/lib.rs @@ -135,7 +135,7 @@ fn extract_tasks_types(copper_config: &CuConfig) -> (Vec, Vec) { // Collect all the type names used by our configs. let all_types_names: Vec = all_nodes .iter() - .map(|node_config| node_config.get_type_name().to_string()) + .map(|node_config| node_config.get_type().to_string()) .collect(); // Transform them as Rust types diff --git a/copper_derive_test/copperconfig.ron b/copper_derive_test/copperconfig.ron index a4e248563..9007d98be 100644 --- a/copper_derive_test/copperconfig.ron +++ b/copper_derive_test/copperconfig.ron @@ -2,32 +2,32 @@ graph: ( nodes: [ ( - instance_name: "camera", - type_name: "v4lsrc::Video4LinuxSource", + id: "monitoring", + type: "copper::monitoring::MonitoringTask", + base_period_ns: 60000000000, + ), + ( + id: "camera", + type: "v4lsrc::Video4LinuxSource", base_period_ns: 1000000000, - instance_config: { + config: { "dev": "/dev/video0", }, ), ( - instance_name: "logger", - type_name: "simplelogger::SimpleLogger", + id: "logger", + type: "simplelogger::SimpleLogger", base_period_ns: 60000000000, - instance_config: { + config: { "path": "/tmp/stuff.cu", }, ), - ( - instance_name: "monitoring", - type_name: "copper::monitoring::MonitoringTask", - base_period_ns: 60000000000, - ), ], node_holes: [], edge_property: directed, edges: [ - (0, 1, "v4lsrc::ImageMsg"), - (2, 1, "()"), + (1, 2, "v4lsrc::ImageMsg"), + (0, 2, "()"), ], ), )