From de856d5e43ecadcd876bdf03800ecc5421347872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 15 Oct 2020 20:52:27 +0200 Subject: initial cli --- mumd/src/command.rs | 53 ++++++++++++++++------------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index b4bd1b7..9adf7d8 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -1,54 +1,33 @@ -use crate::state::{Channel, Server, State, StatePhase}; +use crate::state::{State, StatePhase}; +use ipc_channel::ipc::IpcSender; use log::*; -use std::collections::HashMap; +use mumlib::command::{Command, CommandResponse}; use std::sync::{Arc, Mutex}; use tokio::sync::mpsc; -#[derive(Clone, Debug)] -pub enum Command { - ChannelJoin { - channel_id: u32, - }, - ChannelList, - ServerConnect { - host: String, - port: u16, - username: String, - accept_invalid_cert: bool, //TODO ask when connecting - }, - ServerDisconnect, - Status, -} - -#[derive(Debug)] -pub enum CommandResponse { - ChannelList { - channels: HashMap, - }, - Status { - username: Option, - server_state: Server, - }, -} - pub async fn handle( state: Arc>, - mut command_receiver: mpsc::UnboundedReceiver, - command_response_sender: mpsc::UnboundedSender, ()>>, + mut command_receiver: mpsc::UnboundedReceiver<(Command, IpcSender, ()>>)>, ) { - //TODO err if not connected - while let Some(command) = command_receiver.recv().await { - debug!("Parsing command {:?}", command); + debug!("Begin listening for commands"); + loop { + debug!("Enter loop"); + let command = command_receiver.recv().await.unwrap(); + debug!("Received command {:?}", command.0); let mut state = state.lock().unwrap(); - let (wait_for_connected, command_response) = state.handle_command(command).await; + let (wait_for_connected, command_response) = state.handle_command(command.0).await; if wait_for_connected { let mut watcher = state.phase_receiver(); drop(state); while !matches!(watcher.recv().await.unwrap(), StatePhase::Connected) {} } - command_response_sender.send(command_response).unwrap(); + command.1.send(command_response).unwrap(); } + //TODO err if not connected + //while let Some(command) = command_receiver.recv().await { + // debug!("Parsing command {:?}", command); + //} - debug!("Finished handling commands"); + //debug!("Finished handling commands"); } -- cgit v1.2.1