diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2022-05-02 17:46:49 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-05-02 17:46:49 +0000 |
commit | fde4c70207ff32157549cae969e99b5cf2604c70 (patch) | |
tree | ae067751c9fd5ecbcf9996ca9958646b43268b2b | |
parent | 2b0921d7c3702a2a406df1b5d98c86d14bbfb704 (diff) | |
parent | 19ab538af81a8216c0807286f44df6680f28bb45 (diff) | |
download | uwb-fde4c70207ff32157549cae969e99b5cf2604c70.tar.gz |
Merge "uwb_core: group UciNotification to core, session, and vendor" into tm-dev am: 19ab538af8
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/uwb/+/17881426
Change-Id: I1daaefb3f9ca3483518beeb27e41cdd5d453c871
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | src/rust/uwb_core/src/session/session_manager.rs | 82 | ||||
-rw-r--r-- | src/rust/uwb_core/src/uci/notification.rs | 53 | ||||
-rw-r--r-- | src/rust/uwb_core/src/uci/uci_manager.rs | 10 |
3 files changed, 82 insertions, 63 deletions
diff --git a/src/rust/uwb_core/src/session/session_manager.rs b/src/rust/uwb_core/src/session/session_manager.rs index 9828ca9..97881aa 100644 --- a/src/rust/uwb_core/src/session/session_manager.rs +++ b/src/rust/uwb_core/src/session/session_manager.rs @@ -20,7 +20,7 @@ use tokio::sync::{mpsc, oneshot}; use crate::session::error::{Error, Result}; use crate::session::params::AppConfigParams; use crate::session::uwb_session::UwbSession; -use crate::uci::notification::{SessionRangeData, UciNotification}; +use crate::uci::notification::{SessionNotification, SessionRangeData, UciNotification}; use crate::uci::params::{ Controlee, SessionId, SessionState, SessionType, UpdateMulticastListAction, }; @@ -147,7 +147,9 @@ impl<T: UciManager> SessionManagerActor<T> { } Some(uci_notf) = self.uci_notf_receiver.recv() => { - self.handle_uci_notification(uci_notf); + if let UciNotification::Session(notf) = uci_notf { + self.handle_uci_notification(notf); + } } } } @@ -236,9 +238,9 @@ impl<T: UciManager> SessionManagerActor<T> { } } - fn handle_uci_notification(&mut self, notf: UciNotification) { + fn handle_uci_notification(&mut self, notf: SessionNotification) { match notf { - UciNotification::SessionStatus { session_id, session_state, reason_code } => { + SessionNotification::Status { session_id, session_state, reason_code } => { if session_state == SessionState::SessionStateDeinit { debug!("Session {:?} is deinitialized", session_id); let _ = self.active_sessions.remove(&session_id); @@ -255,7 +257,7 @@ impl<T: UciManager> SessionManagerActor<T> { } } } - UciNotification::SessionUpdateControllerMulticastList { + SessionNotification::UpdateControllerMulticastList { session_id, remaining_multicast_list_size: _, status_list, @@ -268,13 +270,12 @@ impl<T: UciManager> SessionManagerActor<T> { ); } }, - UciNotification::RangeData(data) => { + SessionNotification::RangeData(data) => { match self.active_sessions.get_mut(&data.session_id) { Some(session) => session.on_range_data_received(data), None => warn!("Received range data of the unknown Session: {:?}", data), } } - _ => {} } } } @@ -358,16 +359,17 @@ mod tests { let tlvs = params.generate_tlvs(); let (mut session_manager, mut mock_uci_manager) = setup_session_manager(move |uci_manager| { - let init_notfs = vec![UciNotification::SessionStatus { + let init_notfs = vec![UciNotification::Session(SessionNotification::Status { session_id, session_state: SessionState::SessionStateInit, reason_code: ReasonCode::StateChangeWithSessionManagementCommands, - }]; - let set_app_config_notfs = vec![UciNotification::SessionStatus { - session_id, - session_state: SessionState::SessionStateIdle, - reason_code: ReasonCode::StateChangeWithSessionManagementCommands, - }]; + })]; + let set_app_config_notfs = + vec![UciNotification::Session(SessionNotification::Status { + session_id, + session_state: SessionState::SessionStateIdle, + reason_code: ReasonCode::StateChangeWithSessionManagementCommands, + })]; uci_manager.expect_session_init(session_id, session_type, init_notfs, Ok(())); uci_manager.expect_session_set_app_config( session_id, @@ -439,21 +441,22 @@ mod tests { let (mut session_manager, mut mock_uci_manager) = setup_session_manager(move |uci_manager| { - let state_init_notf = vec![UciNotification::SessionStatus { + let state_init_notf = vec![UciNotification::Session(SessionNotification::Status { session_id, session_state: SessionState::SessionStateInit, reason_code: ReasonCode::StateChangeWithSessionManagementCommands, - }]; - let state_idle_notf = vec![UciNotification::SessionStatus { + })]; + let state_idle_notf = vec![UciNotification::Session(SessionNotification::Status { session_id, session_state: SessionState::SessionStateIdle, reason_code: ReasonCode::StateChangeWithSessionManagementCommands, - }]; - let state_active_notf = vec![UciNotification::SessionStatus { - session_id, - session_state: SessionState::SessionStateActive, - reason_code: ReasonCode::StateChangeWithSessionManagementCommands, - }]; + })]; + let state_active_notf = + vec![UciNotification::Session(SessionNotification::Status { + session_id, + session_state: SessionState::SessionStateActive, + reason_code: ReasonCode::StateChangeWithSessionManagementCommands, + })]; uci_manager.expect_session_init(session_id, session_type, state_init_notf, Ok(())); uci_manager.expect_session_set_app_config( session_id, @@ -493,18 +496,18 @@ mod tests { let controlees_clone = controlees.clone(); let (mut session_manager, mut mock_uci_manager) = setup_session_manager(move |uci_manager| { - let state_init_notf = vec![UciNotification::SessionStatus { + let state_init_notf = vec![UciNotification::Session(SessionNotification::Status { session_id, session_state: SessionState::SessionStateInit, reason_code: ReasonCode::StateChangeWithSessionManagementCommands, - }]; - let state_idle_notf = vec![UciNotification::SessionStatus { + })]; + let state_idle_notf = vec![UciNotification::Session(SessionNotification::Status { session_id, session_state: SessionState::SessionStateIdle, reason_code: ReasonCode::StateChangeWithSessionManagementCommands, - }]; - let multicast_list_notf = - vec![UciNotification::SessionUpdateControllerMulticastList { + })]; + let multicast_list_notf = vec![UciNotification::Session( + SessionNotification::UpdateControllerMulticastList { session_id, remaining_multicast_list_size: 1, status_list: vec![ControleeStatus { @@ -512,7 +515,8 @@ mod tests { subsession_id: 0x24, status: MulticastUpdateStatusCode::StatusOkMulticastListUpdate, }], - }]; + }, + )]; uci_manager.expect_session_init(session_id, session_type, state_init_notf, Ok(())); uci_manager.expect_session_set_app_config( session_id, @@ -556,16 +560,16 @@ mod tests { let controlees_clone = controlees.clone(); let (mut session_manager, mut mock_uci_manager) = setup_session_manager(move |uci_manager| { - let state_init_notf = vec![UciNotification::SessionStatus { + let state_init_notf = vec![UciNotification::Session(SessionNotification::Status { session_id, session_state: SessionState::SessionStateInit, reason_code: ReasonCode::StateChangeWithSessionManagementCommands, - }]; - let state_idle_notf = vec![UciNotification::SessionStatus { + })]; + let state_idle_notf = vec![UciNotification::Session(SessionNotification::Status { session_id, session_state: SessionState::SessionStateIdle, reason_code: ReasonCode::StateChangeWithSessionManagementCommands, - }]; + })]; uci_manager.expect_session_init(session_id, session_type, state_init_notf, Ok(())); uci_manager.expect_session_set_app_config( session_id, @@ -631,18 +635,18 @@ mod tests { let range_data_clone = range_data.clone(); let (mut session_manager, mut mock_uci_manager) = setup_session_manager(move |uci_manager| { - let init_notfs = vec![UciNotification::SessionStatus { + let init_notfs = vec![UciNotification::Session(SessionNotification::Status { session_id, session_state: SessionState::SessionStateInit, reason_code: ReasonCode::StateChangeWithSessionManagementCommands, - }]; + })]; let set_app_config_notfs = vec![ - UciNotification::SessionStatus { + UciNotification::Session(SessionNotification::Status { session_id, session_state: SessionState::SessionStateIdle, reason_code: ReasonCode::StateChangeWithSessionManagementCommands, - }, - UciNotification::RangeData(range_data_clone), + }), + UciNotification::Session(SessionNotification::RangeData(range_data_clone)), ]; uci_manager.expect_session_init(session_id, session_type, init_notfs, Ok(())); uci_manager.expect_session_set_app_config( diff --git a/src/rust/uwb_core/src/uci/notification.rs b/src/rust/uwb_core/src/uci/notification.rs index 6e4e6dd..f68c7d1 100644 --- a/src/rust/uwb_core/src/uci/notification.rs +++ b/src/rust/uwb_core/src/uci/notification.rs @@ -26,20 +26,30 @@ use crate::uci::params::{ #[derive(Debug, Clone)] pub(crate) enum UciNotification { - CoreDeviceStatus(DeviceState), - CoreGenericError(StatusCode), - SessionStatus { + Core(CoreNotification), + Session(SessionNotification), + Vendor(RawVendorMessage), +} + +#[derive(Debug, Clone)] +pub(crate) enum CoreNotification { + DeviceStatus(DeviceState), + GenericError(StatusCode), +} + +#[derive(Debug, Clone)] +pub(crate) enum SessionNotification { + Status { session_id: SessionId, session_state: SessionState, reason_code: ReasonCode, }, - SessionUpdateControllerMulticastList { + UpdateControllerMulticastList { session_id: SessionId, remaining_multicast_list_size: usize, status_list: Vec<ControleeStatus>, }, RangeData(SessionRangeData), - RawVendor(RawVendorMessage), } #[derive(Debug, Clone, PartialEq)] @@ -115,7 +125,10 @@ fn extended_address_two_way_ranging_measurement_eq( impl UciNotification { pub fn need_retry(&self) -> bool { - matches!(self, Self::CoreGenericError(StatusCode::UciStatusCommandRetry)) + matches!( + self, + Self::Core(CoreNotification::GenericError(StatusCode::UciStatusCommandRetry)) + ) } } @@ -124,9 +137,9 @@ impl TryFrom<uwb_uci_packets::UciNotificationPacket> for UciNotification { fn try_from(evt: uwb_uci_packets::UciNotificationPacket) -> Result<Self, Self::Error> { use uwb_uci_packets::UciNotificationChild; match evt.specialize() { - UciNotificationChild::CoreNotification(evt) => evt.try_into(), - UciNotificationChild::SessionNotification(evt) => evt.try_into(), - UciNotificationChild::RangingNotification(evt) => evt.try_into(), + UciNotificationChild::CoreNotification(evt) => Ok(Self::Core(evt.try_into()?)), + UciNotificationChild::SessionNotification(evt) => Ok(Self::Session(evt.try_into()?)), + UciNotificationChild::RangingNotification(evt) => Ok(Self::Session(evt.try_into()?)), UciNotificationChild::AndroidNotification(evt) => evt.try_into(), UciNotificationChild::UciVendor_9_Notification(evt) => vendor_notification(evt.into()), UciNotificationChild::UciVendor_A_Notification(evt) => vendor_notification(evt.into()), @@ -138,34 +151,32 @@ impl TryFrom<uwb_uci_packets::UciNotificationPacket> for UciNotification { } } -impl TryFrom<uwb_uci_packets::CoreNotificationPacket> for UciNotification { +impl TryFrom<uwb_uci_packets::CoreNotificationPacket> for CoreNotification { type Error = Error; fn try_from(evt: uwb_uci_packets::CoreNotificationPacket) -> Result<Self, Self::Error> { use uwb_uci_packets::CoreNotificationChild; match evt.specialize() { CoreNotificationChild::DeviceStatusNtf(evt) => { - Ok(UciNotification::CoreDeviceStatus(evt.get_device_state())) - } - CoreNotificationChild::GenericError(evt) => { - Ok(UciNotification::CoreGenericError(evt.get_status())) + Ok(Self::DeviceStatus(evt.get_device_state())) } + CoreNotificationChild::GenericError(evt) => Ok(Self::GenericError(evt.get_status())), _ => Err(Error::Specialize(evt.to_vec())), } } } -impl TryFrom<uwb_uci_packets::SessionNotificationPacket> for UciNotification { +impl TryFrom<uwb_uci_packets::SessionNotificationPacket> for SessionNotification { type Error = Error; fn try_from(evt: uwb_uci_packets::SessionNotificationPacket) -> Result<Self, Self::Error> { use uwb_uci_packets::SessionNotificationChild; match evt.specialize() { - SessionNotificationChild::SessionStatusNtf(evt) => Ok(UciNotification::SessionStatus { + SessionNotificationChild::SessionStatusNtf(evt) => Ok(Self::Status { session_id: evt.get_session_id(), session_state: evt.get_session_state(), reason_code: evt.get_reason_code(), }), SessionNotificationChild::SessionUpdateControllerMulticastListNtf(evt) => { - Ok(UciNotification::SessionUpdateControllerMulticastList { + Ok(Self::UpdateControllerMulticastList { session_id: evt.get_session_id(), remaining_multicast_list_size: evt.get_remaining_multicast_list_size() as usize, status_list: evt.get_controlee_status().clone(), @@ -176,7 +187,7 @@ impl TryFrom<uwb_uci_packets::SessionNotificationPacket> for UciNotification { } } -impl TryFrom<uwb_uci_packets::RangingNotificationPacket> for UciNotification { +impl TryFrom<uwb_uci_packets::RangingNotificationPacket> for SessionNotification { type Error = Error; fn try_from(evt: uwb_uci_packets::RangingNotificationPacket) -> Result<Self, Self::Error> { use uwb_uci_packets::RangingNotificationChild; @@ -187,7 +198,7 @@ impl TryFrom<uwb_uci_packets::RangingNotificationPacket> for UciNotification { } } -impl TryFrom<uwb_uci_packets::RangeDataNtfPacket> for UciNotification { +impl TryFrom<uwb_uci_packets::RangeDataNtfPacket> for SessionNotification { type Error = Error; fn try_from(evt: uwb_uci_packets::RangeDataNtfPacket) -> Result<Self, Self::Error> { use uwb_uci_packets::RangeDataNtfChild; @@ -200,7 +211,7 @@ impl TryFrom<uwb_uci_packets::RangeDataNtfPacket> for UciNotification { } _ => return Err(Error::Specialize(evt.to_vec())), }; - Ok(UciNotification::RangeData(SessionRangeData { + Ok(Self::RangeData(SessionRangeData { sequence_number: evt.get_sequence_number(), session_id: evt.get_session_id(), current_ranging_interval_ms: evt.get_current_ranging_interval(), @@ -218,7 +229,7 @@ impl TryFrom<uwb_uci_packets::AndroidNotificationPacket> for UciNotification { } fn vendor_notification(evt: uwb_uci_packets::UciNotificationPacket) -> UciResult<UciNotification> { - Ok(UciNotification::RawVendor(RawVendorMessage { + Ok(UciNotification::Vendor(RawVendorMessage { gid: evt.get_group_id().to_u32().ok_or_else(|| Error::Specialize(evt.clone().to_vec()))?, oid: evt.get_opcode().to_u32().ok_or_else(|| Error::Specialize(evt.clone().to_vec()))?, payload: get_vendor_uci_payload(evt)?, diff --git a/src/rust/uwb_core/src/uci/uci_manager.rs b/src/rust/uwb_core/src/uci/uci_manager.rs index 2e2a912..b89b9ab 100644 --- a/src/rust/uwb_core/src/uci/uci_manager.rs +++ b/src/rust/uwb_core/src/uci/uci_manager.rs @@ -23,7 +23,7 @@ use uwb_uci_packets::{Packet, UciCommandPacket}; use crate::uci::command::UciCommand; use crate::uci::error::{Error, Result}; use crate::uci::message::UciMessage; -use crate::uci::notification::UciNotification; +use crate::uci::notification::{CoreNotification, SessionNotification, UciNotification}; use crate::uci::params::{ AppConfigTlv, AppConfigTlvType, CapTlv, Controlee, CoreSetConfigResponse, CountryCode, DeviceConfigId, DeviceConfigTlv, DeviceState, GetDeviceInfoResponse, PowerStats, @@ -566,7 +566,7 @@ impl<T: UciHal> UciManagerActor<T> { } match notf.clone() { - UciNotification::CoreDeviceStatus(status) => { + UciNotification::Core(CoreNotification::DeviceStatus(status)) => { if let Some(result_sender) = self.open_hal_result_sender.take() { let result = match status { DeviceState::DeviceStateReady | DeviceState::DeviceStateActive => { @@ -577,7 +577,11 @@ impl<T: UciHal> UciManagerActor<T> { let _ = result_sender.send(result); } } - UciNotification::SessionStatus { session_id, session_state, reason_code: _ } => { + UciNotification::Session(SessionNotification::Status { + session_id, + session_state, + reason_code: _, + }) => { if matches!(session_state, SessionState::SessionStateInit) { if let Err(e) = self.hal.notify_session_initialized(session_id).await { warn!("notify_session_initialized() failed: {:?}", e); |