Rename FrontendEvent to FrontendRequest (#111)

* rename frontend event and notify
* simplify event names
This commit is contained in:
Ferdinand Schober
2024-04-25 22:18:43 +02:00
committed by GitHub
parent 9edd2f7f3b
commit 279e582698
7 changed files with 97 additions and 92 deletions

View File

@@ -84,34 +84,39 @@ pub fn wait_for_service() -> Result<std::net::TcpStream> {
}
#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
pub enum FrontendEvent {
pub enum FrontendRequest {
/// add a new client
AddClient(Option<String>, u16, Position),
Create(Option<String>, u16, Position),
/// activate/deactivate client
ActivateClient(ClientHandle, bool),
Activate(ClientHandle, bool),
/// change the listen port (recreate udp listener)
ChangePort(u16),
/// remove a client
DelClient(ClientHandle),
/// request an enumertaion of all clients
Delete(ClientHandle),
/// request an enumeration of all clients
Enumerate(),
/// service shutdown
Shutdown(),
Terminate(),
/// update a client (hostname, port, position)
UpdateClient(ClientHandle, Option<String>, u16, Position),
Update(ClientHandle, Option<String>, u16, Position),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum FrontendNotify {
NotifyClientActivate(ClientHandle, bool),
NotifyClientCreate(Client),
NotifyClientUpdate(Client),
NotifyClientDelete(ClientHandle),
pub enum FrontendEvent {
/// the given client was activated
Activated(ClientHandle, bool),
/// a client was created
Created(Client),
/// a client was updated
Updated(Client),
/// the client was deleted
Deleted(ClientHandle),
/// new port, reason of failure (if failed)
NotifyPortChange(u16, Option<String>),
/// Client State, active
PortChanged(u16, Option<String>),
/// list of all clients, used for initial state synchronization
Enumerate(Vec<(Client, bool)>),
NotifyError(String),
/// an error occured
Error(String),
}
pub struct FrontendListener {
@@ -217,7 +222,7 @@ impl FrontendListener {
Ok(rx)
}
pub(crate) async fn notify_all(&mut self, notify: FrontendNotify) -> Result<()> {
pub(crate) async fn broadcast_event(&mut self, notify: FrontendEvent) -> Result<()> {
// encode event
let json = serde_json::to_string(&notify).unwrap();
let payload = json.as_bytes();
@@ -255,7 +260,7 @@ impl Drop for FrontendListener {
}
#[cfg(unix)]
pub async fn read_event(stream: &mut ReadHalf<UnixStream>) -> Result<FrontendEvent> {
pub async fn wait_for_request(stream: &mut ReadHalf<UnixStream>) -> Result<FrontendRequest> {
let len = stream.read_u64().await?;
assert!(len <= 256);
let mut buf = [0u8; 256];
@@ -264,7 +269,7 @@ pub async fn read_event(stream: &mut ReadHalf<UnixStream>) -> Result<FrontendEve
}
#[cfg(windows)]
pub async fn read_event(stream: &mut ReadHalf<TcpStream>) -> Result<FrontendEvent> {
pub async fn wait_for_request(stream: &mut ReadHalf<TcpStream>) -> Result<FrontendRequest> {
let len = stream.read_u64().await?;
let mut buf = [0u8; 256];
stream.read_exact(&mut buf[..len as usize]).await?;