Skip to content

Commit e32c6d7

Browse files
committed
Digital Twin Graph
1 parent a0ce789 commit e32c6d7

File tree

7 files changed

+70
-54
lines changed

7 files changed

+70
-54
lines changed

core/module/digital_twin_registry/src/digital_twin_registry_impl.rs

+26
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,32 @@ impl DigitalTwinRegistryImpl {
137137
fn register_entity(&self, entity_access_info: EntityAccessInfo) -> Result<(), String> {
138138
// This block controls the lifetime of the lock.
139139
{
140+
if entity_access_info.provider_id.is_empty() {
141+
return Err("Provider id cannot be empty".to_string());
142+
}
143+
144+
if entity_access_info.model_id.is_empty() {
145+
return Err("Model id cannot be empty".to_string());
146+
}
147+
148+
if entity_access_info.instance_id.is_empty() {
149+
return Err("Instance id cannot be empty".to_string());
150+
}
151+
152+
if entity_access_info.protocol.is_empty() {
153+
return Err("Protocol cannot be empty".to_string());
154+
}
155+
156+
if entity_access_info.uri.is_empty() {
157+
return Err("Uri cannot be empty".to_string());
158+
}
159+
160+
if entity_access_info.operations.is_empty() {
161+
return Err("Operations cannot be empty".to_string());
162+
}
163+
164+
// Note: the context is optional.
165+
140166
let mut lock: RwLockWriteGuard<HashMap<String, Vec<EntityAccessInfo>>> =
141167
self.entity_access_info_map.write();
142168
let get_result = lock.get(&entity_access_info.model_id);

digital-twin-model/src/sdv_v1.rs

+36-45
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub mod airbag_seat_massager {
4141
))]
4242
pub model_id: String,
4343
pub sequence_name: String,
44-
pub sequence: crate::sdv_v1::airbag_seat_massager::massage_step::TYPE,
44+
pub sequence: crate::sdv_v1::airbag_seat_massager::massage_step::SCHEMA_TYPE,
4545
}
4646
}
4747

@@ -62,7 +62,7 @@ pub mod airbag_seat_massager {
6262
value = "crate::sdv_v1::airbag_seat_massager::store_sequence::response::ID.to_string()"
6363
))]
6464
pub model_id: String,
65-
pub status: crate::sdv_v1::airbag_seat_massager::status::TYPE,
65+
pub status: crate::sdv_v1::airbag_seat_massager::status::SCHEMA_TYPE,
6666
}
6767
}
6868
}
@@ -89,7 +89,7 @@ pub mod airbag_seat_massager {
8989
value = "crate::sdv_v1::airbag_seat_massager::perform_step::request::ID.to_string()"
9090
))]
9191
pub model_id: String,
92-
pub step: crate::sdv_v1::airbag_seat_massager::massage_step::TYPE,
92+
pub step: crate::sdv_v1::airbag_seat_massager::massage_step::SCHEMA_TYPE,
9393
}
9494
}
9595

