|
|
|
@ -6,11 +6,16 @@ use tokio::sync::{
|
|
|
|
|
Mutex,
|
|
|
|
|
|
|
|
|
|
mpsc,
|
|
|
|
|
oneshot,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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)]
|
|
|
|
|
pub struct Handle
|
|
|
|
|
{
|
|
|
|
@ -18,21 +23,38 @@ pub struct Handle
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[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)]
|
|
|
|
|
pub struct Comm{
|
|
|
|
|
inner: Arc<CommInner>,
|
|
|
|
|
pub struct Channel{
|
|
|
|
|
inner: Arc<ChannelInner>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tx: mpsc::Sender<()>,
|
|
|
|
|
tx: mpsc::Sender<Request>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Eq for Comm{}
|
|
|
|
|
impl PartialEq for Comm {
|
|
|
|
|
impl Eq for Channel{}
|
|
|
|
|
impl PartialEq for Channel {
|
|
|
|
|
#[inline] fn eq(&self, other: &Self) -> bool
|
|
|
|
|
{
|
|
|
|
|
Arc::ptr_eq(&self.inner, &other.inner)
|
|
|
|
|