mod client;
mod spawn;
use std::path::Path;
use anyhow::Result;
use config::Config;
use interprocess::local_socket::tokio::Stream as LocalStream;
use ipc::{BrokerRequest, BrokerResponse};
use tokio_util::codec::{Framed, LengthDelimitedCodec};
pub(in crate::commands) use client::{run_status, send_frame};
pub(crate) async fn call(
cfg: &Config,
device: Option<&str>,
config_path: Option<&Path>,
req: BrokerRequest,
) -> Result<BrokerResponse> {
let addr = device.unwrap_or_else(|| cfg.device.address());
spawn::ensure_running(cfg, device, config_path).await?;
client::send_request(addr, req).await
}
pub(crate) async fn connect(
cfg: &Config,
device: Option<&str>,
config_path: Option<&Path>,
) -> Result<Framed<LocalStream, LengthDelimitedCodec>> {
let addr = device.unwrap_or_else(|| cfg.device.address());
spawn::ensure_running(cfg, device, config_path).await?;
client::connect_raw(addr).await
}