script/dom/bluetooth/
bluetoothcharacteristicproperties.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6
7use crate::dom::bindings::codegen::Bindings::BluetoothCharacteristicPropertiesBinding::BluetoothCharacteristicPropertiesMethods;
8use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
9use crate::dom::bindings::root::DomRoot;
10use crate::dom::globalscope::GlobalScope;
11use crate::script_runtime::CanGc;
12
13// https://webbluetoothcg.github.io/web-bluetooth/#characteristicproperties
14#[dom_struct]
15pub(crate) struct BluetoothCharacteristicProperties {
16    reflector_: Reflector,
17    broadcast: bool,
18    read: bool,
19    write_without_response: bool,
20    write: bool,
21    notify: bool,
22    indicate: bool,
23    authenticated_signed_writes: bool,
24    reliable_write: bool,
25    writable_auxiliaries: bool,
26}
27
28#[allow(non_snake_case)]
29impl BluetoothCharacteristicProperties {
30    #[allow(clippy::too_many_arguments)]
31    pub(crate) fn new_inherited(
32        broadcast: bool,
33        read: bool,
34        write_without_response: bool,
35        write: bool,
36        notify: bool,
37        indicate: bool,
38        authenticated_signed_writes: bool,
39        reliable_write: bool,
40        writable_auxiliaries: bool,
41    ) -> BluetoothCharacteristicProperties {
42        BluetoothCharacteristicProperties {
43            reflector_: Reflector::new(),
44            broadcast,
45            read,
46            write_without_response,
47            write,
48            notify,
49            indicate,
50            authenticated_signed_writes,
51            reliable_write,
52            writable_auxiliaries,
53        }
54    }
55
56    #[allow(clippy::too_many_arguments)]
57    pub(crate) fn new(
58        global: &GlobalScope,
59        broadcast: bool,
60        read: bool,
61        writeWithoutResponse: bool,
62        write: bool,
63        notify: bool,
64        indicate: bool,
65        authenticatedSignedWrites: bool,
66        reliableWrite: bool,
67        writableAuxiliaries: bool,
68        can_gc: CanGc,
69    ) -> DomRoot<BluetoothCharacteristicProperties> {
70        reflect_dom_object(
71            Box::new(BluetoothCharacteristicProperties::new_inherited(
72                broadcast,
73                read,
74                writeWithoutResponse,
75                write,
76                notify,
77                indicate,
78                authenticatedSignedWrites,
79                reliableWrite,
80                writableAuxiliaries,
81            )),
82            global,
83            can_gc,
84        )
85    }
86}
87
88impl BluetoothCharacteristicPropertiesMethods<crate::DomTypeHolder>
89    for BluetoothCharacteristicProperties
90{
91    // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothcharacteristicproperties-broadcast
92    fn Broadcast(&self) -> bool {
93        self.broadcast
94    }
95
96    // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothcharacteristicproperties-read
97    fn Read(&self) -> bool {
98        self.read
99    }
100
101    // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothcharacteristicproperties-writewithoutresponse
102    fn WriteWithoutResponse(&self) -> bool {
103        self.write_without_response
104    }
105
106    // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothcharacteristicproperties-write
107    fn Write(&self) -> bool {
108        self.write
109    }
110
111    // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothcharacteristicproperties-notify
112    fn Notify(&self) -> bool {
113        self.notify
114    }
115
116    // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothcharacteristicproperties-indicate
117    fn Indicate(&self) -> bool {
118        self.indicate
119    }
120
121    // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothcharacteristicproperties-authenticatedsignedwrites
122    fn AuthenticatedSignedWrites(&self) -> bool {
123        self.authenticated_signed_writes
124    }
125
126    // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothcharacteristicproperties-reliablewrite
127    fn ReliableWrite(&self) -> bool {
128        self.reliable_write
129    }
130
131    // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothcharacteristicproperties-writableauxiliaries
132    fn WritableAuxiliaries(&self) -> bool {
133        self.writable_auxiliaries
134    }
135}