66// for full license information.
77
88use super :: {
9- adapter:: uuid_to_bdaddr,
109 framework:: cb:: CBPeripheralState ,
1110 internal:: {
1211 CBPeripheralEvent , CoreBluetoothMessage , CoreBluetoothReply , CoreBluetoothReplyFuture ,
@@ -35,6 +34,9 @@ use tokio::sync::broadcast;
3534use tokio:: task;
3635use uuid:: Uuid ;
3736
37+ #[ derive( Clone , Debug , Eq , Hash , PartialEq ) ]
38+ pub struct PeripheralId ( Uuid ) ;
39+
3840/// Implementation of [api::Peripheral](crate::api::Peripheral).
3941#[ derive( Clone ) ]
4042pub struct Peripheral {
@@ -65,9 +67,7 @@ impl Peripheral {
6567 // Since we're building the object, we have an active advertisement.
6668 // Build properties now.
6769 let properties = Mutex :: from ( PeripheralProperties {
68- // Rumble required ONLY a BDAddr, not something you can get from
69- // MacOS, so we make it up for now. This sucks.
70- address : uuid_to_bdaddr ( & uuid. to_string ( ) ) ,
70+ address : BDAddr :: default ( ) ,
7171 address_type : None ,
7272 local_name,
7373 tx_power_level : None ,
@@ -108,7 +108,7 @@ impl Peripheral {
108108 shared
109109 . manager
110110 . emit ( CentralEvent :: ManufacturerDataAdvertisement {
111- address : properties . address ,
111+ id : shared . uuid . into ( ) ,
112112 manufacturer_data : properties. manufacturer_data . clone ( ) ,
113113 } ) ;
114114 }
@@ -117,7 +117,7 @@ impl Peripheral {
117117 properties. service_data . extend ( service_data. clone ( ) ) ;
118118
119119 shared. manager . emit ( CentralEvent :: ServiceDataAdvertisement {
120- address : properties . address ,
120+ id : shared . uuid . into ( ) ,
121121 service_data,
122122 } ) ;
123123 }
@@ -126,7 +126,7 @@ impl Peripheral {
126126 properties. services = services. clone ( ) ;
127127
128128 shared. manager . emit ( CentralEvent :: ServicesAdvertisement {
129- address : properties . address ,
129+ id : shared . uuid . into ( ) ,
130130 services,
131131 } ) ;
132132 }
@@ -169,10 +169,12 @@ impl Debug for Peripheral {
169169
170170#[ async_trait]
171171impl api:: Peripheral for Peripheral {
172+ fn id ( & self ) -> PeripheralId {
173+ PeripheralId ( self . shared . uuid )
174+ }
175+
172176 fn address ( & self ) -> BDAddr {
173- // TODO: look at moving/copying address out of properties so we don't have to
174- // take a lock here! (the address for the peripheral won't ever change)
175- self . shared . properties . lock ( ) . unwrap ( ) . address
177+ BDAddr :: default ( )
176178 }
177179
178180 async fn properties ( & self ) -> Result < Option < PeripheralProperties > > {
@@ -215,11 +217,9 @@ impl api::Peripheral for Peripheral {
215217 match fut. await {
216218 CoreBluetoothReply :: Connected ( chars) => {
217219 * ( self . shared . characteristics . lock ( ) . unwrap ( ) ) = chars;
218- self . shared . manager . emit ( CentralEvent :: DeviceConnected (
219- // TODO: look at moving/copying address out of properties so we don't have to
220- // take a lock here! (the address for the peripheral won't ever change)
221- self . shared . properties . lock ( ) . unwrap ( ) . address ,
222- ) ) ;
220+ self . shared
221+ . manager
222+ . emit ( CentralEvent :: DeviceConnected ( self . shared . uuid . into ( ) ) ) ;
223223 }
224224 _ => panic ! ( "Shouldn't get anything but connected!" ) ,
225225 }
@@ -333,6 +333,12 @@ impl api::Peripheral for Peripheral {
333333 }
334334}
335335
336+ impl From < Uuid > for PeripheralId {
337+ fn from ( uuid : Uuid ) -> Self {
338+ PeripheralId ( uuid)
339+ }
340+ }
341+
336342impl From < SendError > for Error {
337343 fn from ( _: SendError ) -> Self {
338344 Error :: Other ( "Channel closed" . to_string ( ) . into ( ) )
0 commit comments