Skip to main content

browser_protocol/bluetoothemulation/
mod.rs

1//! This domain allows configuring virtual Bluetooth devices to test
2//! the web-bluetooth API.
3
4
5use serde::{Serialize, Deserialize};
6use serde_json::Value as JsonValue;
7use std::borrow::Cow;
8
9/// Indicates the various states of Central.
10
11#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
12pub enum CentralState {
13    #[default]
14    #[serde(rename = "absent")]
15    Absent,
16    #[serde(rename = "powered-off")]
17    PoweredOff,
18    #[serde(rename = "powered-on")]
19    PoweredOn,
20}
21
22/// Indicates the various types of GATT event.
23
24#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
25pub enum GATTOperationType {
26    #[default]
27    #[serde(rename = "connection")]
28    Connection,
29    #[serde(rename = "discovery")]
30    Discovery,
31}
32
33/// Indicates the various types of characteristic write.
34
35#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
36pub enum CharacteristicWriteType {
37    #[default]
38    #[serde(rename = "write-default-deprecated")]
39    WriteDefaultDeprecated,
40    #[serde(rename = "write-with-response")]
41    WriteWithResponse,
42    #[serde(rename = "write-without-response")]
43    WriteWithoutResponse,
44}
45
46/// Indicates the various types of characteristic operation.
47
48#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
49pub enum CharacteristicOperationType {
50    #[default]
51    #[serde(rename = "read")]
52    Read,
53    #[serde(rename = "write")]
54    Write,
55    #[serde(rename = "subscribe-to-notifications")]
56    SubscribeToNotifications,
57    #[serde(rename = "unsubscribe-from-notifications")]
58    UnsubscribeFromNotifications,
59}
60
61/// Indicates the various types of descriptor operation.
62
63#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
64pub enum DescriptorOperationType {
65    #[default]
66    #[serde(rename = "read")]
67    Read,
68    #[serde(rename = "write")]
69    Write,
70}
71
72/// Stores the manufacturer data
73
74#[derive(Debug, Clone, Serialize, Deserialize, Default)]
75#[serde(rename_all = "camelCase")]
76pub struct ManufacturerData<'a> {
77    /// Company identifier
78    /// <https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/company_identifiers/company_identifiers.yaml>
79    /// <https://usb.org/developers>
80    key: i64,
81    /// Manufacturer-specific data (Encoded as a base64 string when passed over JSON)
82    data: Cow<'a, str>,
83}
84
85impl<'a> ManufacturerData<'a> {
86    /// Creates a builder for this type with the required parameters:
87    /// * `key`: Company identifier <https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/company_identifiers/company_identifiers.yaml> <https://usb.org/developers>
88    /// * `data`: Manufacturer-specific data (Encoded as a base64 string when passed over JSON)
89    pub fn builder(key: i64, data: impl Into<Cow<'a, str>>) -> ManufacturerDataBuilder<'a> {
90        ManufacturerDataBuilder {
91            key: key,
92            data: data.into(),
93        }
94    }
95    /// Company identifier
96    /// <https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/company_identifiers/company_identifiers.yaml>
97    /// <https://usb.org/developers>
98    pub fn key(&self) -> i64 { self.key }
99    /// Manufacturer-specific data (Encoded as a base64 string when passed over JSON)
100    pub fn data(&self) -> &str { self.data.as_ref() }
101}
102
103
104pub struct ManufacturerDataBuilder<'a> {
105    key: i64,
106    data: Cow<'a, str>,
107}
108
109impl<'a> ManufacturerDataBuilder<'a> {
110    pub fn build(self) -> ManufacturerData<'a> {
111        ManufacturerData {
112            key: self.key,
113            data: self.data,
114        }
115    }
116}
117
118/// Stores the byte data of the advertisement packet sent by a Bluetooth device.
119
120#[derive(Debug, Clone, Serialize, Deserialize, Default)]
121#[serde(rename_all = "camelCase")]
122pub struct ScanRecord<'a> {
123    #[serde(skip_serializing_if = "Option::is_none")]
124    name: Option<Cow<'a, str>>,
125    #[serde(skip_serializing_if = "Option::is_none")]
126    uuids: Option<Vec<Cow<'a, str>>>,
127    /// Stores the external appearance description of the device.
128    #[serde(skip_serializing_if = "Option::is_none")]
129    appearance: Option<i64>,
130    /// Stores the transmission power of a broadcasting device.
131    #[serde(skip_serializing_if = "Option::is_none", rename = "txPower")]
132    tx_power: Option<i64>,
133    /// Key is the company identifier and the value is an array of bytes of
134    /// manufacturer specific data.
135    #[serde(skip_serializing_if = "Option::is_none", rename = "manufacturerData")]
136    manufacturer_data: Option<Vec<ManufacturerData<'a>>>,
137}
138
139impl<'a> ScanRecord<'a> {
140    /// Creates a builder for this type.
141    pub fn builder() -> ScanRecordBuilder<'a> {
142        ScanRecordBuilder {
143            name: None,
144            uuids: None,
145            appearance: None,
146            tx_power: None,
147            manufacturer_data: None,
148        }
149    }
150    pub fn name(&self) -> Option<&str> { self.name.as_deref() }
151    pub fn uuids(&self) -> Option<&[Cow<'a, str>]> { self.uuids.as_deref() }
152    /// Stores the external appearance description of the device.
153    pub fn appearance(&self) -> Option<i64> { self.appearance }
154    /// Stores the transmission power of a broadcasting device.
155    pub fn tx_power(&self) -> Option<i64> { self.tx_power }
156    /// Key is the company identifier and the value is an array of bytes of
157    /// manufacturer specific data.
158    pub fn manufacturer_data(&self) -> Option<&[ManufacturerData<'a>]> { self.manufacturer_data.as_deref() }
159}
160
161#[derive(Default)]
162pub struct ScanRecordBuilder<'a> {
163    name: Option<Cow<'a, str>>,
164    uuids: Option<Vec<Cow<'a, str>>>,
165    appearance: Option<i64>,
166    tx_power: Option<i64>,
167    manufacturer_data: Option<Vec<ManufacturerData<'a>>>,
168}
169
170impl<'a> ScanRecordBuilder<'a> {
171    pub fn name(mut self, name: impl Into<Cow<'a, str>>) -> Self { self.name = Some(name.into()); self }
172    pub fn uuids(mut self, uuids: Vec<Cow<'a, str>>) -> Self { self.uuids = Some(uuids); self }
173    /// Stores the external appearance description of the device.
174    pub fn appearance(mut self, appearance: i64) -> Self { self.appearance = Some(appearance); self }
175    /// Stores the transmission power of a broadcasting device.
176    pub fn tx_power(mut self, tx_power: i64) -> Self { self.tx_power = Some(tx_power); self }
177    /// Key is the company identifier and the value is an array of bytes of
178    /// manufacturer specific data.
179    pub fn manufacturer_data(mut self, manufacturer_data: Vec<ManufacturerData<'a>>) -> Self { self.manufacturer_data = Some(manufacturer_data); self }
180    pub fn build(self) -> ScanRecord<'a> {
181        ScanRecord {
182            name: self.name,
183            uuids: self.uuids,
184            appearance: self.appearance,
185            tx_power: self.tx_power,
186            manufacturer_data: self.manufacturer_data,
187        }
188    }
189}
190
191/// Stores the advertisement packet information that is sent by a Bluetooth device.
192
193#[derive(Debug, Clone, Serialize, Deserialize, Default)]
194#[serde(rename_all = "camelCase")]
195pub struct ScanEntry<'a> {
196    #[serde(rename = "deviceAddress")]
197    device_address: Cow<'a, str>,
198    rssi: i64,
199    #[serde(rename = "scanRecord")]
200    scan_record: ScanRecord<'a>,
201}
202
203impl<'a> ScanEntry<'a> {
204    /// Creates a builder for this type with the required parameters:
205    /// * `device_address`: 
206    /// * `rssi`: 
207    /// * `scan_record`: 
208    pub fn builder(device_address: impl Into<Cow<'a, str>>, rssi: i64, scan_record: ScanRecord<'a>) -> ScanEntryBuilder<'a> {
209        ScanEntryBuilder {
210            device_address: device_address.into(),
211            rssi: rssi,
212            scan_record: scan_record,
213        }
214    }
215    pub fn device_address(&self) -> &str { self.device_address.as_ref() }
216    pub fn rssi(&self) -> i64 { self.rssi }
217    pub fn scan_record(&self) -> &ScanRecord<'a> { &self.scan_record }
218}
219
220
221pub struct ScanEntryBuilder<'a> {
222    device_address: Cow<'a, str>,
223    rssi: i64,
224    scan_record: ScanRecord<'a>,
225}
226
227impl<'a> ScanEntryBuilder<'a> {
228    pub fn build(self) -> ScanEntry<'a> {
229        ScanEntry {
230            device_address: self.device_address,
231            rssi: self.rssi,
232            scan_record: self.scan_record,
233        }
234    }
235}
236
237/// Describes the properties of a characteristic. This follows Bluetooth Core
238/// Specification BT 4.2 Vol 3 Part G 3.3.1. Characteristic Properties.
239
240#[derive(Debug, Clone, Serialize, Deserialize, Default)]
241#[serde(rename_all = "camelCase")]
242pub struct CharacteristicProperties {
243    #[serde(skip_serializing_if = "Option::is_none")]
244    broadcast: Option<bool>,
245    #[serde(skip_serializing_if = "Option::is_none")]
246    read: Option<bool>,
247    #[serde(skip_serializing_if = "Option::is_none", rename = "writeWithoutResponse")]
248    write_without_response: Option<bool>,
249    #[serde(skip_serializing_if = "Option::is_none")]
250    write: Option<bool>,
251    #[serde(skip_serializing_if = "Option::is_none")]
252    notify: Option<bool>,
253    #[serde(skip_serializing_if = "Option::is_none")]
254    indicate: Option<bool>,
255    #[serde(skip_serializing_if = "Option::is_none", rename = "authenticatedSignedWrites")]
256    authenticated_signed_writes: Option<bool>,
257    #[serde(skip_serializing_if = "Option::is_none", rename = "extendedProperties")]
258    extended_properties: Option<bool>,
259}
260
261impl CharacteristicProperties {
262    /// Creates a builder for this type.
263    pub fn builder() -> CharacteristicPropertiesBuilder {
264        CharacteristicPropertiesBuilder {
265            broadcast: None,
266            read: None,
267            write_without_response: None,
268            write: None,
269            notify: None,
270            indicate: None,
271            authenticated_signed_writes: None,
272            extended_properties: None,
273        }
274    }
275    pub fn broadcast(&self) -> Option<bool> { self.broadcast }
276    pub fn read(&self) -> Option<bool> { self.read }
277    pub fn write_without_response(&self) -> Option<bool> { self.write_without_response }
278    pub fn write(&self) -> Option<bool> { self.write }
279    pub fn notify(&self) -> Option<bool> { self.notify }
280    pub fn indicate(&self) -> Option<bool> { self.indicate }
281    pub fn authenticated_signed_writes(&self) -> Option<bool> { self.authenticated_signed_writes }
282    pub fn extended_properties(&self) -> Option<bool> { self.extended_properties }
283}
284
285#[derive(Default)]
286pub struct CharacteristicPropertiesBuilder {
287    broadcast: Option<bool>,
288    read: Option<bool>,
289    write_without_response: Option<bool>,
290    write: Option<bool>,
291    notify: Option<bool>,
292    indicate: Option<bool>,
293    authenticated_signed_writes: Option<bool>,
294    extended_properties: Option<bool>,
295}
296
297impl CharacteristicPropertiesBuilder {
298    pub fn broadcast(mut self, broadcast: bool) -> Self { self.broadcast = Some(broadcast); self }
299    pub fn read(mut self, read: bool) -> Self { self.read = Some(read); self }
300    pub fn write_without_response(mut self, write_without_response: bool) -> Self { self.write_without_response = Some(write_without_response); self }
301    pub fn write(mut self, write: bool) -> Self { self.write = Some(write); self }
302    pub fn notify(mut self, notify: bool) -> Self { self.notify = Some(notify); self }
303    pub fn indicate(mut self, indicate: bool) -> Self { self.indicate = Some(indicate); self }
304    pub fn authenticated_signed_writes(mut self, authenticated_signed_writes: bool) -> Self { self.authenticated_signed_writes = Some(authenticated_signed_writes); self }
305    pub fn extended_properties(mut self, extended_properties: bool) -> Self { self.extended_properties = Some(extended_properties); self }
306    pub fn build(self) -> CharacteristicProperties {
307        CharacteristicProperties {
308            broadcast: self.broadcast,
309            read: self.read,
310            write_without_response: self.write_without_response,
311            write: self.write,
312            notify: self.notify,
313            indicate: self.indicate,
314            authenticated_signed_writes: self.authenticated_signed_writes,
315            extended_properties: self.extended_properties,
316        }
317    }
318}
319
320/// Enable the BluetoothEmulation domain.
321
322#[derive(Debug, Clone, Serialize, Deserialize, Default)]
323#[serde(rename_all = "camelCase")]
324pub struct EnableParams {
325    /// State of the simulated central.
326    state: CentralState,
327    /// If the simulated central supports low-energy.
328    #[serde(rename = "leSupported")]
329    le_supported: bool,
330}
331
332impl EnableParams {
333    /// Creates a builder for this type with the required parameters:
334    /// * `state`: State of the simulated central.
335    /// * `le_supported`: If the simulated central supports low-energy.
336    pub fn builder(state: impl Into<CentralState>, le_supported: bool) -> EnableParamsBuilder {
337        EnableParamsBuilder {
338            state: state.into(),
339            le_supported: le_supported,
340        }
341    }
342    /// State of the simulated central.
343    pub fn state(&self) -> &CentralState { &self.state }
344    /// If the simulated central supports low-energy.
345    pub fn le_supported(&self) -> bool { self.le_supported }
346}
347
348
349pub struct EnableParamsBuilder {
350    state: CentralState,
351    le_supported: bool,
352}
353
354impl EnableParamsBuilder {
355    pub fn build(self) -> EnableParams {
356        EnableParams {
357            state: self.state,
358            le_supported: self.le_supported,
359        }
360    }
361}
362
363impl EnableParams { pub const METHOD: &'static str = "BluetoothEmulation.enable"; }
364
365impl<'a> crate::CdpCommand<'a> for EnableParams {
366    const METHOD: &'static str = "BluetoothEmulation.enable";
367    type Response = crate::EmptyReturns;
368}
369
370/// Set the state of the simulated central.
371
372#[derive(Debug, Clone, Serialize, Deserialize, Default)]
373#[serde(rename_all = "camelCase")]
374pub struct SetSimulatedCentralStateParams {
375    /// State of the simulated central.
376    state: CentralState,
377}
378
379impl SetSimulatedCentralStateParams {
380    /// Creates a builder for this type with the required parameters:
381    /// * `state`: State of the simulated central.
382    pub fn builder(state: impl Into<CentralState>) -> SetSimulatedCentralStateParamsBuilder {
383        SetSimulatedCentralStateParamsBuilder {
384            state: state.into(),
385        }
386    }
387    /// State of the simulated central.
388    pub fn state(&self) -> &CentralState { &self.state }
389}
390
391
392pub struct SetSimulatedCentralStateParamsBuilder {
393    state: CentralState,
394}
395
396impl SetSimulatedCentralStateParamsBuilder {
397    pub fn build(self) -> SetSimulatedCentralStateParams {
398        SetSimulatedCentralStateParams {
399            state: self.state,
400        }
401    }
402}
403
404impl SetSimulatedCentralStateParams { pub const METHOD: &'static str = "BluetoothEmulation.setSimulatedCentralState"; }
405
406impl<'a> crate::CdpCommand<'a> for SetSimulatedCentralStateParams {
407    const METHOD: &'static str = "BluetoothEmulation.setSimulatedCentralState";
408    type Response = crate::EmptyReturns;
409}
410
411#[derive(Debug, Clone, Serialize, Deserialize, Default)]
412pub struct DisableParams {}
413
414impl DisableParams { pub const METHOD: &'static str = "BluetoothEmulation.disable"; }
415
416impl<'a> crate::CdpCommand<'a> for DisableParams {
417    const METHOD: &'static str = "BluetoothEmulation.disable";
418    type Response = crate::EmptyReturns;
419}
420
421/// Simulates a peripheral with |address|, |name| and |knownServiceUuids|
422/// that has already been connected to the system.
423
424#[derive(Debug, Clone, Serialize, Deserialize, Default)]
425#[serde(rename_all = "camelCase")]
426pub struct SimulatePreconnectedPeripheralParams<'a> {
427    address: Cow<'a, str>,
428    name: Cow<'a, str>,
429    #[serde(rename = "manufacturerData")]
430    manufacturer_data: Vec<ManufacturerData<'a>>,
431    #[serde(rename = "knownServiceUuids")]
432    known_service_uuids: Vec<Cow<'a, str>>,
433}
434
435impl<'a> SimulatePreconnectedPeripheralParams<'a> {
436    /// Creates a builder for this type with the required parameters:
437    /// * `address`: 
438    /// * `name`: 
439    /// * `manufacturer_data`: 
440    /// * `known_service_uuids`: 
441    pub fn builder(address: impl Into<Cow<'a, str>>, name: impl Into<Cow<'a, str>>, manufacturer_data: Vec<ManufacturerData<'a>>, known_service_uuids: Vec<Cow<'a, str>>) -> SimulatePreconnectedPeripheralParamsBuilder<'a> {
442        SimulatePreconnectedPeripheralParamsBuilder {
443            address: address.into(),
444            name: name.into(),
445            manufacturer_data: manufacturer_data,
446            known_service_uuids: known_service_uuids,
447        }
448    }
449    pub fn address(&self) -> &str { self.address.as_ref() }
450    pub fn name(&self) -> &str { self.name.as_ref() }
451    pub fn manufacturer_data(&self) -> &[ManufacturerData<'a>] { &self.manufacturer_data }
452    pub fn known_service_uuids(&self) -> &[Cow<'a, str>] { &self.known_service_uuids }
453}
454
455
456pub struct SimulatePreconnectedPeripheralParamsBuilder<'a> {
457    address: Cow<'a, str>,
458    name: Cow<'a, str>,
459    manufacturer_data: Vec<ManufacturerData<'a>>,
460    known_service_uuids: Vec<Cow<'a, str>>,
461}
462
463impl<'a> SimulatePreconnectedPeripheralParamsBuilder<'a> {
464    pub fn build(self) -> SimulatePreconnectedPeripheralParams<'a> {
465        SimulatePreconnectedPeripheralParams {
466            address: self.address,
467            name: self.name,
468            manufacturer_data: self.manufacturer_data,
469            known_service_uuids: self.known_service_uuids,
470        }
471    }
472}
473
474impl<'a> SimulatePreconnectedPeripheralParams<'a> { pub const METHOD: &'static str = "BluetoothEmulation.simulatePreconnectedPeripheral"; }
475
476impl<'a> crate::CdpCommand<'a> for SimulatePreconnectedPeripheralParams<'a> {
477    const METHOD: &'static str = "BluetoothEmulation.simulatePreconnectedPeripheral";
478    type Response = crate::EmptyReturns;
479}
480
481/// Simulates an advertisement packet described in |entry| being received by
482/// the central.
483
484#[derive(Debug, Clone, Serialize, Deserialize, Default)]
485#[serde(rename_all = "camelCase")]
486pub struct SimulateAdvertisementParams<'a> {
487    entry: ScanEntry<'a>,
488}
489
490impl<'a> SimulateAdvertisementParams<'a> {
491    /// Creates a builder for this type with the required parameters:
492    /// * `entry`: 
493    pub fn builder(entry: ScanEntry<'a>) -> SimulateAdvertisementParamsBuilder<'a> {
494        SimulateAdvertisementParamsBuilder {
495            entry: entry,
496        }
497    }
498    pub fn entry(&self) -> &ScanEntry<'a> { &self.entry }
499}
500
501
502pub struct SimulateAdvertisementParamsBuilder<'a> {
503    entry: ScanEntry<'a>,
504}
505
506impl<'a> SimulateAdvertisementParamsBuilder<'a> {
507    pub fn build(self) -> SimulateAdvertisementParams<'a> {
508        SimulateAdvertisementParams {
509            entry: self.entry,
510        }
511    }
512}
513
514impl<'a> SimulateAdvertisementParams<'a> { pub const METHOD: &'static str = "BluetoothEmulation.simulateAdvertisement"; }
515
516impl<'a> crate::CdpCommand<'a> for SimulateAdvertisementParams<'a> {
517    const METHOD: &'static str = "BluetoothEmulation.simulateAdvertisement";
518    type Response = crate::EmptyReturns;
519}
520
521/// Simulates the response code from the peripheral with |address| for a
522/// GATT operation of |type|. The |code| value follows the HCI Error Codes from
523/// Bluetooth Core Specification Vol 2 Part D 1.3 List Of Error Codes.
524
525#[derive(Debug, Clone, Serialize, Deserialize, Default)]
526#[serde(rename_all = "camelCase")]
527pub struct SimulateGATTOperationResponseParams<'a> {
528    address: Cow<'a, str>,
529    #[serde(rename = "type")]
530    type_: GATTOperationType,
531    code: i64,
532}
533
534impl<'a> SimulateGATTOperationResponseParams<'a> {
535    /// Creates a builder for this type with the required parameters:
536    /// * `address`: 
537    /// * `type_`: 
538    /// * `code`: 
539    pub fn builder(address: impl Into<Cow<'a, str>>, type_: impl Into<GATTOperationType>, code: i64) -> SimulateGATTOperationResponseParamsBuilder<'a> {
540        SimulateGATTOperationResponseParamsBuilder {
541            address: address.into(),
542            type_: type_.into(),
543            code: code,
544        }
545    }
546    pub fn address(&self) -> &str { self.address.as_ref() }
547    pub fn type_(&self) -> &GATTOperationType { &self.type_ }
548    pub fn code(&self) -> i64 { self.code }
549}
550
551
552pub struct SimulateGATTOperationResponseParamsBuilder<'a> {
553    address: Cow<'a, str>,
554    type_: GATTOperationType,
555    code: i64,
556}
557
558impl<'a> SimulateGATTOperationResponseParamsBuilder<'a> {
559    pub fn build(self) -> SimulateGATTOperationResponseParams<'a> {
560        SimulateGATTOperationResponseParams {
561            address: self.address,
562            type_: self.type_,
563            code: self.code,
564        }
565    }
566}
567
568impl<'a> SimulateGATTOperationResponseParams<'a> { pub const METHOD: &'static str = "BluetoothEmulation.simulateGATTOperationResponse"; }
569
570impl<'a> crate::CdpCommand<'a> for SimulateGATTOperationResponseParams<'a> {
571    const METHOD: &'static str = "BluetoothEmulation.simulateGATTOperationResponse";
572    type Response = crate::EmptyReturns;
573}
574
575/// Simulates the response from the characteristic with |characteristicId| for a
576/// characteristic operation of |type|. The |code| value follows the Error
577/// Codes from Bluetooth Core Specification Vol 3 Part F 3.4.1.1 Error Response.
578/// The |data| is expected to exist when simulating a successful read operation
579/// response.
580
581#[derive(Debug, Clone, Serialize, Deserialize, Default)]
582#[serde(rename_all = "camelCase")]
583pub struct SimulateCharacteristicOperationResponseParams<'a> {
584    #[serde(rename = "characteristicId")]
585    characteristic_id: Cow<'a, str>,
586    #[serde(rename = "type")]
587    type_: CharacteristicOperationType,
588    code: i64,
589    #[serde(skip_serializing_if = "Option::is_none")]
590    data: Option<Cow<'a, str>>,
591}
592
593impl<'a> SimulateCharacteristicOperationResponseParams<'a> {
594    /// Creates a builder for this type with the required parameters:
595    /// * `characteristic_id`: 
596    /// * `type_`: 
597    /// * `code`: 
598    pub fn builder(characteristic_id: impl Into<Cow<'a, str>>, type_: impl Into<CharacteristicOperationType>, code: i64) -> SimulateCharacteristicOperationResponseParamsBuilder<'a> {
599        SimulateCharacteristicOperationResponseParamsBuilder {
600            characteristic_id: characteristic_id.into(),
601            type_: type_.into(),
602            code: code,
603            data: None,
604        }
605    }
606    pub fn characteristic_id(&self) -> &str { self.characteristic_id.as_ref() }
607    pub fn type_(&self) -> &CharacteristicOperationType { &self.type_ }
608    pub fn code(&self) -> i64 { self.code }
609    pub fn data(&self) -> Option<&str> { self.data.as_deref() }
610}
611
612
613pub struct SimulateCharacteristicOperationResponseParamsBuilder<'a> {
614    characteristic_id: Cow<'a, str>,
615    type_: CharacteristicOperationType,
616    code: i64,
617    data: Option<Cow<'a, str>>,
618}
619
620impl<'a> SimulateCharacteristicOperationResponseParamsBuilder<'a> {
621    pub fn data(mut self, data: impl Into<Cow<'a, str>>) -> Self { self.data = Some(data.into()); self }
622    pub fn build(self) -> SimulateCharacteristicOperationResponseParams<'a> {
623        SimulateCharacteristicOperationResponseParams {
624            characteristic_id: self.characteristic_id,
625            type_: self.type_,
626            code: self.code,
627            data: self.data,
628        }
629    }
630}
631
632impl<'a> SimulateCharacteristicOperationResponseParams<'a> { pub const METHOD: &'static str = "BluetoothEmulation.simulateCharacteristicOperationResponse"; }
633
634impl<'a> crate::CdpCommand<'a> for SimulateCharacteristicOperationResponseParams<'a> {
635    const METHOD: &'static str = "BluetoothEmulation.simulateCharacteristicOperationResponse";
636    type Response = crate::EmptyReturns;
637}
638
639/// Simulates the response from the descriptor with |descriptorId| for a
640/// descriptor operation of |type|. The |code| value follows the Error
641/// Codes from Bluetooth Core Specification Vol 3 Part F 3.4.1.1 Error Response.
642/// The |data| is expected to exist when simulating a successful read operation
643/// response.
644
645#[derive(Debug, Clone, Serialize, Deserialize, Default)]
646#[serde(rename_all = "camelCase")]
647pub struct SimulateDescriptorOperationResponseParams<'a> {
648    #[serde(rename = "descriptorId")]
649    descriptor_id: Cow<'a, str>,
650    #[serde(rename = "type")]
651    type_: DescriptorOperationType,
652    code: i64,
653    #[serde(skip_serializing_if = "Option::is_none")]
654    data: Option<Cow<'a, str>>,
655}
656
657impl<'a> SimulateDescriptorOperationResponseParams<'a> {
658    /// Creates a builder for this type with the required parameters:
659    /// * `descriptor_id`: 
660    /// * `type_`: 
661    /// * `code`: 
662    pub fn builder(descriptor_id: impl Into<Cow<'a, str>>, type_: impl Into<DescriptorOperationType>, code: i64) -> SimulateDescriptorOperationResponseParamsBuilder<'a> {
663        SimulateDescriptorOperationResponseParamsBuilder {
664            descriptor_id: descriptor_id.into(),
665            type_: type_.into(),
666            code: code,
667            data: None,
668        }
669    }
670    pub fn descriptor_id(&self) -> &str { self.descriptor_id.as_ref() }
671    pub fn type_(&self) -> &DescriptorOperationType { &self.type_ }
672    pub fn code(&self) -> i64 { self.code }
673    pub fn data(&self) -> Option<&str> { self.data.as_deref() }
674}
675
676
677pub struct SimulateDescriptorOperationResponseParamsBuilder<'a> {
678    descriptor_id: Cow<'a, str>,
679    type_: DescriptorOperationType,
680    code: i64,
681    data: Option<Cow<'a, str>>,
682}
683
684impl<'a> SimulateDescriptorOperationResponseParamsBuilder<'a> {
685    pub fn data(mut self, data: impl Into<Cow<'a, str>>) -> Self { self.data = Some(data.into()); self }
686    pub fn build(self) -> SimulateDescriptorOperationResponseParams<'a> {
687        SimulateDescriptorOperationResponseParams {
688            descriptor_id: self.descriptor_id,
689            type_: self.type_,
690            code: self.code,
691            data: self.data,
692        }
693    }
694}
695
696impl<'a> SimulateDescriptorOperationResponseParams<'a> { pub const METHOD: &'static str = "BluetoothEmulation.simulateDescriptorOperationResponse"; }
697
698impl<'a> crate::CdpCommand<'a> for SimulateDescriptorOperationResponseParams<'a> {
699    const METHOD: &'static str = "BluetoothEmulation.simulateDescriptorOperationResponse";
700    type Response = crate::EmptyReturns;
701}
702
703/// Adds a service with |serviceUuid| to the peripheral with |address|.
704
705#[derive(Debug, Clone, Serialize, Deserialize, Default)]
706#[serde(rename_all = "camelCase")]
707pub struct AddServiceParams<'a> {
708    address: Cow<'a, str>,
709    #[serde(rename = "serviceUuid")]
710    service_uuid: Cow<'a, str>,
711}
712
713impl<'a> AddServiceParams<'a> {
714    /// Creates a builder for this type with the required parameters:
715    /// * `address`: 
716    /// * `service_uuid`: 
717    pub fn builder(address: impl Into<Cow<'a, str>>, service_uuid: impl Into<Cow<'a, str>>) -> AddServiceParamsBuilder<'a> {
718        AddServiceParamsBuilder {
719            address: address.into(),
720            service_uuid: service_uuid.into(),
721        }
722    }
723    pub fn address(&self) -> &str { self.address.as_ref() }
724    pub fn service_uuid(&self) -> &str { self.service_uuid.as_ref() }
725}
726
727
728pub struct AddServiceParamsBuilder<'a> {
729    address: Cow<'a, str>,
730    service_uuid: Cow<'a, str>,
731}
732
733impl<'a> AddServiceParamsBuilder<'a> {
734    pub fn build(self) -> AddServiceParams<'a> {
735        AddServiceParams {
736            address: self.address,
737            service_uuid: self.service_uuid,
738        }
739    }
740}
741
742/// Adds a service with |serviceUuid| to the peripheral with |address|.
743
744#[derive(Debug, Clone, Serialize, Deserialize, Default)]
745#[serde(rename_all = "camelCase")]
746pub struct AddServiceReturns<'a> {
747    /// An identifier that uniquely represents this service.
748    #[serde(rename = "serviceId")]
749    service_id: Cow<'a, str>,
750}
751
752impl<'a> AddServiceReturns<'a> {
753    /// Creates a builder for this type with the required parameters:
754    /// * `service_id`: An identifier that uniquely represents this service.
755    pub fn builder(service_id: impl Into<Cow<'a, str>>) -> AddServiceReturnsBuilder<'a> {
756        AddServiceReturnsBuilder {
757            service_id: service_id.into(),
758        }
759    }
760    /// An identifier that uniquely represents this service.
761    pub fn service_id(&self) -> &str { self.service_id.as_ref() }
762}
763
764
765pub struct AddServiceReturnsBuilder<'a> {
766    service_id: Cow<'a, str>,
767}
768
769impl<'a> AddServiceReturnsBuilder<'a> {
770    pub fn build(self) -> AddServiceReturns<'a> {
771        AddServiceReturns {
772            service_id: self.service_id,
773        }
774    }
775}
776
777impl<'a> AddServiceParams<'a> { pub const METHOD: &'static str = "BluetoothEmulation.addService"; }
778
779impl<'a> crate::CdpCommand<'a> for AddServiceParams<'a> {
780    const METHOD: &'static str = "BluetoothEmulation.addService";
781    type Response = AddServiceReturns<'a>;
782}
783
784/// Removes the service respresented by |serviceId| from the simulated central.
785
786#[derive(Debug, Clone, Serialize, Deserialize, Default)]
787#[serde(rename_all = "camelCase")]
788pub struct RemoveServiceParams<'a> {
789    #[serde(rename = "serviceId")]
790    service_id: Cow<'a, str>,
791}
792
793impl<'a> RemoveServiceParams<'a> {
794    /// Creates a builder for this type with the required parameters:
795    /// * `service_id`: 
796    pub fn builder(service_id: impl Into<Cow<'a, str>>) -> RemoveServiceParamsBuilder<'a> {
797        RemoveServiceParamsBuilder {
798            service_id: service_id.into(),
799        }
800    }
801    pub fn service_id(&self) -> &str { self.service_id.as_ref() }
802}
803
804
805pub struct RemoveServiceParamsBuilder<'a> {
806    service_id: Cow<'a, str>,
807}
808
809impl<'a> RemoveServiceParamsBuilder<'a> {
810    pub fn build(self) -> RemoveServiceParams<'a> {
811        RemoveServiceParams {
812            service_id: self.service_id,
813        }
814    }
815}
816
817impl<'a> RemoveServiceParams<'a> { pub const METHOD: &'static str = "BluetoothEmulation.removeService"; }
818
819impl<'a> crate::CdpCommand<'a> for RemoveServiceParams<'a> {
820    const METHOD: &'static str = "BluetoothEmulation.removeService";
821    type Response = crate::EmptyReturns;
822}
823
824/// Adds a characteristic with |characteristicUuid| and |properties| to the
825/// service represented by |serviceId|.
826
827#[derive(Debug, Clone, Serialize, Deserialize, Default)]
828#[serde(rename_all = "camelCase")]
829pub struct AddCharacteristicParams<'a> {
830    #[serde(rename = "serviceId")]
831    service_id: Cow<'a, str>,
832    #[serde(rename = "characteristicUuid")]
833    characteristic_uuid: Cow<'a, str>,
834    properties: CharacteristicProperties,
835}
836
837impl<'a> AddCharacteristicParams<'a> {
838    /// Creates a builder for this type with the required parameters:
839    /// * `service_id`: 
840    /// * `characteristic_uuid`: 
841    /// * `properties`: 
842    pub fn builder(service_id: impl Into<Cow<'a, str>>, characteristic_uuid: impl Into<Cow<'a, str>>, properties: CharacteristicProperties) -> AddCharacteristicParamsBuilder<'a> {
843        AddCharacteristicParamsBuilder {
844            service_id: service_id.into(),
845            characteristic_uuid: characteristic_uuid.into(),
846            properties: properties,
847        }
848    }
849    pub fn service_id(&self) -> &str { self.service_id.as_ref() }
850    pub fn characteristic_uuid(&self) -> &str { self.characteristic_uuid.as_ref() }
851    pub fn properties(&self) -> &CharacteristicProperties { &self.properties }
852}
853
854
855pub struct AddCharacteristicParamsBuilder<'a> {
856    service_id: Cow<'a, str>,
857    characteristic_uuid: Cow<'a, str>,
858    properties: CharacteristicProperties,
859}
860
861impl<'a> AddCharacteristicParamsBuilder<'a> {
862    pub fn build(self) -> AddCharacteristicParams<'a> {
863        AddCharacteristicParams {
864            service_id: self.service_id,
865            characteristic_uuid: self.characteristic_uuid,
866            properties: self.properties,
867        }
868    }
869}
870
871/// Adds a characteristic with |characteristicUuid| and |properties| to the
872/// service represented by |serviceId|.
873
874#[derive(Debug, Clone, Serialize, Deserialize, Default)]
875#[serde(rename_all = "camelCase")]
876pub struct AddCharacteristicReturns<'a> {
877    /// An identifier that uniquely represents this characteristic.
878    #[serde(rename = "characteristicId")]
879    characteristic_id: Cow<'a, str>,
880}
881
882impl<'a> AddCharacteristicReturns<'a> {
883    /// Creates a builder for this type with the required parameters:
884    /// * `characteristic_id`: An identifier that uniquely represents this characteristic.
885    pub fn builder(characteristic_id: impl Into<Cow<'a, str>>) -> AddCharacteristicReturnsBuilder<'a> {
886        AddCharacteristicReturnsBuilder {
887            characteristic_id: characteristic_id.into(),
888        }
889    }
890    /// An identifier that uniquely represents this characteristic.
891    pub fn characteristic_id(&self) -> &str { self.characteristic_id.as_ref() }
892}
893
894
895pub struct AddCharacteristicReturnsBuilder<'a> {
896    characteristic_id: Cow<'a, str>,
897}
898
899impl<'a> AddCharacteristicReturnsBuilder<'a> {
900    pub fn build(self) -> AddCharacteristicReturns<'a> {
901        AddCharacteristicReturns {
902            characteristic_id: self.characteristic_id,
903        }
904    }
905}
906
907impl<'a> AddCharacteristicParams<'a> { pub const METHOD: &'static str = "BluetoothEmulation.addCharacteristic"; }
908
909impl<'a> crate::CdpCommand<'a> for AddCharacteristicParams<'a> {
910    const METHOD: &'static str = "BluetoothEmulation.addCharacteristic";
911    type Response = AddCharacteristicReturns<'a>;
912}
913
914/// Removes the characteristic respresented by |characteristicId| from the
915/// simulated central.
916
917#[derive(Debug, Clone, Serialize, Deserialize, Default)]
918#[serde(rename_all = "camelCase")]
919pub struct RemoveCharacteristicParams<'a> {
920    #[serde(rename = "characteristicId")]
921    characteristic_id: Cow<'a, str>,
922}
923
924impl<'a> RemoveCharacteristicParams<'a> {
925    /// Creates a builder for this type with the required parameters:
926    /// * `characteristic_id`: 
927    pub fn builder(characteristic_id: impl Into<Cow<'a, str>>) -> RemoveCharacteristicParamsBuilder<'a> {
928        RemoveCharacteristicParamsBuilder {
929            characteristic_id: characteristic_id.into(),
930        }
931    }
932    pub fn characteristic_id(&self) -> &str { self.characteristic_id.as_ref() }
933}
934
935
936pub struct RemoveCharacteristicParamsBuilder<'a> {
937    characteristic_id: Cow<'a, str>,
938}
939
940impl<'a> RemoveCharacteristicParamsBuilder<'a> {
941    pub fn build(self) -> RemoveCharacteristicParams<'a> {
942        RemoveCharacteristicParams {
943            characteristic_id: self.characteristic_id,
944        }
945    }
946}
947
948impl<'a> RemoveCharacteristicParams<'a> { pub const METHOD: &'static str = "BluetoothEmulation.removeCharacteristic"; }
949
950impl<'a> crate::CdpCommand<'a> for RemoveCharacteristicParams<'a> {
951    const METHOD: &'static str = "BluetoothEmulation.removeCharacteristic";
952    type Response = crate::EmptyReturns;
953}
954
955/// Adds a descriptor with |descriptorUuid| to the characteristic respresented
956/// by |characteristicId|.
957
958#[derive(Debug, Clone, Serialize, Deserialize, Default)]
959#[serde(rename_all = "camelCase")]
960pub struct AddDescriptorParams<'a> {
961    #[serde(rename = "characteristicId")]
962    characteristic_id: Cow<'a, str>,
963    #[serde(rename = "descriptorUuid")]
964    descriptor_uuid: Cow<'a, str>,
965}
966
967impl<'a> AddDescriptorParams<'a> {
968    /// Creates a builder for this type with the required parameters:
969    /// * `characteristic_id`: 
970    /// * `descriptor_uuid`: 
971    pub fn builder(characteristic_id: impl Into<Cow<'a, str>>, descriptor_uuid: impl Into<Cow<'a, str>>) -> AddDescriptorParamsBuilder<'a> {
972        AddDescriptorParamsBuilder {
973            characteristic_id: characteristic_id.into(),
974            descriptor_uuid: descriptor_uuid.into(),
975        }
976    }
977    pub fn characteristic_id(&self) -> &str { self.characteristic_id.as_ref() }
978    pub fn descriptor_uuid(&self) -> &str { self.descriptor_uuid.as_ref() }
979}
980
981
982pub struct AddDescriptorParamsBuilder<'a> {
983    characteristic_id: Cow<'a, str>,
984    descriptor_uuid: Cow<'a, str>,
985}
986
987impl<'a> AddDescriptorParamsBuilder<'a> {
988    pub fn build(self) -> AddDescriptorParams<'a> {
989        AddDescriptorParams {
990            characteristic_id: self.characteristic_id,
991            descriptor_uuid: self.descriptor_uuid,
992        }
993    }
994}
995
996/// Adds a descriptor with |descriptorUuid| to the characteristic respresented
997/// by |characteristicId|.
998
999#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1000#[serde(rename_all = "camelCase")]
1001pub struct AddDescriptorReturns<'a> {
1002    /// An identifier that uniquely represents this descriptor.
1003    #[serde(rename = "descriptorId")]
1004    descriptor_id: Cow<'a, str>,
1005}
1006
1007impl<'a> AddDescriptorReturns<'a> {
1008    /// Creates a builder for this type with the required parameters:
1009    /// * `descriptor_id`: An identifier that uniquely represents this descriptor.
1010    pub fn builder(descriptor_id: impl Into<Cow<'a, str>>) -> AddDescriptorReturnsBuilder<'a> {
1011        AddDescriptorReturnsBuilder {
1012            descriptor_id: descriptor_id.into(),
1013        }
1014    }
1015    /// An identifier that uniquely represents this descriptor.
1016    pub fn descriptor_id(&self) -> &str { self.descriptor_id.as_ref() }
1017}
1018
1019
1020pub struct AddDescriptorReturnsBuilder<'a> {
1021    descriptor_id: Cow<'a, str>,
1022}
1023
1024impl<'a> AddDescriptorReturnsBuilder<'a> {
1025    pub fn build(self) -> AddDescriptorReturns<'a> {
1026        AddDescriptorReturns {
1027            descriptor_id: self.descriptor_id,
1028        }
1029    }
1030}
1031
1032impl<'a> AddDescriptorParams<'a> { pub const METHOD: &'static str = "BluetoothEmulation.addDescriptor"; }
1033
1034impl<'a> crate::CdpCommand<'a> for AddDescriptorParams<'a> {
1035    const METHOD: &'static str = "BluetoothEmulation.addDescriptor";
1036    type Response = AddDescriptorReturns<'a>;
1037}
1038
1039/// Removes the descriptor with |descriptorId| from the simulated central.
1040
1041#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1042#[serde(rename_all = "camelCase")]
1043pub struct RemoveDescriptorParams<'a> {
1044    #[serde(rename = "descriptorId")]
1045    descriptor_id: Cow<'a, str>,
1046}
1047
1048impl<'a> RemoveDescriptorParams<'a> {
1049    /// Creates a builder for this type with the required parameters:
1050    /// * `descriptor_id`: 
1051    pub fn builder(descriptor_id: impl Into<Cow<'a, str>>) -> RemoveDescriptorParamsBuilder<'a> {
1052        RemoveDescriptorParamsBuilder {
1053            descriptor_id: descriptor_id.into(),
1054        }
1055    }
1056    pub fn descriptor_id(&self) -> &str { self.descriptor_id.as_ref() }
1057}
1058
1059
1060pub struct RemoveDescriptorParamsBuilder<'a> {
1061    descriptor_id: Cow<'a, str>,
1062}
1063
1064impl<'a> RemoveDescriptorParamsBuilder<'a> {
1065    pub fn build(self) -> RemoveDescriptorParams<'a> {
1066        RemoveDescriptorParams {
1067            descriptor_id: self.descriptor_id,
1068        }
1069    }
1070}
1071
1072impl<'a> RemoveDescriptorParams<'a> { pub const METHOD: &'static str = "BluetoothEmulation.removeDescriptor"; }
1073
1074impl<'a> crate::CdpCommand<'a> for RemoveDescriptorParams<'a> {
1075    const METHOD: &'static str = "BluetoothEmulation.removeDescriptor";
1076    type Response = crate::EmptyReturns;
1077}
1078
1079/// Simulates a GATT disconnection from the peripheral with |address|.
1080
1081#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1082#[serde(rename_all = "camelCase")]
1083pub struct SimulateGATTDisconnectionParams<'a> {
1084    address: Cow<'a, str>,
1085}
1086
1087impl<'a> SimulateGATTDisconnectionParams<'a> {
1088    /// Creates a builder for this type with the required parameters:
1089    /// * `address`: 
1090    pub fn builder(address: impl Into<Cow<'a, str>>) -> SimulateGATTDisconnectionParamsBuilder<'a> {
1091        SimulateGATTDisconnectionParamsBuilder {
1092            address: address.into(),
1093        }
1094    }
1095    pub fn address(&self) -> &str { self.address.as_ref() }
1096}
1097
1098
1099pub struct SimulateGATTDisconnectionParamsBuilder<'a> {
1100    address: Cow<'a, str>,
1101}
1102
1103impl<'a> SimulateGATTDisconnectionParamsBuilder<'a> {
1104    pub fn build(self) -> SimulateGATTDisconnectionParams<'a> {
1105        SimulateGATTDisconnectionParams {
1106            address: self.address,
1107        }
1108    }
1109}
1110
1111impl<'a> SimulateGATTDisconnectionParams<'a> { pub const METHOD: &'static str = "BluetoothEmulation.simulateGATTDisconnection"; }
1112
1113impl<'a> crate::CdpCommand<'a> for SimulateGATTDisconnectionParams<'a> {
1114    const METHOD: &'static str = "BluetoothEmulation.simulateGATTDisconnection";
1115    type Response = crate::EmptyReturns;
1116}