@@ -110,7 +110,7 @@ pub mod airbag_seat_massager {
110110
value = "crate::sdv_v1::airbag_seat_massager::perform_step::response::ID.to_string()"
111111
))]
112112
pub model_id: String,
113-
pub status: crate::sdv_v1::airbag_seat_massager::status::TYPE,
113+
pub status: crate::sdv_v1::airbag_seat_massager::status::SCHEMA_TYPE,
114114
}
115115
}
116116
}
@@ -121,7 +121,7 @@ pub mod airbag_seat_massager {
121121
pub const DESCRIPTION: &str = "An airbag adjustment.";
122122

123123
#[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug)]
124-
pub struct TYPE {
124+
pub struct SCHEMA_TYPE {
125125
pub airbag_identifier: i32,
126126
pub inflation_level: i32,
127127
pub inflation_duration_in_seconds: i32,
@@ -133,7 +133,8 @@ pub mod airbag_seat_massager {
133133
pub const NAME: &str = "massage_step";
134134
pub const DESCRIPTION: &str = "The massage step.";
135135

136-
pub type TYPE = Vec<crate::sdv_v1::airbag_seat_massager::airbag_adjustment::TYPE>;
136+
pub type SCHEMA_TYPE =
137+
Vec<crate::sdv_v1::airbag_seat_massager::airbag_adjustment::SCHEMA_TYPE>;
137138
}
138139

139140
pub mod status {
@@ -142,7 +143,7 @@ pub mod airbag_seat_massager {
142143
pub const DESCRIPTION: &str = "The status.";
143144

144145
#[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug, Default)]
145-
pub struct TYPE {
146+
pub struct SCHEMA_TYPE {
146147
pub code: i32,
147148
pub message: String,
148149
}
@@ -167,7 +168,7 @@ pub mod basic_airbag_seat_massager {
167168
value = "crate::sdv_v1::basic_airbag_seat_massager::ID.to_string()"
168169
))]
169170
pub model_id: String,
170-
pub sequence_names: crate::sdv_v1::seat_massager::sequence_names::TYPE,
171+
pub sequence_names: crate::sdv_v1::seat_massager::sequence_names::SCHEMA_TYPE,
171172
}
172173
}
173174

@@ -187,8 +188,6 @@ pub mod cabin {
187188
#[serde(rename = "@id")]
188189
pub instance_id: String,
189190
}
190-
191-
pub type TYPE = Vec<RELATIONSHIP_TYPE>;
192191
}
193192

194193
pub mod hvac {
@@ -203,8 +202,6 @@ pub mod cabin {
203202
#[serde(rename = "@id")]
204203
pub instance_id: String,
205204
}
206-
207-
pub type TYPE = Vec<RELATIONSHIP_TYPE>;
208205
}
209206

210207
pub mod seat {
@@ -235,8 +232,6 @@ pub mod cabin {
235232
pub seat_row: SEAT_ROW_TYPE,
236233
pub seat_position: SEAT_POSITION_TYPE,
237234
}
238-
239-
pub type TYPE = Vec<RELATIONSHIP_TYPE>;
240235
}
241236

242237
#[derive(derivative::Derivative)]
@@ -251,9 +246,9 @@ pub mod cabin {
251246
#[serde(rename = "@type")]
252247
#[derivative(Default(value = "crate::sdv_v1::cabin::ID.to_string()"))]
253248
pub model_id: String,
254-
pub infotainment: crate::sdv_v1::cabin::infotainment::TYPE,
255-
pub hvac: crate::sdv_v1::cabin::hvac::TYPE,
256-
pub seat: crate::sdv_v1::cabin::seat::TYPE,
249+
pub infotainment: Vec<crate::sdv_v1::cabin::infotainment::RELATIONSHIP_TYPE>,
250+
pub hvac: Vec<crate::sdv_v1::cabin::hvac::RELATIONSHIP_TYPE>,
251+
pub seat: Vec<crate::sdv_v1::cabin::seat::RELATIONSHIP_TYPE>,
257252
}
258253
}
259254

@@ -270,7 +265,7 @@ pub mod camera {
270265
#[derive(derivative::Derivative)]
271266
#[derivative(Default)]
272267
#[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug)]
273-
pub struct TYPE {
268+
pub struct PAYLOAD_TYPE {
274269
#[serde(rename = "@context")]
275270
#[derivative(Default(value = "crate::sdv_v1::context()"))]
276271
pub context: Vec<String>,
@@ -294,7 +289,7 @@ pub mod camera {
294289
#[serde(rename = "@type")]
295290
#[derivative(Default(value = "crate::sdv_v1::camera::ID.to_string()"))]
296291
pub model_id: String,
297-
}
292+
}
298293
}
299294

300295
pub mod hmi {
@@ -335,7 +330,7 @@ pub mod hmi {
335330
#[derive(derivative::Derivative)]
336331
#[derivative(Default)]
337332
#[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug)]
338-
pub struct TYPE {
333+
pub struct PAYLOAD_TYPE {
339334
#[serde(rename = "@context")]
340335
#[derivative(Default(value = "crate::sdv_v1::context()"))]
341336
pub context: Vec<String>,
@@ -344,7 +339,7 @@ pub mod hmi {
344339
value = "crate::sdv_v1::hmi::show_notification::response::ID.to_string()"
345340
))]
346341
pub model_id: String,
347-
pub status: crate::sdv_v1::hmi::status::TYPE,
342+
pub status: crate::sdv_v1::hmi::status::SCHEMA_TYPE,
348343
}
349344
}
350345
}
@@ -361,15 +356,15 @@ pub mod hmi {
361356
#[serde(rename = "@type")]
362357
#[derivative(Default(value = "crate::sdv_v1::hmi::ID.to_string()"))]
363358
pub model_id: String,
364-
}
359+
}
365360

