From 10772095e7574d3dd83152ed9f182e25df3464ca Mon Sep 17 00:00:00 2001 From: Przemyslaw Wegrzyn Date: Sun, 6 Oct 2024 18:04:29 +0200 Subject: [PATCH] Enforce BLEClient creation via BLEDevice instance. --- src/ble_device.rs | 8 ++++++-- src/client/ble_client.rs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ble_device.rs b/src/ble_device.rs index b84b8a7..c1dc218 100644 --- a/src/ble_device.rs +++ b/src/ble_device.rs @@ -8,8 +8,8 @@ use esp_idf_sys::{esp, esp_nofail, EspError}; use once_cell::sync::Lazy; use crate::{ - ble, enums::*, utilities::mutex::Mutex, BLEAddress, BLEAddressType, BLEError, BLESecurity, - BLEServer, + ble, enums::*, utilities::mutex::Mutex, BLEAddress, BLEAddressType, BLEClient, BLEError, + BLESecurity, BLEServer, }; #[cfg(not(esp_idf_bt_nimble_ext_adv))] @@ -149,6 +149,10 @@ impl BLEDevice { Ok(()) } + pub fn new_client(&self) -> BLEClient { + BLEClient::new() + } + pub fn get_server(&self) -> &'static mut BLEServer { unsafe { Lazy::force_mut(&mut BLE_SERVER) } } diff --git a/src/client/ble_client.rs b/src/client/ble_client.rs index c65755c..dc12ff1 100644 --- a/src/client/ble_client.rs +++ b/src/client/ble_client.rs @@ -28,7 +28,7 @@ pub struct BLEClient { } impl BLEClient { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self { state: ArcUnsafeCell::new(BLEClientState { address: None,