1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#[cfg(feature = "btleplug-manager")]
pub mod btleplug;
#[cfg(all(feature = "xinput-manager", target_os = "windows"))]
pub mod xinput;
#[cfg(feature = "btleplug-manager")]
use ::btleplug::Error as BtleplugError;
#[cfg(all(feature = "xinput-manager", target_os = "windows"))]
use rusty_xinput::XInputUsageError;
#[cfg(feature = "lovense-dongle-manager")]
pub mod lovense_dongle;
#[cfg(feature = "serial-manager")]
pub mod serialport;
use crate::{core::ButtplugResultFuture, device::ButtplugDeviceImplCreator};
use async_channel::Sender;
use std::sync::{atomic::AtomicBool, Arc};
use thiserror::Error;
pub enum DeviceCommunicationEvent {
DeviceFound(Box<dyn ButtplugDeviceImplCreator>),
DeviceManagerAdded(Arc<AtomicBool>),
ScanningFinished,
}
pub trait DeviceCommunicationManagerCreator: Send {
fn new(sender: Sender<DeviceCommunicationEvent>) -> Self;
}
pub trait DeviceCommunicationManager: Send + Sync {
fn name(&self) -> &'static str;
fn start_scanning(&self) -> ButtplugResultFuture;
fn stop_scanning(&self) -> ButtplugResultFuture;
fn scanning_status(&self) -> Arc<AtomicBool> {
Arc::new(AtomicBool::new(false))
}
}
#[derive(Error, Debug, Clone)]
pub enum ButtplugDeviceSpecificError {
#[cfg(all(feature = "xinput-manager", target_os = "windows"))]
#[error("XInput usage error: {0:?}")]
XInputError(XInputUsageError),
#[cfg(feature = "btleplug-manager")]
#[error("Btleplug error: {0:?}")]
BtleplugError(BtleplugError),
}