From e32c6d7c8959046a1cedc08f536ce566ff96c7ac Mon Sep 17 00:00:00 2001 From: Ash Beitz <8304894+ashbeitz@users.noreply.github.com> Date: Thu, 9 May 2024 15:18:14 -0700 Subject: [PATCH] Digital Twin Graph --- .../src/digital_twin_registry_impl.rs | 26 ++++++ digital-twin-model/src/sdv_v1.rs | 81 +++++++++---------- .../digital_twin_graph/consumer/src/main.rs | 5 +- .../src/request_impl.rs | 2 +- .../vehicle_core_provider/src/main.rs | 6 +- samples/seat_massager/consumer/src/main.rs | 2 +- .../provider/src/request_impl.rs | 2 +- 7 files changed, 70 insertions(+), 54 deletions(-) diff --git a/core/module/digital_twin_registry/src/digital_twin_registry_impl.rs b/core/module/digital_twin_registry/src/digital_twin_registry_impl.rs index 73f7d31e..2fea764f 100644 --- a/core/module/digital_twin_registry/src/digital_twin_registry_impl.rs +++ b/core/module/digital_twin_registry/src/digital_twin_registry_impl.rs @@ -137,6 +137,32 @@ impl DigitalTwinRegistryImpl { fn register_entity(&self, entity_access_info: EntityAccessInfo) -> Result<(), String> { // This block controls the lifetime of the lock. { + if entity_access_info.provider_id.is_empty() { + return Err("Provider id cannot be empty".to_string()); + } + + if entity_access_info.model_id.is_empty() { + return Err("Model id cannot be empty".to_string()); + } + + if entity_access_info.instance_id.is_empty() { + return Err("Instance id cannot be empty".to_string()); + } + + if entity_access_info.protocol.is_empty() { + return Err("Protocol cannot be empty".to_string()); + } + + if entity_access_info.uri.is_empty() { + return Err("Uri cannot be empty".to_string()); + } + + if entity_access_info.operations.is_empty() { + return Err("Operations cannot be empty".to_string()); + } + + // Note: the context is optional. + let mut lock: RwLockWriteGuard>> = self.entity_access_info_map.write(); let get_result = lock.get(&entity_access_info.model_id); diff --git a/digital-twin-model/src/sdv_v1.rs b/digital-twin-model/src/sdv_v1.rs index f1932662..69e0cc72 100644 --- a/digital-twin-model/src/sdv_v1.rs +++ b/digital-twin-model/src/sdv_v1.rs @@ -41,7 +41,7 @@ pub mod airbag_seat_massager { ))] pub model_id: String, pub sequence_name: String, - pub sequence: crate::sdv_v1::airbag_seat_massager::massage_step::TYPE, + pub sequence: crate::sdv_v1::airbag_seat_massager::massage_step::SCHEMA_TYPE, } } @@ -62,7 +62,7 @@ pub mod airbag_seat_massager { value = "crate::sdv_v1::airbag_seat_massager::store_sequence::response::ID.to_string()" ))] pub model_id: String, - pub status: crate::sdv_v1::airbag_seat_massager::status::TYPE, + pub status: crate::sdv_v1::airbag_seat_massager::status::SCHEMA_TYPE, } } } @@ -89,7 +89,7 @@ pub mod airbag_seat_massager { value = "crate::sdv_v1::airbag_seat_massager::perform_step::request::ID.to_string()" ))] pub model_id: String, - pub step: crate::sdv_v1::airbag_seat_massager::massage_step::TYPE, + pub step: crate::sdv_v1::airbag_seat_massager::massage_step::SCHEMA_TYPE, } } @@ -110,7 +110,7 @@ pub mod airbag_seat_massager { value = "crate::sdv_v1::airbag_seat_massager::perform_step::response::ID.to_string()" ))] pub model_id: String, - pub status: crate::sdv_v1::airbag_seat_massager::status::TYPE, + pub status: crate::sdv_v1::airbag_seat_massager::status::SCHEMA_TYPE, } } } @@ -121,7 +121,7 @@ pub mod airbag_seat_massager { pub const DESCRIPTION: &str = "An airbag adjustment."; #[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug)] - pub struct TYPE { + pub struct SCHEMA_TYPE { pub airbag_identifier: i32, pub inflation_level: i32, pub inflation_duration_in_seconds: i32, @@ -133,7 +133,8 @@ pub mod airbag_seat_massager { pub const NAME: &str = "massage_step"; pub const DESCRIPTION: &str = "The massage step."; - pub type TYPE = Vec; + pub type SCHEMA_TYPE = + Vec; } pub mod status { @@ -142,7 +143,7 @@ pub mod airbag_seat_massager { pub const DESCRIPTION: &str = "The status."; #[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug, Default)] - pub struct TYPE { + pub struct SCHEMA_TYPE { pub code: i32, pub message: String, } @@ -167,7 +168,7 @@ pub mod basic_airbag_seat_massager { value = "crate::sdv_v1::basic_airbag_seat_massager::ID.to_string()" ))] pub model_id: String, - pub sequence_names: crate::sdv_v1::seat_massager::sequence_names::TYPE, + pub sequence_names: crate::sdv_v1::seat_massager::sequence_names::SCHEMA_TYPE, } } @@ -187,8 +188,6 @@ pub mod cabin { #[serde(rename = "@id")] pub instance_id: String, } - - pub type TYPE = Vec; } pub mod hvac { @@ -203,8 +202,6 @@ pub mod cabin { #[serde(rename = "@id")] pub instance_id: String, } - - pub type TYPE = Vec; } pub mod seat { @@ -235,8 +232,6 @@ pub mod cabin { pub seat_row: SEAT_ROW_TYPE, pub seat_position: SEAT_POSITION_TYPE, } - - pub type TYPE = Vec; } #[derive(derivative::Derivative)] @@ -251,9 +246,9 @@ pub mod cabin { #[serde(rename = "@type")] #[derivative(Default(value = "crate::sdv_v1::cabin::ID.to_string()"))] pub model_id: String, - pub infotainment: crate::sdv_v1::cabin::infotainment::TYPE, - pub hvac: crate::sdv_v1::cabin::hvac::TYPE, - pub seat: crate::sdv_v1::cabin::seat::TYPE, + pub infotainment: Vec, + pub hvac: Vec, + pub seat: Vec, } } @@ -270,7 +265,7 @@ pub mod camera { #[derive(derivative::Derivative)] #[derivative(Default)] #[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug)] - pub struct TYPE { + pub struct PAYLOAD_TYPE { #[serde(rename = "@context")] #[derivative(Default(value = "crate::sdv_v1::context()"))] pub context: Vec, @@ -294,7 +289,7 @@ pub mod camera { #[serde(rename = "@type")] #[derivative(Default(value = "crate::sdv_v1::camera::ID.to_string()"))] pub model_id: String, - } + } } pub mod hmi { @@ -335,7 +330,7 @@ pub mod hmi { #[derive(derivative::Derivative)] #[derivative(Default)] #[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug)] - pub struct TYPE { + pub struct PAYLOAD_TYPE { #[serde(rename = "@context")] #[derivative(Default(value = "crate::sdv_v1::context()"))] pub context: Vec, @@ -344,7 +339,7 @@ pub mod hmi { value = "crate::sdv_v1::hmi::show_notification::response::ID.to_string()" ))] pub model_id: String, - pub status: crate::sdv_v1::hmi::status::TYPE, + pub status: crate::sdv_v1::hmi::status::SCHEMA_TYPE, } } } @@ -361,7 +356,7 @@ pub mod hmi { #[serde(rename = "@type")] #[derivative(Default(value = "crate::sdv_v1::hmi::ID.to_string()"))] pub model_id: String, - } + } pub mod status { pub const ID: &str = "dtmi:sdv:hmi:status;1"; @@ -369,7 +364,7 @@ pub mod hmi { pub const DESCRIPTION: &str = "The status."; #[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug, Default)] - pub struct TYPE { + pub struct SCHEMA_TYPE { pub code: i32, pub message: String, } @@ -385,7 +380,7 @@ pub mod hvac { pub const NAME: &str = "ambient_air_temperature"; pub const DESCRIPTION: &str = "The immediate surroundings air temperature (in Fahrenheit)."; - pub type TYPE = i32; + pub type SCHEMA_TYPE = i32; } pub mod is_air_conditioning_active { @@ -393,7 +388,7 @@ pub mod hvac { pub const NAME: &str = "is_air_conditioning_active"; pub const DESCRIPTION: &str = "Is air conditioning active?"; - pub type TYPE = bool; + pub type SCHEMA_TYPE = bool; } #[derive(derivative::Derivative)] @@ -408,7 +403,7 @@ pub mod hvac { #[serde(rename = "@type")] #[derivative(Default(value = "crate::sdv_v1::hvac::ID.to_string()"))] pub model_id: String, - } + } } pub mod obd { @@ -420,7 +415,7 @@ pub mod obd { pub const NAME: &str = "hybrid_battery_remaining"; pub const DESCRIPTION: &str = "The remaining hybrid battery life."; - pub type TYPE = i32; + pub type SCHEMA_TYPE = i32; } #[derive(derivative::Derivative)] @@ -435,7 +430,7 @@ pub mod obd { #[serde(rename = "@type")] #[derivative(Default(value = "crate::sdv_v1::obd::ID.to_string()"))] pub model_id: String, - } + } } pub mod premium_airbag_seat_massager { @@ -456,7 +451,7 @@ pub mod premium_airbag_seat_massager { value = "crate::sdv_v1::premium_airbag_seat_massager::ID.to_string()" ))] pub model_id: String, - pub sequence_names: crate::sdv_v1::seat_massager::sequence_names::TYPE, + pub sequence_names: crate::sdv_v1::seat_massager::sequence_names::SCHEMA_TYPE, } } @@ -476,8 +471,6 @@ pub mod seat { #[serde(rename = "@id")] pub instance_id: String, } - - pub type TYPE = Vec; } #[derive(derivative::Derivative)] @@ -492,7 +485,7 @@ pub mod seat { #[serde(rename = "@type")] #[derivative(Default(value = "crate::sdv_v1::seat::ID.to_string()"))] pub model_id: String, - pub seat_massager: crate::sdv_v1::seat::seat_massager::TYPE, + pub seat_massager: Vec, } } @@ -505,7 +498,7 @@ pub mod seat_massager { pub const NAME: &str = "sequence_names"; pub const DESCRIPTION: &str = "The name of each of the stored sequences."; - pub type TYPE = Vec; + pub type SCHEMA_TYPE = Vec; } pub mod load_sequence { @@ -551,7 +544,7 @@ pub mod seat_massager { value = "crate::sdv_v1::seat_massager::load_sequence::response::ID.to_string()" ))] pub model_id: String, - pub status: crate::sdv_v1::seat_massager::status::TYPE, + pub status: crate::sdv_v1::seat_massager::status::SCHEMA_TYPE, } } } @@ -598,7 +591,7 @@ pub mod seat_massager { value = "crate::sdv_v1::seat_massager::pause::response::ID.to_string()" ))] pub model_id: String, - pub status: crate::sdv_v1::seat_massager::status::TYPE, + pub status: crate::sdv_v1::seat_massager::status::SCHEMA_TYPE, } } } @@ -645,7 +638,7 @@ pub mod seat_massager { value = "crate::sdv_v1::seat_massager::play::response::ID.to_string()" ))] pub model_id: String, - pub status: crate::sdv_v1::seat_massager::status::TYPE, + pub status: crate::sdv_v1::seat_massager::status::SCHEMA_TYPE, } } } @@ -692,7 +685,7 @@ pub mod seat_massager { value = "crate::sdv_v1::seat_massager::reset::response::ID.to_string()" ))] pub model_id: String, - pub status: crate::sdv_v1::seat_massager::status::TYPE, + pub status: crate::sdv_v1::seat_massager::status::SCHEMA_TYPE, } } } @@ -703,7 +696,7 @@ pub mod seat_massager { pub const DESCRIPTION: &str = "The status."; #[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug, Default)] - pub struct TYPE { + pub struct SCHEMA_TYPE { pub code: i32, pub message: String, } @@ -724,12 +717,12 @@ pub mod vehicle { pub const NAME: &str = "vin"; pub const DESCRIPTION: &str = "Vehicle Identification Number."; - pub type TYPE = String; + pub type SCHEMA_TYPE = String; } #[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug, Default)] - pub struct TYPE { - pub vin: crate::sdv_v1::vehicle::vehicle_identification::vin::TYPE, + pub struct SCHEMA_TYPE { + pub vin: crate::sdv_v1::vehicle::vehicle_identification::vin::SCHEMA_TYPE, } } @@ -745,8 +738,6 @@ pub mod vehicle { #[serde(rename = "@id")] pub instance_id: String, } - - pub type TYPE = Vec; } #[derive(derivative::Derivative)] @@ -761,7 +752,7 @@ pub mod vehicle { #[serde(rename = "@type")] #[derivative(Default(value = "crate::sdv_v1::vehicle::ID.to_string()"))] pub model_id: String, - pub vehicle_identification: crate::sdv_v1::vehicle::vehicle_identification::TYPE, - pub cabin: crate::sdv_v1::vehicle::cabin::TYPE, + pub vehicle_identification: crate::sdv_v1::vehicle::vehicle_identification::SCHEMA_TYPE, + pub cabin: Vec, } } diff --git a/samples/digital_twin_graph/consumer/src/main.rs b/samples/digital_twin_graph/consumer/src/main.rs index 4a0f0d5f..e5a8e3e3 100644 --- a/samples/digital_twin_graph/consumer/src/main.rs +++ b/samples/digital_twin_graph/consumer/src/main.rs @@ -226,7 +226,8 @@ async fn find_seat( get(client.clone(), seat_relationship.instance_id.clone(), "".to_string()).await?; // Deserialize the seat instance. - let seat: sdv::seat::ENTITY_TYPE = serde_json::from_str(&get_seat_response.value).unwrap(); + let seat: sdv::seat::ENTITY_TYPE = + serde_json::from_str(&get_seat_response.value).unwrap(); info!("The seat's instance id is: {}", seat.instance_id); @@ -300,7 +301,7 @@ async fn perform_step( // Generate the perform_step operation's request payload. let request_payload: sdv::airbag_seat_massager::perform_step::request::PAYLOAD_TYPE = sdv::airbag_seat_massager::perform_step::request::PAYLOAD_TYPE { - step: vec![sdv::airbag_seat_massager::airbag_adjustment::TYPE { + step: vec![sdv::airbag_seat_massager::airbag_adjustment::SCHEMA_TYPE { airbag_identifier, inflation_level, inflation_duration_in_seconds, diff --git a/samples/digital_twin_graph/seat_massager_provider/src/request_impl.rs b/samples/digital_twin_graph/seat_massager_provider/src/request_impl.rs index 024548d0..d9195c59 100644 --- a/samples/digital_twin_graph/seat_massager_provider/src/request_impl.rs +++ b/samples/digital_twin_graph/seat_massager_provider/src/request_impl.rs @@ -217,7 +217,7 @@ impl RequestImpl { ); let response = sdv::airbag_seat_massager::perform_step::response::PAYLOAD_TYPE { - status: sdv::airbag_seat_massager::status::TYPE { + status: sdv::airbag_seat_massager::status::SCHEMA_TYPE { code: 200, message: "The step was performed successfully".to_string(), }, diff --git a/samples/digital_twin_graph/vehicle_core_provider/src/main.rs b/samples/digital_twin_graph/vehicle_core_provider/src/main.rs index 2157e662..1ac65c3c 100644 --- a/samples/digital_twin_graph/vehicle_core_provider/src/main.rs +++ b/samples/digital_twin_graph/vehicle_core_provider/src/main.rs @@ -144,10 +144,8 @@ fn create_provider_state() -> ProviderState { // Create the vehicle. let vehicle_instance_id = format!("{}", uuid::Uuid::new_v4()); - let vehicle_identification: sdv::vehicle::vehicle_identification::TYPE = - sdv::vehicle::vehicle_identification::TYPE { - vin: "1M8GDM9AXKP042788".to_string(), - }; + let vehicle_identification: sdv::vehicle::vehicle_identification::SCHEMA_TYPE = + sdv::vehicle::vehicle_identification::SCHEMA_TYPE { vin: "1M8GDM9AXKP042788".to_string() }; let vehicle_value: sdv::vehicle::ENTITY_TYPE = sdv::vehicle::ENTITY_TYPE { instance_id: vehicle_instance_id.clone(), vehicle_identification, diff --git a/samples/seat_massager/consumer/src/main.rs b/samples/seat_massager/consumer/src/main.rs index 385a58c9..e410cde7 100644 --- a/samples/seat_massager/consumer/src/main.rs +++ b/samples/seat_massager/consumer/src/main.rs @@ -63,7 +63,7 @@ fn start_seat_massage_steps( let request_payload: sdv::airbag_seat_massager::perform_step::request::PAYLOAD_TYPE = sdv::airbag_seat_massager::perform_step::request::PAYLOAD_TYPE { - step: vec![sdv::airbag_seat_massager::airbag_adjustment::TYPE { + step: vec![sdv::airbag_seat_massager::airbag_adjustment::SCHEMA_TYPE { airbag_identifier, inflation_level, inflation_duration_in_seconds, diff --git a/samples/seat_massager/provider/src/request_impl.rs b/samples/seat_massager/provider/src/request_impl.rs index 147dccd8..d5102c7f 100644 --- a/samples/seat_massager/provider/src/request_impl.rs +++ b/samples/seat_massager/provider/src/request_impl.rs @@ -88,7 +88,7 @@ impl Request for RequestImpl { // Prepare the perform_step response payload. let response_payload: sdv::airbag_seat_massager::perform_step::response::PAYLOAD_TYPE = sdv::airbag_seat_massager::perform_step::response::PAYLOAD_TYPE { - status: sdv::airbag_seat_massager::status::TYPE { + status: sdv::airbag_seat_massager::status::SCHEMA_TYPE { code: status::ok::CODE, message: status::ok::MESSAGE.to_string(), },