Skip to content

Commit

Permalink
chore: Run rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
qdot committed Nov 4, 2023
1 parent 48e50a7 commit cb86ea1
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 29 deletions.
3 changes: 1 addition & 2 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct IntifaceCLIArguments {
#[argh(option)]
#[getset(get = "pub")]
websocket_client_address: Option<String>,

// Options that set up communications with intiface GUI
/// if passed, output json for parent process via websockets
#[argh(option)]
Expand Down Expand Up @@ -146,7 +146,6 @@ pub struct IntifaceCLIArguments {
#[getset(get = "pub")]
mdns_suffix: Option<String>,


#[cfg(debug_assertions)]
/// crash the main thread (that holds the runtime)
#[argh(switch)]
Expand Down
6 changes: 3 additions & 3 deletions src/device_communication_managers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pub fn setup_server_device_comm_managers(
if args.use_bluetooth_le() {
info!("Including Bluetooth LE (btleplug) Device Comm Manager Support");
let mut command_manager_builder = BtlePlugCommunicationManagerBuilder::default();
#[cfg(target_os="ios")]
#[cfg(target_os = "ios")]
command_manager_builder.requires_keepalive(true);
#[cfg(not(target_os="ios"))]
#[cfg(not(target_os = "ios"))]
command_manager_builder.requires_keepalive(false);
server_builder.comm_manager(command_manager_builder);
}
Expand All @@ -30,10 +30,10 @@ pub fn setup_server_device_comm_managers(
#[cfg(not(any(target_os = "android", target_os = "ios")))]
{
use buttplug::server::device::hardware::communication::{
hid::HidCommunicationManagerBuilder,
lovense_dongle::{
LovenseHIDDongleCommunicationManagerBuilder, LovenseSerialDongleCommunicationManagerBuilder,
},
hid::HidCommunicationManagerBuilder,
serialport::SerialPortCommunicationManagerBuilder,
};
if args.use_lovense_dongle_hid() {
Expand Down
21 changes: 12 additions & 9 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@ use crate::{
},
logging::setup_frontend_logging,
options::EngineOptions,
IntifaceError,
ButtplugRemoteServer,
ButtplugServerConnectorError
ButtplugRemoteServer, ButtplugServerConnectorError, IntifaceError,
};
use buttplug::{
core::{
connector::{
ButtplugRemoteServerConnector,
ButtplugWebsocketClientTransport,
ButtplugRemoteServerConnector, ButtplugWebsocketClientTransport,
ButtplugWebsocketServerTransportBuilder,
},
message::serializer::ButtplugServerJSONSerializer,
},
server::{ButtplugServerBuilder},
server::ButtplugServerBuilder,
};
use once_cell::sync::OnceCell;
use std::{str::FromStr, sync::Arc, time::Duration};
Expand Down Expand Up @@ -113,7 +110,7 @@ async fn run_server(
_,
ButtplugServerJSONSerializer,
>::new(
ButtplugWebsocketClientTransport::new_insecure_connector(&addr)
ButtplugWebsocketClientTransport::new_insecure_connector(&addr),
))
.await
} else {
Expand All @@ -136,7 +133,7 @@ impl IntifaceEngine {
&self,
options: &EngineOptions,
external_frontend: Option<Arc<dyn Frontend>>,
skip_logging_setup: bool
skip_logging_setup: bool,
) -> Result<(), IntifaceEngineError> {
// At this point we will have received and validated options.

Expand Down Expand Up @@ -205,7 +202,13 @@ impl IntifaceEngine {
let stop_child_token = self.stop_token.child_token();
let options_clone = options.clone();
tokio::spawn(async move {
frontend_server_event_loop(&options_clone, event_receiver, frontend_clone, stop_child_token).await;
frontend_server_event_loop(
&options_clone,
event_receiver,
frontend_clone,
stop_child_token,
)
.await;
});

loop {
Expand Down
32 changes: 22 additions & 10 deletions src/frontend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
pub mod process_messages;
mod websocket_frontend;
use crate::remote_server::ButtplugRemoteServerEvent;
use crate::{error::IntifaceError, options::EngineOptions};
use async_trait::async_trait;
use crate::remote_server::ButtplugRemoteServerEvent;
use futures::{pin_mut, Stream, StreamExt};
use mdns_sd::{ServiceDaemon, ServiceInfo};
pub use process_messages::{EngineMessage, IntifaceMessage};
use rand::distributions::{Alphanumeric, DistString};
use std::collections::HashMap;
use std::sync::Arc;
use tokio::{
select,
sync::{broadcast, Notify},
};
use tokio_util::sync::CancellationToken;
use websocket_frontend::WebsocketFrontend;
use mdns_sd::{ServiceDaemon, ServiceInfo};
use std::collections::HashMap;
use rand::distributions::{Alphanumeric, DistString};

const VERSION: &str = env!("CARGO_PKG_VERSION");

Expand Down Expand Up @@ -75,25 +75,37 @@ pub async fn frontend_server_event_loop(
let mut mdns = None;

if options.broadcast_server_mdns() {
// Create a daemon
// Create a daemon
let mdns_daemon = ServiceDaemon::new().expect("Failed to create daemon");

// Create a service info.
let service_type = "_intiface_engine._tcp.local.";
let random_suffix = Alphanumeric.sample_string(&mut rand::thread_rng(), 6);
let instance_name = format!("intiface_engine_{}_{}", options.mdns_suffix().as_ref().unwrap_or(&"".to_owned()).to_owned(), random_suffix);
info!("Bringing up mDNS Advertisment using instance name {}", instance_name);
let instance_name = format!(
"intiface_engine_{}_{}",
options
.mdns_suffix()
.as_ref()
.unwrap_or(&"".to_owned())
.to_owned(),
random_suffix
);
info!(
"Bringing up mDNS Advertisment using instance name {}",
instance_name
);
let host_name = format!("{}.local.", instance_name);
let port = options.websocket_port().unwrap_or(12345);
let properties:HashMap<String, String> = HashMap::new();
let properties: HashMap<String, String> = HashMap::new();
let mut my_service = ServiceInfo::new(
service_type,
&instance_name,
&host_name,
"",
port,
properties
).unwrap();
properties,
)
.unwrap();
my_service = my_service.enable_addr_auto();
mdns_daemon.register(my_service).unwrap();
mdns = Some(mdns_daemon);
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/process_messages.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use buttplug::{util::device_configuration::UserConfigDeviceIdentifier};
use buttplug::util::device_configuration::UserConfigDeviceIdentifier;
use serde::{Deserialize, Serialize};

// Everything in this struct is an object, even if it has null contents. This is to make other
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ pub use error::*;
pub use frontend::{EngineMessage, Frontend, IntifaceMessage};
pub use logging::{setup_console_logging, setup_frontend_logging, BroadcastWriter};
pub use options::{EngineOptions, EngineOptionsBuilder, EngineOptionsExternal};
pub use remote_server::{ButtplugRemoteServer, ButtplugServerConnectorError};
pub use remote_server::{ButtplugRemoteServer, ButtplugServerConnectorError};
4 changes: 2 additions & 2 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub struct EngineOptionsExternal {
pub crash_main_thread: bool,
pub crash_task_thread: bool,
pub broadcast_server_mdns: bool,
pub mdns_suffix: Option<String>
pub mdns_suffix: Option<String>,
}

impl From<EngineOptionsExternal> for EngineOptions {
Expand Down Expand Up @@ -115,7 +115,7 @@ impl From<EngineOptionsExternal> for EngineOptions {
crash_main_thread: other.crash_main_thread,
crash_task_thread: other.crash_task_thread,
broadcast_server_mdns: other.broadcast_server_mdns,
mdns_suffix: other.mdns_suffix
mdns_suffix: other.mdns_suffix,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/remote_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn run_device_event_stream(
) {
let server_receiver = server.event_stream();
pin_mut!(server_receiver);
loop {
loop {
match server_receiver.next().await {
None => {
info!("Server disconnected via server disappearance, exiting loop.");
Expand Down

0 comments on commit cb86ea1

Please sign in to comment.