From be060e9a138b1d38cc4476a24cec51fde00c7076 Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Sat, 20 Mar 2021 01:18:09 +0530 Subject: [PATCH] Introduce ServerContext --- src/common/errors.rs | 42 +++++++++++++++++++++++++++++++++++++++--- src/server/mod.rs | 6 +++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/common/errors.rs b/src/common/errors.rs index 4259600fb..e8e02e5ad 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -1,7 +1,9 @@ //! Error context system based on a thread-local representation of the call stack, itself based on //! the instructions that are sent between threads. -use super::{os_input_output::ServerOsApiInstruction, AppInstruction, OPENCALLS}; +use super::{ + os_input_output::ServerOsApiInstruction, AppInstruction, ServerInstruction, OPENCALLS, +}; use crate::pty_bus::PtyInstruction; use crate::screen::ScreenInstruction; use serde::{Deserialize, Serialize}; @@ -144,7 +146,7 @@ pub enum ContextType { Plugin(PluginContext), /// An app-related call. App(AppContext), - IPCServer, // Fix: Create a separate ServerContext when sessions are introduced + IPCServer(ServerContext), StdinHandler, AsyncTask, /// An empty, placeholder call. This should be thought of as representing no call at all. @@ -163,7 +165,7 @@ impl Display for ContextType { ContextType::Os(c) => write!(f, "{}os_thread: {}{:?}", purple, green, c), ContextType::Plugin(c) => write!(f, "{}plugin_thread: {}{:?}", purple, green, c), ContextType::App(c) => write!(f, "{}main_thread: {}{:?}", purple, green, c), - ContextType::IpcServer => write!(f, "{}ipc_server: {}AcceptInput", purple, green), + ContextType::IPCServer(c) => write!(f, "{}ipc_server: {}{:?}", purple, green, c), ContextType::StdinHandler => { write!(f, "{}stdin_handler_thread: {}AcceptInput", purple, green) } @@ -367,3 +369,37 @@ impl From<&AppInstruction> for AppContext { } } } + +/// Stack call representations corresponding to the different types of [`AppInstruction`]s. +#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] +pub enum ServerContext { + OpenFile, + SplitHorizontally, + SplitVertically, + MoveFocus, + NewClient, + ToPty, + ToScreen, + OsApi, + DoneClosingPane, + ClosePluginPane, + Exit, +} + +impl From<&ServerInstruction> for ServerContext { + fn from(server_instruction: &ServerInstruction) -> Self { + match *server_instruction { + ServerInstruction::OpenFile(_) => ServerContext::OpenFile, + ServerInstruction::SplitHorizontally => ServerContext::SplitHorizontally, + ServerInstruction::SplitVertically => ServerContext::SplitVertically, + ServerInstruction::MoveFocus => ServerContext::MoveFocus, + ServerInstruction::NewClient(_) => ServerContext::NewClient, + ServerInstruction::ToPty(_) => ServerContext::ToPty, + ServerInstruction::ToScreen(_) => ServerContext::ToScreen, + ServerInstruction::OsApi(_) => ServerContext::OsApi, + ServerInstruction::DoneClosingPane => ServerContext::DoneClosingPane, + ServerInstruction::ClosePluginPane(_) => ServerContext::ClosePluginPane, + ServerInstruction::Exit => ServerContext::Exit, + } + } +} diff --git a/src/server/mod.rs b/src/server/mod.rs index 9ad2cbcec..b13180619 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -3,8 +3,8 @@ use crate::common::{ ChannelWithContext, ClientInstruction, IpcSenderWithContext, SenderType, SenderWithContext, ServerInstruction, }; -use crate::errors::{ContextType, ErrorContext, OsContext, PtyContext}; -use crate::os_input_output::{get_server_os_input, ServerOsApi, ServerOsApiInstruction}; +use crate::errors::{ContextType, ErrorContext, OsContext, PtyContext, ServerContext}; +use crate::os_input_output::{ServerOsApi, ServerOsApiInstruction}; use crate::panes::PaneId; use crate::pty_bus::{PtyBus, PtyInstruction}; use crate::screen::ScreenInstruction; @@ -161,7 +161,7 @@ pub fn start_server( move || loop { let (mut err_ctx, instruction): (ErrorContext, ServerInstruction) = recv_server_instructions.recv().unwrap(); - err_ctx.add_call(ContextType::IPCServer); + err_ctx.add_call(ContextType::IPCServer(ServerContext::from(&instruction))); send_pty_instructions.update(err_ctx); send_os_instructions.update(err_ctx); if send_client_instructions.len() == 1 {