summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorziyiw <ziyiw@google.com>2022-03-01 21:36:31 +0000
committerziyiw <ziyiw@google.com>2022-03-01 23:23:41 +0000
commit011c2f24ba292241958b358347328b1c91cc2840 (patch)
tree8a12e5ae5f166f70a8aa2a67bbb6912b8a091175 /src
parentc3aab1e047396f54d95cd76ca09ccba797e5bac2 (diff)
downloaduwb-011c2f24ba292241958b358347328b1c91cc2840.tar.gz
Change the wrapper of UwbAdaptation to Arc.
Test: UwbManagerTest Bug: 216512326 Change-Id: Ieba46c57e33c2729a7cc8349fb4508b8d7240b29
Diffstat (limited to 'src')
-rw-r--r--src/rust/adaptation/mod.rs12
-rw-r--r--src/rust/uci/mod.rs16
2 files changed, 14 insertions, 14 deletions
diff --git a/src/rust/adaptation/mod.rs b/src/rust/adaptation/mod.rs
index 2dfbcc1..80ec6b2 100644
--- a/src/rust/adaptation/mod.rs
+++ b/src/rust/adaptation/mod.rs
@@ -188,26 +188,26 @@ pub mod tests {
}
#[allow(dead_code)]
- pub fn expect_finalize(&mut self, expected_exit_status: bool) {
+ pub fn expect_finalize(&self, expected_exit_status: bool) {
self.expected_calls
.lock()
.unwrap()
.push_back(ExpectedCall::Finalize { expected_exit_status });
}
#[allow(dead_code)]
- pub fn expect_hal_open(&mut self, out: Result<()>) {
+ pub fn expect_hal_open(&self, out: Result<()>) {
self.expected_calls.lock().unwrap().push_back(ExpectedCall::HalOpen { out });
}
#[allow(dead_code)]
- pub fn expect_hal_close(&mut self, out: Result<()>) {
+ pub fn expect_hal_close(&self, out: Result<()>) {
self.expected_calls.lock().unwrap().push_back(ExpectedCall::HalClose { out });
}
#[allow(dead_code)]
- pub fn expect_core_initialization(&mut self, out: Result<()>) {
+ pub fn expect_core_initialization(&self, out: Result<()>) {
self.expected_calls.lock().unwrap().push_back(ExpectedCall::CoreInitialization { out });
}
#[allow(dead_code)]
- pub fn expect_session_initialization(&mut self, expected_session_id: i32, out: Result<()>) {
+ pub fn expect_session_initialization(&self, expected_session_id: i32, out: Result<()>) {
self.expected_calls
.lock()
.unwrap()
@@ -215,7 +215,7 @@ pub mod tests {
}
#[allow(dead_code)]
pub fn expect_send_uci_message(
- &mut self,
+ &self,
expected_data: Vec<u8>,
rsp_data: Option<Vec<u8>>,
notf_data: Option<Vec<u8>>,
diff --git a/src/rust/uci/mod.rs b/src/rust/uci/mod.rs
index 44acf11..a5749e2 100644
--- a/src/rust/uci/mod.rs
+++ b/src/rust/uci/mod.rs
@@ -41,7 +41,7 @@ use uwb_uci_packets::{
pub type Result<T> = std::result::Result<T, UwbErr>;
pub type UciResponseHandle = oneshot::Sender<UciResponse>;
-type SyncUwbAdaptation = Box<dyn UwbAdaptation + std::marker::Send + std::marker::Sync>;
+type SyncUwbAdaptation = Arc<dyn UwbAdaptation + Send + Sync>;
// Commands sent from JNI.
#[derive(Debug)]
@@ -151,7 +151,7 @@ impl Retryer {
self.failed.notify_one()
}
- fn send_with_retry(self, adaptation: Arc<SyncUwbAdaptation>, cmd: UciCommandPacket) {
+ fn send_with_retry(self, adaptation: SyncUwbAdaptation, cmd: UciCommandPacket) {
tokio::task::spawn(async move {
let mut received_response = false;
for retry in 0..MAX_RETRIES {
@@ -188,7 +188,7 @@ async fn option_future<R, T: Future<Output = R>>(mf: Option<T>) -> Option<R> {
}
struct Driver<T: EventManager> {
- adaptation: Arc<SyncUwbAdaptation>,
+ adaptation: SyncUwbAdaptation,
event_manager: T,
cmd_receiver: mpsc::UnboundedReceiver<(JNICommand, Option<UciResponseHandle>)>,
rsp_receiver: mpsc::UnboundedReceiver<HalCallback>,
@@ -203,7 +203,7 @@ async fn drive<T: EventManager + Send + Sync>(
cmd_receiver: mpsc::UnboundedReceiver<(JNICommand, Option<UciResponseHandle>)>,
rsp_receiver: mpsc::UnboundedReceiver<HalCallback>,
) -> Result<()> {
- Driver::new(Arc::new(adaptation), event_manager, cmd_receiver, rsp_receiver).await.drive().await
+ Driver::new(adaptation, event_manager, cmd_receiver, rsp_receiver).await.drive().await
}
const MAX_RETRIES: usize = 5;
@@ -211,7 +211,7 @@ const RETRY_DELAY_MS: u64 = 800;
impl<T: EventManager> Driver<T> {
async fn new(
- adaptation: Arc<SyncUwbAdaptation>,
+ adaptation: SyncUwbAdaptation,
event_manager: T,
cmd_receiver: mpsc::UnboundedReceiver<(JNICommand, Option<UciResponseHandle>)>,
rsp_receiver: mpsc::UnboundedReceiver<HalCallback>,
@@ -467,7 +467,7 @@ impl Dispatcher {
pub fn new<T: 'static + EventManager + Send + Sync>(event_manager: T) -> Result<Self> {
let (rsp_sender, rsp_receiver) = mpsc::unbounded_channel::<HalCallback>();
// TODO when simplifying constructors, avoid spare runtime
- let adaptation: SyncUwbAdaptation = Box::new(
+ let adaptation: SyncUwbAdaptation = Arc::new(
Builder::new_current_thread().build()?.block_on(UwbAdaptationImpl::new(rsp_sender))?,
);
@@ -539,7 +539,7 @@ mod tests {
use uwb_uci_packets::{DeviceState, DeviceStatusNtfBuilder, GetDeviceInfoRspBuilder, Packet};
fn setup_dispatcher(
- config_fn: fn(&mut Box<MockUwbAdaptation>, &mut MockEventManager),
+ config_fn: fn(&mut Arc<MockUwbAdaptation>, &mut MockEventManager),
) -> Result<Dispatcher> {
// TODO: Remove this once we call it somewhere real.
logger::init(
@@ -547,7 +547,7 @@ mod tests {
);
let (rsp_sender, rsp_receiver) = mpsc::unbounded_channel::<HalCallback>();
- let mut mock_adaptation = Box::new(MockUwbAdaptation::new(rsp_sender));
+ let mut mock_adaptation = Arc::new(MockUwbAdaptation::new(rsp_sender));
let mut mock_event_manager = MockEventManager::new();
config_fn(&mut mock_adaptation, &mut mock_event_manager);