Buttplug sex toy control library
at dev 8.3 kB view raw
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 use_bluetooth_le: bool, 27 #[getset(get_copy = "pub")] 28 use_serial_port: bool, 29 #[getset(get_copy = "pub")] 30 use_hid: bool, 31 #[getset(get_copy = "pub")] 32 use_lovense_dongle_serial: bool, 33 #[getset(get_copy = "pub")] 34 use_lovense_dongle_hid: bool, 35 #[getset(get_copy = "pub")] 36 use_xinput: bool, 37 #[getset(get_copy = "pub")] 38 use_lovense_connect: bool, 39 #[getset(get_copy = "pub")] 40 use_device_websocket_server: bool, 41 #[getset(get_copy = "pub")] 42 device_websocket_server_port: Option<u16>, 43 #[getset(get_copy = "pub")] 44 crash_main_thread: bool, 45 #[getset(get_copy = "pub")] 46 crash_task_thread: bool, 47 #[getset(get_copy = "pub")] 48 broadcast_server_mdns: bool, 49 #[getset(get = "pub")] 50 mdns_suffix: Option<String>, 51 #[getset(get_copy = "pub")] 52 repeater_mode: bool, 53 #[getset(get_copy = "pub")] 54 repeater_local_port: Option<u16>, 55 #[getset(get = "pub")] 56 repeater_remote_address: Option<String>, 57 #[getset(get_copy = "pub")] 58 rest_api_port: Option<u16>, 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 use_bluetooth_le: bool, 74 pub use_serial_port: bool, 75 pub use_hid: bool, 76 pub use_lovense_dongle_serial: bool, 77 pub use_lovense_dongle_hid: bool, 78 pub use_xinput: bool, 79 pub use_lovense_connect: bool, 80 pub use_device_websocket_server: bool, 81 pub device_websocket_server_port: Option<u16>, 82 pub crash_main_thread: bool, 83 pub crash_task_thread: bool, 84 pub broadcast_server_mdns: bool, 85 pub mdns_suffix: Option<String>, 86 pub repeater_mode: bool, 87 pub repeater_local_port: Option<u16>, 88 pub repeater_remote_address: Option<String>, 89 pub rest_api_port: Option<u16>, 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 use_bluetooth_le: other.use_bluetooth_le, 106 use_serial_port: other.use_serial_port, 107 use_hid: other.use_hid, 108 use_lovense_dongle_serial: other.use_lovense_dongle_serial, 109 use_lovense_dongle_hid: other.use_lovense_dongle_hid, 110 use_xinput: other.use_xinput, 111 use_lovense_connect: other.use_lovense_connect, 112 use_device_websocket_server: other.use_device_websocket_server, 113 device_websocket_server_port: other.device_websocket_server_port, 114 crash_main_thread: other.crash_main_thread, 115 crash_task_thread: other.crash_task_thread, 116 broadcast_server_mdns: other.broadcast_server_mdns, 117 mdns_suffix: other.mdns_suffix, 118 repeater_mode: other.repeater_mode, 119 repeater_local_port: other.repeater_local_port, 120 repeater_remote_address: other.repeater_remote_address, 121 rest_api_port: other.rest_api_port, 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 use_bluetooth_le(&mut self, value: bool) -> &mut Self { 176 self.options.use_bluetooth_le = value; 177 self 178 } 179 180 pub fn use_serial_port(&mut self, value: bool) -> &mut Self { 181 self.options.use_serial_port = value; 182 self 183 } 184 185 pub fn use_hid(&mut self, value: bool) -> &mut Self { 186 self.options.use_hid = value; 187 self 188 } 189 190 pub fn use_lovense_dongle_serial(&mut self, value: bool) -> &mut Self { 191 self.options.use_lovense_dongle_serial = value; 192 self 193 } 194 195 pub fn use_lovense_dongle_hid(&mut self, value: bool) -> &mut Self { 196 self.options.use_lovense_dongle_hid = value; 197 self 198 } 199 200 pub fn use_xinput(&mut self, value: bool) -> &mut Self { 201 self.options.use_xinput = value; 202 self 203 } 204 205 pub fn use_lovense_connect(&mut self, value: bool) -> &mut Self { 206 self.options.use_lovense_connect = value; 207 self 208 } 209 210 pub fn use_device_websocket_server(&mut self, value: bool) -> &mut Self { 211 self.options.use_device_websocket_server = value; 212 self 213 } 214 215 pub fn websocket_port(&mut self, port: u16) -> &mut Self { 216 self.options.websocket_port = Some(port); 217 self 218 } 219 220 pub fn websocket_client_address(&mut self, address: &str) -> &mut Self { 221 self.options.websocket_client_address = Some(address.to_owned()); 222 self 223 } 224 225 pub fn frontend_websocket_port(&mut self, port: u16) -> &mut Self { 226 self.options.frontend_websocket_port = Some(port); 227 self 228 } 229 230 pub fn frontend_in_process_channel(&mut self, value: bool) -> &mut Self { 231 self.options.frontend_in_process_channel = value; 232 self 233 } 234 235 pub fn device_websocket_server_port(&mut self, port: u16) -> &mut Self { 236 self.options.device_websocket_server_port = Some(port); 237 self 238 } 239 240 pub fn max_ping_time(&mut self, value: u32) -> &mut Self { 241 self.options.max_ping_time = value; 242 self 243 } 244 245 pub fn broadcast_server_mdns(&mut self, value: bool) -> &mut Self { 246 self.options.broadcast_server_mdns = value; 247 self 248 } 249 250 pub fn mdns_suffix(&mut self, name: &str) -> &mut Self { 251 self.options.mdns_suffix = Some(name.to_owned()); 252 self 253 } 254 255 pub fn use_repeater_mode(&mut self) -> &mut Self { 256 self.options.repeater_mode = true; 257 self 258 } 259 260 pub fn repeater_local_port(&mut self, port: u16) -> &mut Self { 261 self.options.repeater_local_port = Some(port); 262 self 263 } 264 265 pub fn repeater_remote_address(&mut self, addr: &str) -> &mut Self { 266 self.options.repeater_remote_address = Some(addr.to_owned()); 267 self 268 } 269 270 pub fn rest_api_port(&mut self, port: u16) -> &mut Self { 271 self.options.rest_api_port = Some(port); 272 self 273 } 274 275 pub fn finish(&mut self) -> EngineOptions { 276 self.options.clone() 277 } 278}