Skip to content

Commit

Permalink
Reformat plugin-specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
handicraftsman committed Oct 28, 2024
1 parent ffa1fe9 commit fb49d69
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ mod log {
mod dns_cache;
mod dns_parser;
mod error;
mod service_daemon;
mod service_info;
#[cfg(feature = "plugins")]
mod plugin;
mod service_daemon;
mod service_info;

pub use error::{Error, Result};
pub use service_daemon::{
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use crate::ServiceInfo;
use flume::Sender;
use std::collections::HashMap;

/// Commands to be implemented by plugins
#[derive(Debug)]
Expand Down
24 changes: 14 additions & 10 deletions src/service_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,14 @@ impl ServiceDaemon {
/// Please note that enabling the feature enables fetching the plugin-provided services
/// on *every* request, so this is disabled by default due to extra overhead.
#[cfg(feature = "plugins")]
pub fn register_plugin(&self, name: String, pc_recv: Sender<Receiver<PluginCommand>>) -> Result<()> {
pub fn register_plugin(
&self,
name: String,
pc_recv: Sender<Receiver<PluginCommand>>,
) -> Result<()> {
self.send_cmd(Command::RegisterPlugin(name, pc_recv))
}


/// Registers a service provided by this host.
///
/// If `service_info` has no addresses yet and its `addr_auto` is enabled,
Expand All @@ -310,7 +313,6 @@ impl ServiceDaemon {
self.send_cmd(Command::Register(service_info))
}


/// Unregisters a service. This is a graceful shutdown of a service.
///
/// Returns a channel receiver that is used to receive the status code
Expand Down Expand Up @@ -431,13 +433,15 @@ impl ServiceDaemon {
let (p_send, p_recv) = bounded(1);

match sender.send(PluginCommand::Exit(p_send)) {
Ok(()) => {},
Err(e) => error!("failed to send plugin exit command: {}, {}", plugin, e)
Ok(()) => {}
Err(e) => {
error!("failed to send plugin exit command: {}, {}", plugin, e)
}
};

match p_recv.recv() {
Ok(()) => debug!("plugin {} exited successfully", plugin),
Err(e) => error!("plugin {} failed to exit: {}", plugin, e)
Err(e) => error!("plugin {} failed to exit: {}", plugin, e),
}
}

Expand Down Expand Up @@ -2403,12 +2407,12 @@ impl Zeroconf {
warn!("Could not find plugin {}", plugin);

return HashMap::new();
},
}
Some(p_send) => p_send,
};

match p_send.send(PluginCommand::ListServices(r_send)) {
Ok(()) => {},
Ok(()) => {}
Err(e) => warn!("Failed to send ListServices command: {}", e),
}

Expand Down Expand Up @@ -2439,12 +2443,12 @@ impl Zeroconf {

match old_send.send(PluginCommand::Exit(exit_send)) {
Ok(()) => debug!("Requested old plugin exit"),
Err(e) => warn!("Failed to send exit command to a plugin: {}", e)
Err(e) => warn!("Failed to send exit command to a plugin: {}", e),
}

match exit_recv.recv_timeout(Duration::from_secs(1)) {
Ok(()) => debug!("The old plugin exited"),
Err(e) => warn!("Old plugin's exit timed out: {}", e)
Err(e) => warn!("Old plugin's exit timed out: {}", e),
}
}

Expand Down

0 comments on commit fb49d69

Please sign in to comment.