366361
pub mod status {
367362
pub const ID: &str = "dtmi:sdv:hmi:status;1";
368363
pub const NAME: &str = "status";
369364
pub const DESCRIPTION: &str = "The status.";
370365

371366
#[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug, Default)]
372-
pub struct TYPE {
367+
pub struct SCHEMA_TYPE {
373368
pub code: i32,
374369
pub message: String,
375370
}
@@ -385,15 +380,15 @@ pub mod hvac {
385380
pub const NAME: &str = "ambient_air_temperature";
386381
pub const DESCRIPTION: &str = "The immediate surroundings air temperature (in Fahrenheit).";
387382

388-
pub type TYPE = i32;
383+
pub type SCHEMA_TYPE = i32;
389384
}
390385

391386
pub mod is_air_conditioning_active {
392387
pub const ID: &str = "dtmi:sdv:HVAC:is_air_conditioning_active;1";
393388
pub const NAME: &str = "is_air_conditioning_active";
394389
pub const DESCRIPTION: &str = "Is air conditioning active?";
395390

396-
pub type TYPE = bool;
391+
pub type SCHEMA_TYPE = bool;
397392
}
398393

399394
#[derive(derivative::Derivative)]
@@ -408,7 +403,7 @@ pub mod hvac {
408403
#[serde(rename = "@type")]
409404
#[derivative(Default(value = "crate::sdv_v1::hvac::ID.to_string()"))]
410405
pub model_id: String,
411-
}
406+
}
412407
}
413408

414409
pub mod obd {
@@ -420,7 +415,7 @@ pub mod obd {
420415
pub const NAME: &str = "hybrid_battery_remaining";
421416
pub const DESCRIPTION: &str = "The remaining hybrid battery life.";
422417

423-
pub type TYPE = i32;
418+
pub type SCHEMA_TYPE = i32;
424419
}
425420

426421
#[derive(derivative::Derivative)]
@@ -435,7 +430,7 @@ pub mod obd {
435430
#[serde(rename = "@type")]
436431
#[derivative(Default(value = "crate::sdv_v1::obd::ID.to_string()"))]
437432
pub model_id: String,
438-
}
433+
}
439434
}
440435

441436
pub mod premium_airbag_seat_massager {
@@ -456,7 +451,7 @@ pub mod premium_airbag_seat_massager {
456451
value = "crate::sdv_v1::premium_airbag_seat_massager::ID.to_string()"
457452
))]
458453
pub model_id: String,
459-
pub sequence_names: crate::sdv_v1::seat_massager::sequence_names::TYPE,
454+
pub sequence_names: crate::sdv_v1::seat_massager::sequence_names::SCHEMA_TYPE,
460455
}
461456
}
462457

@@ -476,8 +471,6 @@ pub mod seat {
476471
#[serde(rename = "@id")]
477472
pub instance_id: String,
478473
}
479-
480-
pub type TYPE = Vec<RELATIONSHIP_TYPE>;
481474
}
482475

483476
#[derive(derivative::Derivative)]
@@ -492,7 +485,7 @@ pub mod seat {
492485
#[serde(rename = "@type")]
493486
#[derivative(Default(value = "crate::sdv_v1::seat::ID.to_string()"))]
494487
pub model_id: String,
495-
pub seat_massager: crate::sdv_v1::seat::seat_massager::TYPE,
488+
pub seat_massager: Vec<crate::sdv_v1::seat::seat_massager::RELATIONSHIP_TYPE>,
496489
}
497490
}
498491

@@ -505,7 +498,7 @@ pub mod seat_massager {
505498
pub const NAME: &str = "sequence_names";
506499
pub const DESCRIPTION: &str = "The name of each of the stored sequences.";
507500

508-
pub type TYPE = Vec<String>;
501+
pub type SCHEMA_TYPE = Vec<String>;
509502
}
510503

