use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::{Mutex, RwLock};
use synwire_core::agents::sandbox::SandboxConfig;
use crate::process_registry::ProcessRegistry;
use crate::visibility::ProcessVisibilityScope;
use super::expect_engine::{PtyStream, StubProcess};
#[cfg(target_os = "linux")]
use crate::platform::linux::namespace::NamespaceContainer;
pub type ExpectSession = expectrl::Session<StubProcess, PtyStream>;
#[derive(Debug)]
pub struct SandboxContext {
pub config: SandboxConfig,
pub registry: Arc<RwLock<ProcessRegistry>>,
pub scope: ProcessVisibilityScope,
#[cfg(target_os = "linux")]
pub container: NamespaceContainer,
pub(crate) sessions: Mutex<HashMap<String, ExpectSession>>,
#[cfg(target_os = "linux")]
pub(crate) session_children: Mutex<HashMap<String, tokio::process::Child>>,
}
impl SandboxContext {
#[cfg(target_os = "linux")]
pub fn new(
config: SandboxConfig,
registry: Arc<RwLock<ProcessRegistry>>,
scope: ProcessVisibilityScope,
container: NamespaceContainer,
) -> Self {
Self {
config,
registry,
scope,
container,
sessions: Mutex::new(HashMap::new()),
session_children: Mutex::new(HashMap::new()),
}
}
}