Skip to content

Commit

Permalink
PR feedback fixes:
Browse files Browse the repository at this point in the history
* Use UUri::try_from_parts() when building a UUri
  • Loading branch information
PLeVasseur committed Aug 2, 2024
1 parent 4100ea0 commit bcdaf9b
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 247 deletions.
44 changes: 22 additions & 22 deletions up-transport-vsomeip/examples/hello_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const HELLO_SERVICE_UE_VERSION_MAJOR: u8 = HELLO_SERVICE_MAJOR;
const HELLO_SERVICE_RESOURCE_ID: u16 = HELLO_METHOD_ID;

const CLIENT_AUTHORITY: &str = "me_authority";
const CLIENT_UE_ID: u16 = 0x5678;
const CLIENT_UE_ID: u32 = 0x5678;
const CLIENT_UE_VERSION_MAJOR: u8 = 1;
const CLIENT_RESOURCE_ID: u16 = 0;

Expand Down Expand Up @@ -66,13 +66,13 @@ async fn main() -> Result<(), UStatus> {

// There will be a single vsomeip_transport, as there is a connection into device and a streamer
// TODO: Add error handling if we fail to create a UPTransportVsomeip
let client_uuri = UUri {
authority_name: CLIENT_AUTHORITY.to_string(),
ue_id: CLIENT_UE_ID as u32,
ue_version_major: CLIENT_UE_VERSION_MAJOR as u32,
resource_id: CLIENT_RESOURCE_ID as u32,
..Default::default()
};
let client_uuri = UUri::try_from_parts(
CLIENT_AUTHORITY,
CLIENT_UE_ID,
CLIENT_UE_VERSION_MAJOR,
CLIENT_RESOURCE_ID,
)
.unwrap();
let client: Arc<dyn UTransport> = Arc::new(
UPTransportVsomeip::new_with_config(
client_uuri,
Expand All @@ -83,20 +83,20 @@ async fn main() -> Result<(), UStatus> {
.unwrap(),
);

let source = UUri {
authority_name: CLIENT_AUTHORITY.to_string(),
ue_id: CLIENT_UE_ID as u32,
ue_version_major: CLIENT_UE_VERSION_MAJOR as u32,
resource_id: CLIENT_RESOURCE_ID as u32,
..Default::default()
};
let sink = UUri {
authority_name: HELLO_SERVICE_AUTHORITY.to_string(),
ue_id: HELLO_SERVICE_UE_ID,
ue_version_major: HELLO_SERVICE_UE_VERSION_MAJOR as u32,
resource_id: HELLO_SERVICE_RESOURCE_ID as u32,
..Default::default()
};
let source = UUri::try_from_parts(
CLIENT_AUTHORITY,
CLIENT_UE_ID,
CLIENT_UE_VERSION_MAJOR,
CLIENT_RESOURCE_ID,
)
.unwrap();
let sink = UUri::try_from_parts(
HELLO_SERVICE_AUTHORITY,
HELLO_SERVICE_UE_ID,
HELLO_SERVICE_UE_VERSION_MAJOR,
HELLO_SERVICE_RESOURCE_ID,
)
.unwrap();

let service_response_listener: Arc<dyn UListener> = Arc::new(ServiceResponseListener);
client
Expand Down
36 changes: 15 additions & 21 deletions up-transport-vsomeip/examples/hello_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ async fn main() -> Result<(), UStatus> {

// There will be a single vsomeip_transport, as there is a connection into device and a streamer
// TODO: Add error handling if we fail to create a UPTransportVsomeip
let service_uuri = UUri {
authority_name: HELLO_SERVICE_AUTHORITY.to_string(),
ue_id: HELLO_SERVICE_UE_ID,
ue_version_major: HELLO_SERVICE_MAJOR as u32,
resource_id: HELLO_SERVICE_RESOURCE_ID as u32,
..Default::default()
};
let service_uuri = UUri::try_from_parts(
HELLO_SERVICE_AUTHORITY,
HELLO_SERVICE_UE_ID,
HELLO_SERVICE_MAJOR,
HELLO_SERVICE_RESOURCE_ID,
)
.unwrap();
let service: Arc<dyn UTransport> = Arc::new(
UPTransportVsomeip::new_with_config(
service_uuri,
Expand All @@ -106,20 +106,14 @@ async fn main() -> Result<(), UStatus> {
.unwrap(),
);

let source_filter = UUri {
authority_name: "*".to_string(),
ue_id: 0x0000_FFFF,
ue_version_major: 0xFF,
resource_id: 0xFFFF,
..Default::default()
};
let sink_filter = UUri {
authority_name: HELLO_SERVICE_AUTHORITY.to_string(),
ue_id: HELLO_SERVICE_UE_ID,
ue_version_major: HELLO_SERVICE_MAJOR as u32,
resource_id: HELLO_SERVICE_RESOURCE_ID as u32,
..Default::default()
};
let source_filter = UUri::any();
let sink_filter = UUri::try_from_parts(
HELLO_SERVICE_AUTHORITY,
HELLO_SERVICE_UE_ID,
HELLO_SERVICE_MAJOR,
HELLO_SERVICE_RESOURCE_ID,
)
.unwrap();
let service_request_responder: Arc<dyn UListener> =
Arc::new(ServiceRequestResponder::new(service.clone()));
// TODO: Need to revisit how the vsomeip config file is used in non point-to-point cases
Expand Down
133 changes: 84 additions & 49 deletions up-transport-vsomeip/src/message_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,21 +355,31 @@ impl VsomeipMessageToUMessage {
.get_interface_version();

trace!("MT_REQUEST type");
let sink = UUri {
authority_name: authority_name.to_string(),
ue_id: service_id as u32,
ue_version_major: interface_version as u32,
resource_id: method_id as u32,
..Default::default()
};
let sink = UUri::try_from_parts(
authority_name,
service_id as u32, // TODO: Need to address this by adding instance_id in MSB
interface_version,
method_id,
)
.map_err(|e| {
UStatus::fail_with_code(
UCode::INVALID_ARGUMENT,
format!("Unable to build sink UUri for MT_REQUEST type: {e:?}"),
)
})?;

let source = UUri {
authority_name: mechatronics_authority_name.to_string(),
ue_id: client_id as u32,
ue_version_major: 1, // TODO: I don't see a way to get this
resource_id: 0, // set to 0 as this is the resource_id of "me"
..Default::default()
};
let source = UUri::try_from_parts(
mechatronics_authority_name,
client_id as u32, // TODO: Need to address this by adding instance_id in MSB
1, // TODO: I don't see a way to get this
0, // set to 0 as this is the resource_id of "me"
)
.map_err(|e| {
UStatus::fail_with_code(
UCode::INVALID_ARGUMENT,
format!("Unable to build source UUri for MT_REQUEST type: {e:?}"),
)
})?;

// TODO: Not sure where to get this
let ttl = 1000;
Expand Down Expand Up @@ -423,21 +433,31 @@ impl VsomeipMessageToUMessage {
.get_interface_version();

trace!("MT_RESPONSE type");
let sink = UUri {
authority_name: authority_name.to_string(),
ue_id: client_id as u32,
ue_version_major: 1, // TODO: I don't see a way to get this
resource_id: 0, // set to 0 as this is the resource_id of "me"
..Default::default()
};
let sink = UUri::try_from_parts(
authority_name,
client_id as u32, // TODO: Need to address this by adding instance_id in MSB
1, // TODO: I don't see a way to get this
0, // set to 0 as this is the resource_id of "me"
)
.map_err(|e| {
UStatus::fail_with_code(
UCode::INVALID_ARGUMENT,
format!("Unable to build sink UUri for MT_RESPONSE type: {e:?}"),
)
})?;

let source = UUri {
authority_name: mechatronics_authority_name.to_string(),
ue_id: service_id as u32,
ue_version_major: interface_version as u32,
resource_id: method_id as u32,
..Default::default()
};
let source = UUri::try_from_parts(
mechatronics_authority_name,
service_id as u32, // TODO: Need to address this by adding instance_id in MSB
interface_version,
method_id,
)
.map_err(|e| {
UStatus::fail_with_code(
UCode::INVALID_ARGUMENT,
format!("Unable to build source UUri for MT_RESPONSE type: {e:?}"),
)
})?;

trace!(
"{} - request_id to look up to correlate to req_id: {}",
Expand Down Expand Up @@ -479,21 +499,31 @@ impl VsomeipMessageToUMessage {
.get_interface_version();

trace!("MT_ERROR type");
let sink = UUri {
authority_name: authority_name.to_string(),
ue_id: client_id as u32,
ue_version_major: 1, // TODO: I don't see a way to get this
resource_id: 0, // set to 0 as this is the resource_id of "me"
..Default::default()
};
let sink = UUri::try_from_parts(
authority_name,
client_id as u32, // TODO: Need to address this by adding instance_id in MSB
1, // TODO: I don't see a way to get this
0, // set to 0 as this is the resource_id of "me"
)
.map_err(|e| {
UStatus::fail_with_code(
UCode::INVALID_ARGUMENT,
format!("Unable to build sink UUri for MT_ERROR type: {e:?}"),
)
})?;

let source = UUri {
authority_name: mechatronics_authority_name.to_string(),
ue_id: service_id as u32,
ue_version_major: interface_version as u32,
resource_id: method_id as u32,
..Default::default()
};
let source = UUri::try_from_parts(
mechatronics_authority_name,
service_id as u32, // TODO: Need to address this by adding instance_id in MSB
interface_version,
method_id,
)
.map_err(|e| {
UStatus::fail_with_code(
UCode::INVALID_ARGUMENT,
format!("Unable to build source UUri for MT_ERROR type: {e:?}"),
)
})?;

trace!(
"{} - request_id to look up to correlate to req_id: {}",
Expand Down Expand Up @@ -532,13 +562,18 @@ impl VsomeipMessageToUMessage {
// TODO: Talk with @StevenHartley. It seems like vsomeip notify doesn't let us set the
// interface_version... going to set this manually to 1 for now
let interface_version = 1;
let source = UUri {
authority_name: mechatronics_authority_name.to_string(), // TODO: Should we set this to anything specific?
ue_id: service_id as u32,
ue_version_major: interface_version as u32,
resource_id: method_id as u32,
..Default::default()
};
let source = UUri::try_from_parts(
mechatronics_authority_name, // TODO: Should we set this to anything specific?
service_id as u32, // TODO: Need to address this by adding instance_id in MSB
interface_version,
method_id,
)
.map_err(|e| {
UStatus::fail_with_code(
UCode::INVALID_ARGUMENT,
format!("Unable to build source UUri for MT_NOTIFICATION type: {e:?}"),
)
})?;

let umsg_res = UMessageBuilder::publish(source)
.build_with_payload(payload_bytes, UPayloadFormat::UPAYLOAD_FORMAT_UNSPECIFIED);
Expand Down
60 changes: 24 additions & 36 deletions up-transport-vsomeip/tests/client_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,7 @@ async fn client_service() {
let client_config = canonicalize(client_config).ok();
println!("client_config: {client_config:?}");

let client_uuri = UUri {
authority_name: client_authority_name.to_string(),
ue_id: streamer_ue_id,
ue_version_major: 1,
resource_id: 0,
..Default::default()
};
let client_uuri = UUri::try_from_parts(client_authority_name, streamer_ue_id, 1, 0).unwrap();
let client_res = UPTransportVsomeip::new_with_config(
client_uuri,
&service_authority_name.to_string(),
Expand All @@ -164,21 +158,21 @@ async fn client_service() {

tokio::time::sleep(Duration::from_millis(1000)).await;

let client_uuri = UUri {
authority_name: client_authority_name.to_string(),
ue_id: client_ue_id as u32,
ue_version_major: client_ue_version_major,
resource_id: client_resource_id,
..Default::default()
};

let service_1_uuri_method_a = UUri {
authority_name: service_authority_name.to_string(),
ue_id: service_1_ue_id as u32,
ue_version_major: service_1_ue_version_major,
resource_id: service_1_resource_id_a,
..Default::default()
};
let client_uuri = UUri::try_from_parts(
client_authority_name,
client_ue_id as u32,
client_ue_version_major,
client_resource_id,
)
.unwrap();

let service_1_uuri_method_a = UUri::try_from_parts(
service_authority_name,
service_1_ue_id as u32,
service_1_ue_version_major,
service_1_resource_id_a,
)
.unwrap();

let response_listener_check = Arc::new(ResponseListener::new());
let response_listener: Arc<dyn UListener> = response_listener_check.clone();
Expand All @@ -200,13 +194,7 @@ async fn client_service() {
let service_config = canonicalize(service_config).ok();
println!("service_config: {service_config:?}");

let service_uuri = UUri {
authority_name: service_authority_name.to_string(),
ue_id: streamer_ue_id,
ue_version_major: 1,
resource_id: 0,
..Default::default()
};
let service_uuri = UUri::try_from_parts(service_authority_name, streamer_ue_id, 1, 0).unwrap();
let service_res = UPTransportVsomeip::new_with_config(
service_uuri,
&client_authority_name.to_string(),
Expand All @@ -222,13 +210,13 @@ async fn client_service() {

let service = Arc::new(service);

let service_1_uuri = UUri {
authority_name: service_authority_name.to_string(),
ue_id: service_1_ue_id as u32,
ue_version_major: service_1_ue_version_major,
resource_id: service_1_resource_id_a,
..Default::default()
};
let service_1_uuri = UUri::try_from_parts(
service_authority_name,
service_1_ue_id as u32,
service_1_ue_version_major,
service_1_resource_id_a,
)
.unwrap();

let request_listener_check = Arc::new(RequestListener::new(service.clone()));
let request_listener: Arc<dyn UListener> = request_listener_check.clone();
Expand Down
Loading

0 comments on commit bcdaf9b

Please sign in to comment.