511504
pub mod load_sequence {
@@ -551,7 +544,7 @@ pub mod seat_massager {
551544
value = "crate::sdv_v1::seat_massager::load_sequence::response::ID.to_string()"
552545
))]
553546
pub model_id: String,
554-
pub status: crate::sdv_v1::seat_massager::status::TYPE,
547+
pub status: crate::sdv_v1::seat_massager::status::SCHEMA_TYPE,
555548
}
556549
}
557550
}
@@ -598,7 +591,7 @@ pub mod seat_massager {
598591
value = "crate::sdv_v1::seat_massager::pause::response::ID.to_string()"
599592
))]
600593
pub model_id: String,
601-
pub status: crate::sdv_v1::seat_massager::status::TYPE,
594+
pub status: crate::sdv_v1::seat_massager::status::SCHEMA_TYPE,
602595
}
603596
}
604597
}
@@ -645,7 +638,7 @@ pub mod seat_massager {
645638
value = "crate::sdv_v1::seat_massager::play::response::ID.to_string()"
646639
))]
647640
pub model_id: String,
648-
pub status: crate::sdv_v1::seat_massager::status::TYPE,
641+
pub status: crate::sdv_v1::seat_massager::status::SCHEMA_TYPE,
649642
}
650643
}
651644
}
@@ -692,7 +685,7 @@ pub mod seat_massager {
692685
value = "crate::sdv_v1::seat_massager::reset::response::ID.to_string()"
693686
))]
694687
pub model_id: String,
695-
pub status: crate::sdv_v1::seat_massager::status::TYPE,
688+
pub status: crate::sdv_v1::seat_massager::status::SCHEMA_TYPE,
696689
}
697690
}
698691
}
@@ -703,7 +696,7 @@ pub mod seat_massager {
703696
pub const DESCRIPTION: &str = "The status.";
704697

705698
#[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug, Default)]
706-
pub struct TYPE {
699+
pub struct SCHEMA_TYPE {
707700
pub code: i32,
708701
pub message: String,
709702
}
@@ -724,12 +717,12 @@ pub mod vehicle {
724717
pub const NAME: &str = "vin";
725718
pub const DESCRIPTION: &str = "Vehicle Identification Number.";
726719

727-
pub type TYPE = String;
720+
pub type SCHEMA_TYPE = String;
728721
}
729722

730723
#[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug, Default)]
731-
pub struct TYPE {
732-
pub vin: crate::sdv_v1::vehicle::vehicle_identification::vin::TYPE,
724+
pub struct SCHEMA_TYPE {
725+
pub vin: crate::sdv_v1::vehicle::vehicle_identification::vin::SCHEMA_TYPE,
733726
}
734727
}
735728

@@ -745,8 +738,6 @@ pub mod vehicle {
745738
#[serde(rename = "@id")]
746739
pub instance_id: String,
747740
}
748-
749-
pub type TYPE = Vec<RELATIONSHIP_TYPE>;
750741
}
751742

752743
#[derive(derivative::Derivative)]
@@ -761,7 +752,7 @@ pub mod vehicle {
761752
#[serde(rename = "@type")]
762753
#[derivative(Default(value = "crate::sdv_v1::vehicle::ID.to_string()"))]
763754
pub model_id: String,
764-
pub vehicle_identification: crate::sdv_v1::vehicle::vehicle_identification::TYPE,
765-
pub cabin: crate::sdv_v1::vehicle::cabin::TYPE,
755+
pub vehicle_identification: crate::sdv_v1::vehicle::vehicle_identification::SCHEMA_TYPE,
756+
pub cabin: Vec<crate::sdv_v1::vehicle::cabin::RELATIONSHIP_TYPE>,
766757
}
767758
}

samples/digital_twin_graph/consumer/src/main.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ async fn find_seat(
226226
get(client.clone(), seat_relationship.instance_id.clone(), "".to_string()).await?;
227227

228228
// Deserialize the seat instance.
229-
let seat: sdv::seat::ENTITY_TYPE = serde_json::from_str(&get_seat_response.value).unwrap();
229+
let seat: sdv::seat::ENTITY_TYPE =
230+
serde_json::from_str(&get_seat_response.value).unwrap();
230231

231232
info!("The seat's instance id is: {}", seat.instance_id);
232233

@@ -300,7 +301,7 @@ async fn perform_step(
300301
// Generate the perform_step operation's request payload.
301302
let request_payload: sdv::airbag_seat_massager::perform_step::request::PAYLOAD_TYPE =
302303
sdv::airbag_seat_massager::perform_step::request::PAYLOAD_TYPE {
303-
step: vec![sdv::airbag_seat_massager::airbag_adjustment::TYPE {
304+
step: vec![sdv::airbag_seat_massager::airbag_adjustment::SCHEMA_TYPE {
304305
airbag_identifier,
305306
inflation_level,
306307
inflation_duration_in_seconds,

samples/digital_twin_graph/seat_massager_provider/src/request_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl RequestImpl {
217217
);
218218

219219
let response = sdv::airbag_seat_massager::perform_step::response::PAYLOAD_TYPE {
220-
status: sdv::airbag_seat_massager::status::TYPE {
220+
status: sdv::airbag_seat_massager::status::SCHEMA_TYPE {
221221
code: 200,
222222
message: "The step was performed successfully".to_string(),
223223
},

0 commit comments

Comments
 (0)