Skip to main content

intiface_engine/
options.rs

1// Buttplug Rust Source Code File - See https://buttplug.io for more info.
2//
3// Copyright 2016-2026 Nonpolynomial Labs LLC. All rights reserved.
4//
5// Licensed under the BSD 3-Clause license. See LICENSE file in the project root
6// for full license information.
7
8use getset::{CopyGetters, Getters};
9
10#[derive(CopyGetters, Getters, Default, Debug, Clone)]
11pub struct EngineOptions {
12  #[getset(get = "pub")]
13  device_config_json: Option<String>,
14  #[getset(get = "pub")]
15  user_device_config_json: Option<String>,
16  #[getset(get = "pub")]
17  user_device_config_path: Option<String>,
18  #[getset(get = "pub")]
19  server_name: String,
20  #[getset(get_copy = "pub")]
21  websocket_use_all_interfaces: bool,
22  #[getset(get_copy = "pub")]
23  websocket_port: Option<u16>,
24  #[getset(get = "pub")]
25  websocket_client_address: Option<String>,
26  #[getset(get_copy = "pub")]
27  frontend_websocket_port: Option<u16>,
28  #[getset(get_copy = "pub")]
29  frontend_in_process_channel: bool,
30  #[getset(get_copy = "pub")]
31  max_ping_time: u32,
32  #[getset(get_copy = "pub")]
33  use_bluetooth_le: bool,
34  #[getset(get_copy = "pub")]
35  use_serial_port: bool,
36  #[getset(get_copy = "pub")]
37  use_hid: bool,
38  #[getset(get_copy = "pub")]
39  use_lovense_dongle_serial: bool,
40  #[getset(get_copy = "pub")]
41  use_lovense_dongle_hid: bool,
42  #[getset(get_copy = "pub")]
43  use_xinput: bool,
44  #[getset(get_copy = "pub")]
45  use_lovense_connect: bool,
46  #[getset(get_copy = "pub")]
47  use_device_websocket_server: bool,
48  #[getset(get_copy = "pub")]
49  device_websocket_server_port: Option<u16>,
50  #[getset(get_copy = "pub")]
51  crash_main_thread: bool,
52  #[getset(get_copy = "pub")]
53  crash_task_thread: bool,
54  #[getset(get_copy = "pub")]
55  broadcast_server_mdns: bool,
56  #[getset(get = "pub")]
57  mdns_suffix: Option<String>,
58  #[getset(get_copy = "pub")]
59  repeater_mode: bool,
60  #[getset(get_copy = "pub")]
61  repeater_local_port: Option<u16>,
62  #[getset(get = "pub")]
63  repeater_remote_address: Option<String>,
64  #[getset(get_copy = "pub")]
65  rest_api_port: Option<u16>,
66}
67
68#[derive(Default, Debug, Clone)]
69pub struct EngineOptionsExternal {
70  pub device_config_json: Option<String>,
71  pub user_device_config_json: Option<String>,
72  pub user_device_config_path: Option<String>,
73  pub server_name: String,
74  pub websocket_use_all_interfaces: bool,
75  pub websocket_port: Option<u16>,
76  pub websocket_client_address: Option<String>,
77  pub frontend_websocket_port: Option<u16>,
78  pub frontend_in_process_channel: bool,
79  pub max_ping_time: u32,
80  pub use_bluetooth_le: bool,
81  pub use_serial_port: bool,
82  pub use_hid: bool,
83  pub use_lovense_dongle_serial: bool,
84  pub use_lovense_dongle_hid: bool,
85  pub use_xinput: bool,
86  pub use_lovense_connect: bool,
87  pub use_device_websocket_server: bool,
88  pub device_websocket_server_port: Option<u16>,
89  pub crash_main_thread: bool,
90  pub crash_task_thread: bool,
91  pub broadcast_server_mdns: bool,
92  pub mdns_suffix: Option<String>,
93  pub repeater_mode: bool,
94  pub repeater_local_port: Option<u16>,
95  pub repeater_remote_address: Option<String>,
96  pub rest_api_port: Option<u16>,
97}
98
99impl From<EngineOptionsExternal> for EngineOptions {
100  fn from(other: EngineOptionsExternal) -> Self {
101    Self {
102      device_config_json: other.device_config_json,
103      user_device_config_json: other.user_device_config_json,
104      user_device_config_path: other.user_device_config_path,
105      server_name: other.server_name,
106      websocket_use_all_interfaces: other.websocket_use_all_interfaces,
107      websocket_port: other.websocket_port,
108      websocket_client_address: other.websocket_client_address,
109      frontend_websocket_port: other.frontend_websocket_port,
110      frontend_in_process_channel: other.frontend_in_process_channel,
111      max_ping_time: other.max_ping_time,
112      use_bluetooth_le: other.use_bluetooth_le,
113      use_serial_port: other.use_serial_port,
114      use_hid: other.use_hid,
115      use_lovense_dongle_serial: other.use_lovense_dongle_serial,
116      use_lovense_dongle_hid: other.use_lovense_dongle_hid,
117      use_xinput: other.use_xinput,
118      use_lovense_connect: other.use_lovense_connect,
119      use_device_websocket_server: other.use_device_websocket_server,
120      device_websocket_server_port: other.device_websocket_server_port,
121      crash_main_thread: other.crash_main_thread,
122      crash_task_thread: other.crash_task_thread,
123      broadcast_server_mdns: other.broadcast_server_mdns,
124      mdns_suffix: other.mdns_suffix,
125      repeater_mode: other.repeater_mode,
126      repeater_local_port: other.repeater_local_port,
127      repeater_remote_address: other.repeater_remote_address,
128      rest_api_port: other.rest_api_port,
129    }
130  }
131}
132
133#[derive(Default)]
134pub struct EngineOptionsBuilder {
135  options: EngineOptions,
136}
137
138impl EngineOptionsBuilder {
139  pub fn device_config_json(&mut self, value: &str) -> &mut Self {
140    self.options.device_config_json = Some(value.to_owned());
141    self
142  }
143
144  pub fn user_device_config_json(&mut self, value: &str) -> &mut Self {
145    self.options.user_device_config_json = Some(value.to_owned());
146    self
147  }
148
149  pub fn user_device_config_path(&mut self, value: &str) -> &mut Self {
150    self.options.user_device_config_path = Some(value.to_owned());
151    self
152  }
153
154  pub fn server_name(&mut self, value: &str) -> &mut Self {
155    self.options.server_name = value.to_owned();
156    self
157  }
158
159  #[cfg(debug_assertions)]
160  pub fn crash_main_thread(&mut self, value: bool) -> &mut Self {
161    #[cfg(debug_assertions)]
162    {
163      self.options.crash_main_thread = value;
164    }
165    self
166  }
167
168  #[cfg(debug_assertions)]
169  pub fn crash_task_thread(&mut self, value: bool) -> &mut Self {
170    #[cfg(debug_assertions)]
171    {
172      self.options.crash_main_thread = value;
173    }
174    self
175  }
176
177  pub fn websocket_use_all_interfaces(&mut self, value: bool) -> &mut Self {
178    self.options.websocket_use_all_interfaces = value;
179    self
180  }
181
182  pub fn use_bluetooth_le(&mut self, value: bool) -> &mut Self {
183    self.options.use_bluetooth_le = value;
184    self
185  }
186
187  pub fn use_serial_port(&mut self, value: bool) -> &mut Self {
188    self.options.use_serial_port = value;
189    self
190  }
191
192  pub fn use_hid(&mut self, value: bool) -> &mut Self {
193    self.options.use_hid = value;
194    self
195  }
196
197  pub fn use_lovense_dongle_serial(&mut self, value: bool) -> &mut Self {
198    self.options.use_lovense_dongle_serial = value;
199    self
200  }
201
202  pub fn use_lovense_dongle_hid(&mut self, value: bool) -> &mut Self {
203    self.options.use_lovense_dongle_hid = value;
204    self
205  }
206
207  pub fn use_xinput(&mut self, value: bool) -> &mut Self {
208    self.options.use_xinput = value;
209    self
210  }
211
212  pub fn use_lovense_connect(&mut self, value: bool) -> &mut Self {
213    self.options.use_lovense_connect = value;
214    self
215  }
216
217  pub fn use_device_websocket_server(&mut self, value: bool) -> &mut Self {
218    self.options.use_device_websocket_server = value;
219    self
220  }
221
222  pub fn websocket_port(&mut self, port: u16) -> &mut Self {
223    self.options.websocket_port = Some(port);
224    self
225  }
226
227  pub fn websocket_client_address(&mut self, address: &str) -> &mut Self {
228    self.options.websocket_client_address = Some(address.to_owned());
229    self
230  }
231
232  pub fn frontend_websocket_port(&mut self, port: u16) -> &mut Self {
233    self.options.frontend_websocket_port = Some(port);
234    self
235  }
236
237  pub fn frontend_in_process_channel(&mut self, value: bool) -> &mut Self {
238    self.options.frontend_in_process_channel = value;
239    self
240  }
241
242  pub fn device_websocket_server_port(&mut self, port: u16) -> &mut Self {
243    self.options.device_websocket_server_port = Some(port);
244    self
245  }
246
247  pub fn max_ping_time(&mut self, value: u32) -> &mut Self {
248    self.options.max_ping_time = value;
249    self
250  }
251
252  pub fn broadcast_server_mdns(&mut self, value: bool) -> &mut Self {
253    self.options.broadcast_server_mdns = value;
254    self
255  }
256
257  pub fn mdns_suffix(&mut self, name: &str) -> &mut Self {
258    self.options.mdns_suffix = Some(name.to_owned());
259    self
260  }
261
262  pub fn use_repeater_mode(&mut self) -> &mut Self {
263    self.options.repeater_mode = true;
264    self
265  }
266
267  pub fn repeater_local_port(&mut self, port: u16) -> &mut Self {
268    self.options.repeater_local_port = Some(port);
269    self
270  }
271
272  pub fn repeater_remote_address(&mut self, addr: &str) -> &mut Self {
273    self.options.repeater_remote_address = Some(addr.to_owned());
274    self
275  }
276
277  pub fn rest_api_port(&mut self, port: u16) -> &mut Self {
278    self.options.rest_api_port = Some(port);
279    self
280  }
281
282  pub fn finish(&mut self) -> EngineOptions {
283    self.options.clone()
284  }
285}