use super::{ChannelMode, SonicChannel, SonicStream};
use crate::commands::*;
use crate::result::Result;
use std::net::ToSocketAddrs;
#[derive(Debug)]
pub struct ControlChannel(SonicStream);
impl SonicChannel for ControlChannel {
type Channel = ControlChannel;
fn stream(&self) -> &SonicStream {
&self.0
}
fn start<A, S>(addr: A, password: S) -> Result<Self::Channel>
where
A: ToSocketAddrs,
S: ToString,
{
SonicStream::connect_with_start(ChannelMode::Control, addr, password).map(Self)
}
}
impl ControlChannel {
init_command!(
use QuitCommand for fn quit();
);
init_command!(
use PingCommand for fn ping();
);
}
impl ControlChannel {
init_command!(
use TriggerCommand for fn trigger(
req: TriggerRequest,
)
);
pub fn consolidate(&self) -> Result<()> {
self.trigger(TriggerRequest::Consolidate)
}
pub fn backup(&self, path: &str) -> Result<()> {
self.trigger(TriggerRequest::Backup(path))
}
pub fn restore(&self, path: &str) -> Result<()> {
self.trigger(TriggerRequest::Restore(path))
}
}