intiface_engine/
options.rs

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