|
|
@ -6,11 +6,16 @@ use tokio::sync::{
|
|
|
|
Mutex,
|
|
|
|
Mutex,
|
|
|
|
|
|
|
|
|
|
|
|
mpsc,
|
|
|
|
mpsc,
|
|
|
|
|
|
|
|
oneshot,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
pub mod command;
|
|
|
|
pub mod command;
|
|
|
|
|
|
|
|
use command::{
|
|
|
|
|
|
|
|
CommandKind,
|
|
|
|
|
|
|
|
CommandID,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Handle to a running service
|
|
|
|
/// Handle to a running service. Can be used to join it or create `Channel`s.
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Handle
|
|
|
|
pub struct Handle
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -18,21 +23,38 @@ pub struct Handle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct CommInner
|
|
|
|
struct ChannelInner
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Communicate with a running service
|
|
|
|
|
|
|
|
|
|
|
|
/// The side of a `command::Command` that the running service sees.
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
|
|
|
struct Request
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/// ID that corresponds to the returned `command::Command` from the `send()` function of `Channel`.
|
|
|
|
|
|
|
|
id: CommandID,
|
|
|
|
|
|
|
|
/// The actual command sent by the user.
|
|
|
|
|
|
|
|
kind: CommandKind,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Optional response sender.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Just dropping this is the same as sending `None` as far as the user sees.
|
|
|
|
|
|
|
|
resp: oneshot::Sender<Option<command::Response>>,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Communicates with a running service
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Comm{
|
|
|
|
pub struct Channel{
|
|
|
|
inner: Arc<CommInner>,
|
|
|
|
inner: Arc<ChannelInner>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tx: mpsc::Sender<()>,
|
|
|
|
tx: mpsc::Sender<Request>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Eq for Comm{}
|
|
|
|
impl Eq for Channel{}
|
|
|
|
impl PartialEq for Comm {
|
|
|
|
impl PartialEq for Channel {
|
|
|
|
#[inline] fn eq(&self, other: &Self) -> bool
|
|
|
|
#[inline] fn eq(&self, other: &Self) -> bool
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Arc::ptr_eq(&self.inner, &other.inner)
|
|
|
|
Arc::ptr_eq(&self.inner, &other.inner)
|
|
|
|