| 974 | } |
| 975 | |
| 976 | fn write_value( |
| 977 | &mut self, |
| 978 | peripheral_uuid: Uuid, |
| 979 | service_uuid: Uuid, |
| 980 | characteristic_uuid: Uuid, |
| 981 | data: Vec<u8>, |
| 982 | kind: WriteType, |
| 983 | fut: CoreBluetoothReplyStateShared, |
| 984 | ) { |
| 985 | if let Some(peripheral) = self.peripherals.get_mut(&peripheral_uuid) { |
| 986 | if let Some(service) = peripheral.services.get_mut(&service_uuid) { |
| 987 | if let Some(characteristic) = service.characteristics.get_mut(&characteristic_uuid) |
| 988 | { |
| 989 | trace!("Writing value! With kind {:?}", kind); |
| 990 | match kind { |
| 991 | WriteType::WithoutResponse => { |
| 992 | if unsafe { peripheral.peripheral.canSendWriteWithoutResponse() } { |
| 993 | unsafe { |
| 994 | peripheral.peripheral.writeValue_forCharacteristic_type( |
| 995 | &NSData::from_vec(data), |
| 996 | &characteristic.characteristic, |
| 997 | CBCharacteristicWriteType::CBCharacteristicWriteWithoutResponse, |
| 998 | ); |
| 999 | } |
| 1000 | fut.lock().unwrap().set_reply(CoreBluetoothReply::Ok); |
| 1001 | } else { |
| 1002 | trace!("Queueing write-without-response (peripheral not ready)"); |
| 1003 | peripheral.write_without_response_queue.push_back( |
| 1004 | PendingWriteWithoutResponse { |
| 1005 | service_uuid, |
| 1006 | characteristic_uuid, |
| 1007 | data, |
| 1008 | fut, |
| 1009 | }, |
| 1010 | ); |
| 1011 | } |
| 1012 | } |
| 1013 | WriteType::WithResponse => { |
| 1014 | unsafe { |
| 1015 | peripheral.peripheral.writeValue_forCharacteristic_type( |
| 1016 | &NSData::from_vec(data), |
| 1017 | &characteristic.characteristic, |
| 1018 | CBCharacteristicWriteType::CBCharacteristicWriteWithResponse, |
| 1019 | ); |
| 1020 | } |
| 1021 | characteristic.write_future_state.push_front(fut); |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | fn drain_write_without_response_queue(&mut self, peripheral_uuid: Uuid) { |
| 1030 | if let Some(peripheral) = self.peripherals.get_mut(&peripheral_uuid) { |