Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/buttplug_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ doctest = true
doc = true

[dependencies]
buttplug_core = { version = "10.0.0", path = "../buttplug_core" }
buttplug_core = { version = "10.0.0", path = "../buttplug_core", default-features = false }
futures = "0.3.31"
thiserror = "2.0.18"
log = "0.4.29"
getset = "0.1.6"
tokio = { version = "1.49.0", features = ["macros"] }
dashmap = { version = "6.1.0" }
tracing-futures = "0.2.5"
tracing = "0.1.44"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
Expand Down
10 changes: 5 additions & 5 deletions crates/buttplug_client/src/device/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::{
device::ClientDeviceCommandValue,
};

#[derive(Getters, CopyGetters, Clone)]
#[derive(Getters, CopyGetters, Clone, Debug)]
pub struct ClientDeviceFeature {
#[getset(get_copy = "pub")]
device_index: u32,
Expand Down Expand Up @@ -76,7 +76,7 @@ impl ClientDeviceFeature {
ClientDeviceCommandValue::Percent(f) => self.convert_float_value(feature_output, *f)?,
ClientDeviceCommandValue::Steps(i) => *i,
};
if feature_output.step_limit().contains(&value) {
if feature_output.step_limit().contains(value) {
Ok(value)
} else {
Err(ButtplugClientError::ButtplugOutputCommandConversionError(
Expand Down Expand Up @@ -182,7 +182,7 @@ impl ClientDeviceFeature {
pub fn run_input_subscribe(&self, sensor_type: InputType) -> ButtplugClientResultFuture {
if let Some(sensor_map) = self.feature.input()
&& let Some(sensor) = sensor_map.get(sensor_type)
&& sensor.command().contains(&InputCommandType::Subscribe)
&& sensor.command().contains(InputCommandType::Subscribe)
{
let msg = InputCmdV4::new(
self.device_index,
Expand All @@ -202,7 +202,7 @@ impl ClientDeviceFeature {
pub fn run_input_unsubscribe(&self, sensor_type: InputType) -> ButtplugClientResultFuture {
if let Some(sensor_map) = self.feature.input()
&& let Some(sensor) = sensor_map.get(sensor_type)
&& sensor.command().contains(&InputCommandType::Subscribe)
&& sensor.command().contains(InputCommandType::Subscribe)
{
let msg = InputCmdV4::new(
self.device_index,
Expand All @@ -222,7 +222,7 @@ impl ClientDeviceFeature {
pub fn run_input_read(&self, sensor_type: InputType) -> ButtplugClientResultFuture<InputTypeReading> {
if let Some(sensor_map) = self.feature.input()
&& let Some(sensor) = sensor_map.get(sensor_type)
&& sensor.command().contains(&InputCommandType::Read)
&& sensor.command().contains(InputCommandType::Read)
{
let msg = InputCmdV4::new(
self.device_index,
Expand Down
31 changes: 19 additions & 12 deletions crates/buttplug_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ use buttplug_core::{
connector::{ButtplugConnector, ButtplugConnectorError},
errors::{ButtplugError, ButtplugHandshakeError},
message::{
BUTTPLUG_CURRENT_API_MAJOR_VERSION, BUTTPLUG_CURRENT_API_MINOR_VERSION, ButtplugClientMessageV4, ButtplugServerMessageV4, InputType, PingV0, RequestDeviceListV0, RequestServerInfoV4, StartScanningV0, StopCmdV4, StopScanningV0
BUTTPLUG_CURRENT_API_MAJOR_VERSION,
BUTTPLUG_CURRENT_API_MINOR_VERSION,
ButtplugClientMessageV4,
ButtplugServerMessageV4,
InputType,
PingV0,
RequestDeviceListV0,
RequestServerInfoV4,
StartScanningV0,
StopCmdV4,
StopScanningV0,
},
util::{async_manager, stream::convert_broadcast_receiver_to_stream},
};
Expand All @@ -43,7 +53,7 @@ use std::{
use strum_macros::Display;
use thiserror::Error;
use tokio::sync::{Mutex, broadcast, mpsc};
use tracing_futures::Instrument;
use tracing::info_span;

/// Result type used for public APIs.
///
Expand Down Expand Up @@ -103,7 +113,7 @@ pub enum ButtplugClientError {
/// Error converting output command: {}
ButtplugOutputCommandConversionError(String),
/// Multiple inputs available for {}, must use specific feature
ButtplugMultipleInputAvailableError(InputType)
ButtplugMultipleInputAvailableError(InputType),
}

/// Enum representing different events that can be emitted by a client.
Expand Down Expand Up @@ -286,14 +296,11 @@ impl ButtplugClient {

// Take the request receiver - if None, a previous connection consumed it and we can't reconnect
// without creating a new client (the sender is tied to this receiver)
let request_receiver = self
.request_receiver
.lock()
.await
.take()
.ok_or(ButtplugConnectorError::ConnectorGenericError(
let request_receiver = self.request_receiver.lock().await.take().ok_or(
ButtplugConnectorError::ConnectorGenericError(
"Cannot reconnect - request channel already consumed. Create a new client.".to_string(),
))?;
),
)?;

info!("Connecting to server.");
let (connector_sender, connector_receiver) = mpsc::channel(256);
Expand All @@ -316,8 +323,8 @@ impl ButtplugClient {
async_manager::spawn(
async move {
client_event_loop.run().await;
}
.instrument(tracing::info_span!("Client Loop Span")),
},
info_span!("ClientLoop").or_current(),
);
self.run_handshake().await
}
Expand Down
17 changes: 8 additions & 9 deletions crates/buttplug_client_in_process/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,22 @@ websocket-manager=["buttplug_server_hwmgr_websocket"]
xinput-manager=["buttplug_server_hwmgr_xinput"]

[dependencies]
buttplug_core = { version = "10.0.0", path = "../buttplug_core" }
buttplug_core = { version = "10.0.0", path = "../buttplug_core", default-features = false }
buttplug_client = { version = "10.0.0", path = "../buttplug_client" }
buttplug_server = { version = "10.0.0", path = "../buttplug_server" }
buttplug_server_device_config = { version = "10.0.0", path = "../buttplug_server_device_config" }
buttplug_server_hwmgr_btleplug = { version = "10.0.0", path = "../buttplug_server_hwmgr_btleplug", optional = true}
buttplug_server_hwmgr_hid = { version = "10.0.0", path = "../buttplug_server_hwmgr_hid", optional = true}
buttplug_server_hwmgr_lovense_connect = { version = "10.0.0", path = "../buttplug_server_hwmgr_lovense_connect", optional = true}
buttplug_server_hwmgr_lovense_dongle = { version = "10.0.0", path = "../buttplug_server_hwmgr_lovense_dongle", optional = true}
buttplug_server_hwmgr_serial = { version = "10.0.0", path = "../buttplug_server_hwmgr_serial", optional = true}
buttplug_server_hwmgr_websocket = { version = "10.0.0", path = "../buttplug_server_hwmgr_websocket", optional = true}
buttplug_server_hwmgr_xinput = { version = "10.0.0", path = "../buttplug_server_hwmgr_xinput", optional = true}
buttplug_server_hwmgr_btleplug = { version = "10.0.0", path = "../buttplug_server_hwmgr_btleplug", optional = true }
buttplug_server_hwmgr_hid = { version = "10.0.0", path = "../buttplug_server_hwmgr_hid", optional = true }
buttplug_server_hwmgr_lovense_connect = { version = "10.0.0", path = "../buttplug_server_hwmgr_lovense_connect", optional = true }
buttplug_server_hwmgr_lovense_dongle = { version = "10.0.0", path = "../buttplug_server_hwmgr_lovense_dongle", optional = true }
buttplug_server_hwmgr_serial = { version = "10.0.0", path = "../buttplug_server_hwmgr_serial", optional = true }
buttplug_server_hwmgr_websocket = { version = "10.0.0", path = "../buttplug_server_hwmgr_websocket", optional = true }
buttplug_server_hwmgr_xinput = { version = "10.0.0", path = "../buttplug_server_hwmgr_xinput", optional = true }
futures = "0.3.31"
futures-util = "0.3.31"
thiserror = "2.0.18"
log = "0.4.29"
getset = "0.1.6"
tokio = { version = "1.49.0", features = ["macros"] }
dashmap = { version = "6.1.0" }
tracing-futures = "0.2.5"
tracing = "0.1.44"
33 changes: 18 additions & 15 deletions crates/buttplug_client_in_process/src/in_process_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::sync::{
atomic::{AtomicBool, Ordering},
};
use tokio::sync::mpsc::{Sender, channel};
use tracing_futures::Instrument;
use tracing::info_span;

#[derive(Default)]
pub struct ButtplugInProcessClientConnectorBuilder {
Expand Down Expand Up @@ -116,21 +116,24 @@ impl ButtplugConnector<ButtplugClientMessageV4, ButtplugServerMessageV4>
self.server_outbound_sender = message_sender;
let server_recv = self.server.server_version_event_stream();
async move {
async_manager::spawn(async move {
info!("Starting In Process Client Connector Event Sender Loop");
pin_mut!(server_recv);
while let Some(event) = server_recv.next().await {
// If we get an error back, it means the client dropped our event
// handler, so just stop trying. Otherwise, since this is an
// in-process conversion, we can unwrap because we know our
// try_into() will always succeed (which may not be the case with
// remote connections that have different spec versions).
if send.send(event).await.is_err() {
break;
async_manager::spawn(
async move {
info!("Starting In Process Client Connector Event Sender Loop");
pin_mut!(server_recv);
while let Some(event) = server_recv.next().await {
// If we get an error back, it means the client dropped our event
// handler, so just stop trying. Otherwise, since this is an
// in-process conversion, we can unwrap because we know our
// try_into() will always succeed (which may not be the case with
// remote connections that have different spec versions).
if send.send(event).await.is_err() {
break;
}
}
}
info!("Stopping In Process Client Connector Event Sender Loop, due to channel receiver being dropped.");
}.instrument(tracing::info_span!("InProcessClientConnectorEventSenderLoop")));
info!("Stopping In Process Client Connector Event Sender Loop, due to channel receiver being dropped.");
},
info_span!("InProcessClientConnectorEventSenderLoop").or_current()
);
connected.store(true, Ordering::Relaxed);
Ok(())
}.boxed()
Expand Down
7 changes: 5 additions & 2 deletions crates/buttplug_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ doc = true

[features]
default=["tokio-runtime"]
tokio-runtime=["tokio/rt"]
tokio-runtime=["tokio/rt", "tokio/time"]
wasm=[]

# Only build docs on one platform (linux)
Expand All @@ -46,9 +46,12 @@ log = "0.4.29"
getset = "0.1.6"
jsonschema = { version = "0.38.1", default-features = false }
cfg-if = "1.0.4"
tokio = { version = "1.49.0", features = ["sync", "time", "macros"] }
tokio = { version = "1.49.0", features = ["sync", "macros"] }
async-stream = "0.3.6"
strum_macros = "0.27.2"
strum = "0.27.2"
derive_builder = "0.20.2"
enum_dispatch = "0.3"
async-trait = "0.1.89"
tracing = "0.1.44"
enumflags2 = "0.7.12"
34 changes: 19 additions & 15 deletions crates/buttplug_core/src/connector/remote_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use futures::{FutureExt, future::BoxFuture, select};
use log::*;
use std::marker::PhantomData;
use tokio::sync::mpsc::{Receiver, Sender, channel};
use tracing::info_span;

enum ButtplugRemoteConnectorMessage<T>
where
Expand Down Expand Up @@ -234,21 +235,24 @@ where
// If we connect successfully, we get back the channel from the transport
// to send outgoing messages and receieve incoming events, all serialized.
Ok(()) => {
async_manager::spawn(async move {
remote_connector_event_loop::<
TransportType,
SerializerType,
OutboundMessageType,
InboundMessageType,
>(
connector_outgoing_receiver,
connector_incoming_sender,
transport,
transport_outgoing_sender,
transport_incoming_receiver,
)
.await
});
async_manager::spawn(
async move {
remote_connector_event_loop::<
TransportType,
SerializerType,
OutboundMessageType,
InboundMessageType,
>(
connector_outgoing_receiver,
connector_incoming_sender,
transport,
transport_outgoing_sender,
transport_incoming_receiver,
)
.await
},
info_span!("ButtplugRemoteConnectorEventLoop").or_current(),
);
Ok(())
}
Err(e) => Err(e),
Expand Down
2 changes: 1 addition & 1 deletion crates/buttplug_core/src/connector/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::connector::{
ButtplugConnectorResultFuture,
ButtplugSerializedMessage,
};
use displaydoc::Display;
use strum_macros::Display;
use futures::future::BoxFuture;
use thiserror::Error;
use tokio::sync::mpsc::{Receiver, Sender};
Expand Down
3 changes: 2 additions & 1 deletion crates/buttplug_core/src/connector/transport/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use futures::{
FutureExt,
future::{self, BoxFuture},
};
use tracing::info_span;

use std::sync::Arc;
use tokio::{
Expand Down Expand Up @@ -88,7 +89,7 @@ impl ButtplugConnectorTransport for ButtplugStreamTransport {
}
}
}
});
}, info_span!("ButtplugStreamTransportEventLoop").or_current());
Ok(())
}.boxed()
}
Expand Down
5 changes: 3 additions & 2 deletions crates/buttplug_core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use super::message::{
OutputType,
serializer::ButtplugSerializerError,
};
use displaydoc::Display;
use futures::future::BoxFuture;
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -51,7 +52,7 @@ impl_error_to_future!(
/// a remote network connection cannot be established), see
/// [crate::connector::ButtplugConnectorError].

#[derive(Debug, Error, Display, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Display, Error, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ButtplugHandshakeError {
/// Expected either a ServerInfo or Error message, received {0}
UnexpectedHandshakeMessageReceived(String),
Expand Down Expand Up @@ -130,7 +131,7 @@ pub enum ButtplugDeviceError {
DeviceCommunicationError(String),
/// Device feature only has {0} steps for control, but {1} steps specified.
DeviceStepRangeError(i32, i32),
/// Device got {} output command but has no viable outputs
/// Device got {0} output command but has no viable outputs
DeviceNoOutputError(OutputType),
/// Device got {0} input command but has no viable inputs
DeviceNoInputError(InputType),
Expand Down
3 changes: 0 additions & 3 deletions crates/buttplug_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ pub mod errors;
pub mod message;
pub mod util;

#[macro_use]
extern crate strum_macros;

use errors::ButtplugError;
use futures::future::{self, BoxFuture, FutureExt};

Expand Down
Loading