sfo_cmd_server/client/
mod.rs1mod client;
2
3use std::hash::Hash;
4use bucky_raw_codec::{RawDecode, RawEncode, RawFixedBytes};
5use num::{FromPrimitive, ToPrimitive};
6use sfo_pool::WorkerClassification;
7pub use client::*;
8
9mod classified_client;
10pub use classified_client::*;
11
12use crate::{CmdHandler, TunnelId};
13use crate::errors::CmdResult;
14
15#[async_trait::async_trait]
16pub trait CmdClient<LEN: RawEncode + for<'a> RawDecode<'a> + Copy + RawFixedBytes + Sync + Send + 'static + FromPrimitive + ToPrimitive,
17 CMD: RawEncode + for<'a> RawDecode<'a> + Copy + RawFixedBytes + Sync + Send + 'static + Eq + Hash,>: Send + Sync + 'static {
18 fn register_cmd_handler(&self, cmd: CMD, handler: impl CmdHandler<LEN, CMD>);
19 async fn send(&self, cmd: CMD, version: u8, body: &[u8]) -> CmdResult<()>;
20 async fn send2(&self, cmd: CMD, version: u8, body: &[&[u8]]) -> CmdResult<()>;
21 async fn send_by_specify_tunnel(&self, tunnel_id: TunnelId, cmd: CMD, version: u8, body: &[u8]) -> CmdResult<()>;
22 async fn send2_by_specify_tunnel(&self, tunnel_id: TunnelId, cmd: CMD, version: u8, body: &[&[u8]]) -> CmdResult<()>;
23 async fn clear_all_tunnel(&self);
24}
25
26#[async_trait::async_trait]
27pub trait ClassifiedCmdClient<LEN: RawEncode + for<'a> RawDecode<'a> + Copy + RawFixedBytes + Sync + Send + 'static + FromPrimitive + ToPrimitive,
28 CMD: RawEncode + for<'a> RawDecode<'a> + Copy + RawFixedBytes + Sync + Send + 'static + Eq + Hash, C: WorkerClassification>: CmdClient<LEN, CMD> {
29 async fn send_by_classified_tunnel(&self, classification: C, cmd: CMD, version: u8, body: &[u8]) -> CmdResult<()>;
30 async fn send2_by_classified_tunnel(&self, classification: C, cmd: CMD, version: u8, body: &[&[u8]]) -> CmdResult<()>;
31 async fn find_tunnel_id_by_classified(&self, classification: C) -> CmdResult<TunnelId>;
32}