implements PLN-0058
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
use crate::fs::{FsBackend, FsState};
|
||||
use crate::os::SystemOS;
|
||||
|
||||
pub struct FsFacade<'a> {
|
||||
pub(in crate::os) os: &'a mut SystemOS,
|
||||
}
|
||||
|
||||
impl<'a> FsFacade<'a> {
|
||||
pub fn needs_mount(&self) -> bool {
|
||||
matches!(self.os.fs_state, FsState::Unmounted | FsState::Error(_))
|
||||
}
|
||||
|
||||
pub fn mount(&mut self, backend: Box<dyn FsBackend>) {
|
||||
self.os.vm_runtime.mount_fs(
|
||||
&mut self.os.log_service,
|
||||
&mut self.os.fs,
|
||||
&mut self.os.fs_state,
|
||||
backend,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn unmount(&mut self) {
|
||||
self.os.fs.unmount();
|
||||
self.os.fs_state = FsState::Unmounted;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
use crate::CrashReport;
|
||||
use crate::os::SystemOS;
|
||||
use crate::os::{LifecycleError, LifecycleOperation};
|
||||
use crate::process::{ProcessId, ProcessState};
|
||||
use crate::task::{TaskId, TaskState};
|
||||
|
||||
pub struct LifecycleFacade<'a> {
|
||||
pub(in crate::os) os: &'a mut SystemOS,
|
||||
}
|
||||
|
||||
impl<'a> LifecycleFacade<'a> {
|
||||
pub fn task_state(&self, task_id: TaskId) -> Option<TaskState> {
|
||||
self.os.task_manager.get(task_id).map(|task| task.state)
|
||||
}
|
||||
|
||||
pub fn process_state_for_task(&self, task_id: TaskId) -> Result<ProcessState, LifecycleError> {
|
||||
let process_id = process_id_for_task(self.os, task_id)?;
|
||||
self.os
|
||||
.process_manager
|
||||
.get(process_id)
|
||||
.map(|process| process.state)
|
||||
.ok_or(LifecycleError::ProcessNotFound(process_id))
|
||||
}
|
||||
|
||||
pub fn set_foreground_task(&mut self, task_id: TaskId) -> Result<(), LifecycleError> {
|
||||
let process_id = process_id_for_task(self.os, task_id)?;
|
||||
|
||||
self.os.task_manager.set_foreground(task_id);
|
||||
self.os.process_manager.mark_running(process_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn suspend_task(&mut self, task_id: TaskId) -> Result<(), LifecycleError> {
|
||||
let process_id = process_id_for_task(self.os, task_id)?;
|
||||
|
||||
self.os.task_manager.mark_suspended(task_id);
|
||||
self.os.process_manager.mark_suspended(process_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn resume_task(&mut self, task_id: TaskId) -> Result<(), LifecycleError> {
|
||||
let task =
|
||||
self.os.task_manager.get(task_id).ok_or(LifecycleError::TaskNotFound(task_id))?;
|
||||
|
||||
if task.state != TaskState::Suspended {
|
||||
return Err(LifecycleError::InvalidTransition {
|
||||
task_id,
|
||||
from: task.state,
|
||||
operation: LifecycleOperation::Resume,
|
||||
});
|
||||
}
|
||||
|
||||
let process_id = process_id_for_task(self.os, task_id)?;
|
||||
|
||||
self.os.task_manager.set_foreground(task_id);
|
||||
self.os.process_manager.mark_running(process_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn close_task(&mut self, task_id: TaskId) -> Result<(), LifecycleError> {
|
||||
let process_id = process_id_for_task(self.os, task_id)?;
|
||||
|
||||
self.os.task_manager.close_task(task_id);
|
||||
self.os.process_manager.mark_stopped(process_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn crash_task(
|
||||
&mut self,
|
||||
task_id: TaskId,
|
||||
_report: Option<&CrashReport>,
|
||||
) -> Result<(), LifecycleError> {
|
||||
let process_id = process_id_for_task(self.os, task_id)?;
|
||||
|
||||
self.os.task_manager.mark_crashed(task_id);
|
||||
self.os.process_manager.mark_crashed(process_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn process_id_for_task(os: &SystemOS, task_id: TaskId) -> Result<ProcessId, LifecycleError> {
|
||||
let task = os.task_manager.get(task_id).ok_or(LifecycleError::TaskNotFound(task_id))?;
|
||||
|
||||
if !os.process_manager.contains(task.process_id) {
|
||||
return Err(LifecycleError::ProcessNotFound(task.process_id));
|
||||
}
|
||||
|
||||
Ok(task.process_id)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
mod fs;
|
||||
mod lifecycle;
|
||||
mod sessions;
|
||||
mod vm;
|
||||
mod window;
|
||||
|
||||
pub use fs::FsFacade;
|
||||
pub use lifecycle::LifecycleFacade;
|
||||
pub use sessions::SessionsFacade;
|
||||
pub use vm::VmFacade;
|
||||
pub use window::WindowFacade;
|
||||
@@ -0,0 +1,44 @@
|
||||
use crate::os::SystemOS;
|
||||
use crate::task::TaskId;
|
||||
|
||||
pub struct SessionsFacade<'a> {
|
||||
pub(in crate::os) os: &'a mut SystemOS,
|
||||
}
|
||||
|
||||
impl<'a> SessionsFacade<'a> {
|
||||
pub fn create_vm_game_task(&mut self, app_id: u32, title: impl Into<String>) -> TaskId {
|
||||
let title = title.into();
|
||||
let process_id = self.os.process_manager.spawn_vm_game(app_id, title.clone());
|
||||
let task_id = self.os.task_manager.create_game_task(process_id, app_id, title);
|
||||
self.os
|
||||
.lifecycle()
|
||||
.set_foreground_task(task_id)
|
||||
.expect("newly created game task should have an associated process");
|
||||
|
||||
task_id
|
||||
}
|
||||
|
||||
pub fn create_vm_shell_task(&mut self, app_id: u32, title: impl Into<String>) -> TaskId {
|
||||
let title = title.into();
|
||||
let process_id = self.os.process_manager.spawn_vm_shell(app_id, title.clone());
|
||||
let task_id = self.os.task_manager.create_shell_task(process_id, app_id, title);
|
||||
self.os
|
||||
.lifecycle()
|
||||
.set_foreground_task(task_id)
|
||||
.expect("newly created shell task should have an associated process");
|
||||
|
||||
task_id
|
||||
}
|
||||
|
||||
pub fn create_native_shell_task(&mut self, app_id: u32, title: impl Into<String>) -> TaskId {
|
||||
let title = title.into();
|
||||
let process_id = self.os.process_manager.spawn_native_shell(app_id, title.clone());
|
||||
let task_id = self.os.task_manager.create_shell_task(process_id, app_id, title);
|
||||
self.os
|
||||
.lifecycle()
|
||||
.set_foreground_task(task_id)
|
||||
.expect("newly created native shell task should have an associated process");
|
||||
|
||||
task_id
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
use crate::CrashReport;
|
||||
use crate::os::SystemOS;
|
||||
use prometeu_hal::cartridge::{AppMode, Cartridge};
|
||||
use prometeu_hal::telemetry::{CertificationConfig, TelemetryFrame};
|
||||
use prometeu_hal::{HardwareBridge, InputSignals};
|
||||
use prometeu_vm::VirtualMachine;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
pub struct VmFacade<'a> {
|
||||
pub(in crate::os) os: &'a mut SystemOS,
|
||||
}
|
||||
|
||||
impl<'a> VmFacade<'a> {
|
||||
pub fn initialize(
|
||||
&mut self,
|
||||
vm: &mut VirtualMachine,
|
||||
cartridge: &Cartridge,
|
||||
) -> Result<(), CrashReport> {
|
||||
self.os.clear_cartridge_service_state();
|
||||
self.os.vm_runtime.initialize_vm(&mut self.os.log_service, vm, cartridge)
|
||||
}
|
||||
|
||||
pub fn tick(
|
||||
&mut self,
|
||||
vm: &mut VirtualMachine,
|
||||
signals: &InputSignals,
|
||||
hw: &mut dyn HardwareBridge,
|
||||
) -> Option<CrashReport> {
|
||||
self.os.vm_runtime.tick(
|
||||
&mut self.os.log_service,
|
||||
&mut self.os.fs,
|
||||
&mut self.os.fs_state,
|
||||
&mut self.os.memcard,
|
||||
&mut self.os.open_files,
|
||||
&mut self.os.next_handle,
|
||||
vm,
|
||||
signals,
|
||||
hw,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn reset(&mut self, vm: &mut VirtualMachine) {
|
||||
self.os.vm_runtime.reset(vm);
|
||||
}
|
||||
|
||||
pub fn debug_step_instruction(
|
||||
&mut self,
|
||||
vm: &mut VirtualMachine,
|
||||
hw: &mut dyn HardwareBridge,
|
||||
) -> Option<CrashReport> {
|
||||
self.os.vm_runtime.debug_step_instruction(&mut self.os.log_service, vm, hw)
|
||||
}
|
||||
|
||||
pub fn paused(&self) -> bool {
|
||||
self.os.vm_runtime.paused
|
||||
}
|
||||
|
||||
pub fn set_paused(&mut self, paused: bool) {
|
||||
self.os.vm_runtime.paused = paused;
|
||||
}
|
||||
|
||||
pub fn set_inspection_active(&mut self, active: bool) {
|
||||
self.os.vm_runtime.inspection_active = active;
|
||||
}
|
||||
|
||||
pub fn request_debug_step(&mut self) {
|
||||
self.os.vm_runtime.debug_step_request = true;
|
||||
}
|
||||
|
||||
pub fn debug_step_requested(&self) -> bool {
|
||||
self.os.vm_runtime.debug_step_request
|
||||
}
|
||||
|
||||
pub fn logical_frame_active(&self) -> bool {
|
||||
self.os.vm_runtime.logical_frame_active
|
||||
}
|
||||
|
||||
pub fn tick_index(&self) -> u64 {
|
||||
self.os.vm_runtime.tick_index
|
||||
}
|
||||
|
||||
pub fn logical_frame_index(&self) -> u64 {
|
||||
self.os.vm_runtime.logical_frame_index
|
||||
}
|
||||
|
||||
pub fn last_frame_cpu_time_us(&self) -> u64 {
|
||||
self.os.vm_runtime.last_frame_cpu_time_us
|
||||
}
|
||||
|
||||
pub fn completed_logical_frames(&self) -> u64 {
|
||||
self.os.vm_runtime.atomic_telemetry.completed_logical_frames.load(Ordering::Relaxed).into()
|
||||
}
|
||||
|
||||
pub fn telemetry_snapshot(&self) -> TelemetryFrame {
|
||||
self.os.vm_runtime.atomic_telemetry.snapshot()
|
||||
}
|
||||
|
||||
pub fn cert_config(&self) -> &CertificationConfig {
|
||||
&self.os.vm_runtime.certifier.config
|
||||
}
|
||||
|
||||
pub fn last_crash_report(&self) -> Option<&CrashReport> {
|
||||
self.os.vm_runtime.last_crash_report.as_ref()
|
||||
}
|
||||
|
||||
pub fn current_app_id(&self) -> u32 {
|
||||
self.os.vm_runtime.current_app_id
|
||||
}
|
||||
|
||||
pub fn current_cartridge_title(&self) -> String {
|
||||
self.os.vm_runtime.current_cartridge_title.clone()
|
||||
}
|
||||
|
||||
pub fn current_cartridge_app_version(&self) -> String {
|
||||
self.os.vm_runtime.current_cartridge_app_version.clone()
|
||||
}
|
||||
|
||||
pub fn current_cartridge_app_mode(&self) -> AppMode {
|
||||
self.os.vm_runtime.current_cartridge_app_mode
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
use crate::os::SystemOS;
|
||||
use prometeu_hal::color::Color;
|
||||
use prometeu_hal::window::{Rect, Window, WindowId};
|
||||
|
||||
pub struct WindowFacade<'a> {
|
||||
pub(in crate::os) os: &'a mut SystemOS,
|
||||
}
|
||||
|
||||
impl<'a> WindowFacade<'a> {
|
||||
pub fn add_window(&mut self, title: String, viewport: Rect, color: Color) -> WindowId {
|
||||
self.os.window_manager.add_window(title, viewport, color)
|
||||
}
|
||||
|
||||
pub fn set_focus(&mut self, id: WindowId) {
|
||||
self.os.window_manager.set_focus(id);
|
||||
}
|
||||
|
||||
pub fn focused_window(&self) -> Option<WindowId> {
|
||||
self.os.window_manager.focused
|
||||
}
|
||||
|
||||
pub fn close_window(&mut self, id: WindowId) {
|
||||
self.os.window_manager.remove_window(id);
|
||||
}
|
||||
|
||||
pub fn remove_all_windows(&mut self) {
|
||||
self.os.window_manager.remove_all_windows();
|
||||
}
|
||||
|
||||
pub fn windows(&self) -> &[Window] {
|
||||
&self.os.window_manager.windows
|
||||
}
|
||||
|
||||
pub fn window_count(&self) -> usize {
|
||||
self.os.window_manager.windows.len()
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
mod facades;
|
||||
mod lifecycle;
|
||||
mod system_os;
|
||||
|
||||
pub use facades::{FsFacade, LifecycleFacade, SessionsFacade, VmFacade, WindowFacade};
|
||||
pub use lifecycle::{LifecycleError, LifecycleOperation};
|
||||
pub use system_os::SystemOS;
|
||||
|
||||
@@ -1,31 +1,26 @@
|
||||
use crate::CrashReport;
|
||||
use crate::VirtualMachineRuntime;
|
||||
use crate::fs::{FsBackend, FsState, VirtualFS};
|
||||
use crate::os::{LifecycleError, LifecycleOperation};
|
||||
use crate::fs::{FsState, VirtualFS};
|
||||
use crate::os::{FsFacade, LifecycleFacade, SessionsFacade, VmFacade, WindowFacade};
|
||||
use crate::process::ProcessManager;
|
||||
use crate::services::memcard::MemcardService;
|
||||
use crate::services::window_manager::WindowManager;
|
||||
use crate::task::TaskManager;
|
||||
use crate::task::{TaskId, TaskState};
|
||||
use prometeu_hal::cartridge::Cartridge;
|
||||
use prometeu_hal::log::{LogLevel, LogService, LogSource};
|
||||
use prometeu_hal::log::{LogEvent, LogLevel, LogService, LogSource};
|
||||
use prometeu_hal::telemetry::CertificationConfig;
|
||||
use prometeu_hal::{HardwareBridge, InputSignals};
|
||||
use prometeu_vm::VirtualMachine;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct SystemOS {
|
||||
pub vm_runtime: VirtualMachineRuntime,
|
||||
pub process_manager: ProcessManager,
|
||||
pub task_manager: TaskManager,
|
||||
pub window_manager: WindowManager,
|
||||
pub log_service: LogService,
|
||||
pub fs: VirtualFS,
|
||||
pub fs_state: FsState,
|
||||
pub memcard: MemcardService,
|
||||
pub open_files: HashMap<u32, String>,
|
||||
pub next_handle: u32,
|
||||
pub(super) vm_runtime: VirtualMachineRuntime,
|
||||
pub(super) process_manager: ProcessManager,
|
||||
pub(super) task_manager: TaskManager,
|
||||
pub(super) window_manager: WindowManager,
|
||||
pub(super) log_service: LogService,
|
||||
pub(super) fs: VirtualFS,
|
||||
pub(super) fs_state: FsState,
|
||||
pub(super) memcard: MemcardService,
|
||||
pub(super) open_files: HashMap<u32, String>,
|
||||
pub(super) next_handle: u32,
|
||||
}
|
||||
|
||||
impl SystemOS {
|
||||
@@ -56,156 +51,47 @@ impl SystemOS {
|
||||
self.vm_runtime.log(&mut self.log_service, level, source, tag, msg);
|
||||
}
|
||||
|
||||
pub fn initialize_vm(
|
||||
&mut self,
|
||||
vm: &mut VirtualMachine,
|
||||
cartridge: &Cartridge,
|
||||
) -> Result<(), CrashReport> {
|
||||
self.clear_cartridge_service_state();
|
||||
self.vm_runtime.initialize_vm(&mut self.log_service, vm, cartridge)
|
||||
pub fn recent_logs(&self, n: usize) -> Vec<LogEvent> {
|
||||
self.log_service.get_recent(n)
|
||||
}
|
||||
|
||||
pub fn tick_vm(
|
||||
&mut self,
|
||||
vm: &mut VirtualMachine,
|
||||
signals: &InputSignals,
|
||||
hw: &mut dyn HardwareBridge,
|
||||
) -> Option<CrashReport> {
|
||||
self.vm_runtime.tick(
|
||||
&mut self.log_service,
|
||||
&mut self.fs,
|
||||
&mut self.fs_state,
|
||||
&mut self.memcard,
|
||||
&mut self.open_files,
|
||||
&mut self.next_handle,
|
||||
vm,
|
||||
signals,
|
||||
hw,
|
||||
)
|
||||
pub fn logs_after(&self, seq: u64) -> Vec<LogEvent> {
|
||||
self.log_service.get_after(seq)
|
||||
}
|
||||
|
||||
pub fn mount_fs(&mut self, backend: Box<dyn FsBackend>) {
|
||||
self.vm_runtime.mount_fs(&mut self.log_service, &mut self.fs, &mut self.fs_state, backend);
|
||||
pub fn lifecycle(&mut self) -> LifecycleFacade<'_> {
|
||||
LifecycleFacade { os: self }
|
||||
}
|
||||
|
||||
pub fn unmount_fs(&mut self) {
|
||||
self.fs.unmount();
|
||||
self.fs_state = FsState::Unmounted;
|
||||
pub fn sessions(&mut self) -> SessionsFacade<'_> {
|
||||
SessionsFacade { os: self }
|
||||
}
|
||||
|
||||
fn clear_cartridge_service_state(&mut self) {
|
||||
pub fn vm(&mut self) -> VmFacade<'_> {
|
||||
VmFacade { os: self }
|
||||
}
|
||||
|
||||
pub fn fs(&mut self) -> FsFacade<'_> {
|
||||
FsFacade { os: self }
|
||||
}
|
||||
|
||||
pub fn window(&mut self) -> WindowFacade<'_> {
|
||||
WindowFacade { os: self }
|
||||
}
|
||||
|
||||
pub(super) fn clear_cartridge_service_state(&mut self) {
|
||||
self.open_files.clear();
|
||||
self.next_handle = 1;
|
||||
self.memcard.clear_all_staging();
|
||||
}
|
||||
|
||||
pub fn create_vm_game_task(&mut self, app_id: u32, title: impl Into<String>) -> TaskId {
|
||||
let title = title.into();
|
||||
let process_id = self.process_manager.spawn_vm_game(app_id, title.clone());
|
||||
let task_id = self.task_manager.create_game_task(process_id, app_id, title);
|
||||
self.set_foreground_task(task_id)
|
||||
.expect("newly created game task should have an associated process");
|
||||
|
||||
task_id
|
||||
}
|
||||
|
||||
pub fn create_vm_shell_task(&mut self, app_id: u32, title: impl Into<String>) -> TaskId {
|
||||
let title = title.into();
|
||||
let process_id = self.process_manager.spawn_vm_shell(app_id, title.clone());
|
||||
let task_id = self.task_manager.create_shell_task(process_id, app_id, title);
|
||||
self.set_foreground_task(task_id)
|
||||
.expect("newly created shell task should have an associated process");
|
||||
|
||||
task_id
|
||||
}
|
||||
|
||||
pub fn create_native_shell_task(&mut self, app_id: u32, title: impl Into<String>) -> TaskId {
|
||||
let title = title.into();
|
||||
let process_id = self.process_manager.spawn_native_shell(app_id, title.clone());
|
||||
let task_id = self.task_manager.create_shell_task(process_id, app_id, title);
|
||||
self.set_foreground_task(task_id)
|
||||
.expect("newly created native shell task should have an associated process");
|
||||
|
||||
task_id
|
||||
}
|
||||
|
||||
pub fn set_foreground_task(&mut self, task_id: TaskId) -> Result<(), LifecycleError> {
|
||||
let process_id = self.process_id_for_task(task_id)?;
|
||||
|
||||
self.task_manager.set_foreground(task_id);
|
||||
self.process_manager.mark_running(process_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn suspend_task(&mut self, task_id: TaskId) -> Result<(), LifecycleError> {
|
||||
let process_id = self.process_id_for_task(task_id)?;
|
||||
|
||||
self.task_manager.mark_suspended(task_id);
|
||||
self.process_manager.mark_suspended(process_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn resume_task(&mut self, task_id: TaskId) -> Result<(), LifecycleError> {
|
||||
let task = self.task_manager.get(task_id).ok_or(LifecycleError::TaskNotFound(task_id))?;
|
||||
|
||||
if task.state != TaskState::Suspended {
|
||||
return Err(LifecycleError::InvalidTransition {
|
||||
task_id,
|
||||
from: task.state,
|
||||
operation: LifecycleOperation::Resume,
|
||||
});
|
||||
}
|
||||
|
||||
let process_id = self.process_id_for_task(task_id)?;
|
||||
|
||||
self.task_manager.set_foreground(task_id);
|
||||
self.process_manager.mark_running(process_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn close_task(&mut self, task_id: TaskId) -> Result<(), LifecycleError> {
|
||||
let process_id = self.process_id_for_task(task_id)?;
|
||||
|
||||
self.task_manager.close_task(task_id);
|
||||
self.process_manager.mark_stopped(process_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn crash_task(
|
||||
&mut self,
|
||||
task_id: TaskId,
|
||||
_report: Option<&CrashReport>,
|
||||
) -> Result<(), LifecycleError> {
|
||||
let process_id = self.process_id_for_task(task_id)?;
|
||||
|
||||
self.task_manager.mark_crashed(task_id);
|
||||
self.process_manager.mark_crashed(process_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process_id_for_task(
|
||||
&self,
|
||||
task_id: TaskId,
|
||||
) -> Result<crate::process::ProcessId, LifecycleError> {
|
||||
let task = self.task_manager.get(task_id).ok_or(LifecycleError::TaskNotFound(task_id))?;
|
||||
|
||||
if !self.process_manager.contains(task.process_id) {
|
||||
return Err(LifecycleError::ProcessNotFound(task.process_id));
|
||||
}
|
||||
|
||||
Ok(task.process_id)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::os::{LifecycleError, LifecycleOperation};
|
||||
use crate::process::ProcessState;
|
||||
use crate::task::{TaskId, TaskState};
|
||||
|
||||
fn process_state_for_task(os: &SystemOS, task_id: TaskId) -> ProcessState {
|
||||
let task = os.task_manager.get(task_id).expect("task should exist");
|
||||
@@ -215,10 +101,10 @@ mod tests {
|
||||
#[test]
|
||||
fn set_foreground_task_marks_task_and_process_running() {
|
||||
let mut os = SystemOS::new(None);
|
||||
let task_id = os.create_vm_game_task(42, "Sector Crawl");
|
||||
let task_id = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
||||
|
||||
os.suspend_task(task_id).expect("suspend should succeed");
|
||||
os.set_foreground_task(task_id).expect("foreground should succeed");
|
||||
os.lifecycle().suspend_task(task_id).expect("suspend should succeed");
|
||||
os.lifecycle().set_foreground_task(task_id).expect("foreground should succeed");
|
||||
|
||||
assert_eq!(
|
||||
os.task_manager.get(task_id).expect("task should exist").state,
|
||||
@@ -230,9 +116,9 @@ mod tests {
|
||||
#[test]
|
||||
fn suspend_task_marks_task_and_process_suspended() {
|
||||
let mut os = SystemOS::new(None);
|
||||
let task_id = os.create_vm_game_task(42, "Sector Crawl");
|
||||
let task_id = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
||||
|
||||
os.suspend_task(task_id).expect("suspend should succeed");
|
||||
os.lifecycle().suspend_task(task_id).expect("suspend should succeed");
|
||||
|
||||
assert_eq!(
|
||||
os.task_manager.get(task_id).expect("task should exist").state,
|
||||
@@ -244,10 +130,10 @@ mod tests {
|
||||
#[test]
|
||||
fn resume_task_marks_suspended_task_foreground_and_process_running() {
|
||||
let mut os = SystemOS::new(None);
|
||||
let task_id = os.create_vm_game_task(42, "Sector Crawl");
|
||||
let task_id = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
||||
|
||||
os.suspend_task(task_id).expect("suspend should succeed");
|
||||
os.resume_task(task_id).expect("resume should succeed");
|
||||
os.lifecycle().suspend_task(task_id).expect("suspend should succeed");
|
||||
os.lifecycle().resume_task(task_id).expect("resume should succeed");
|
||||
|
||||
assert_eq!(
|
||||
os.task_manager.get(task_id).expect("task should exist").state,
|
||||
@@ -259,10 +145,10 @@ mod tests {
|
||||
#[test]
|
||||
fn close_task_marks_task_closed_and_process_stopped_without_removing_entities() {
|
||||
let mut os = SystemOS::new(None);
|
||||
let task_id = os.create_vm_game_task(42, "Sector Crawl");
|
||||
let task_id = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
||||
let process_id = os.task_manager.get(task_id).expect("task should exist").process_id;
|
||||
|
||||
os.close_task(task_id).expect("close should succeed");
|
||||
os.lifecycle().close_task(task_id).expect("close should succeed");
|
||||
|
||||
assert_eq!(
|
||||
os.task_manager.get(task_id).expect("task should remain").state,
|
||||
@@ -277,9 +163,9 @@ mod tests {
|
||||
#[test]
|
||||
fn crash_task_marks_task_and_process_crashed() {
|
||||
let mut os = SystemOS::new(None);
|
||||
let task_id = os.create_vm_game_task(42, "Sector Crawl");
|
||||
let task_id = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
||||
|
||||
os.crash_task(task_id, None).expect("crash should succeed");
|
||||
os.lifecycle().crash_task(task_id, None).expect("crash should succeed");
|
||||
|
||||
assert_eq!(
|
||||
os.task_manager.get(task_id).expect("task should exist").state,
|
||||
@@ -292,28 +178,34 @@ mod tests {
|
||||
fn lifecycle_operation_missing_task_returns_typed_error() {
|
||||
let mut os = SystemOS::new(None);
|
||||
|
||||
assert_eq!(os.suspend_task(TaskId(999)), Err(LifecycleError::TaskNotFound(TaskId(999))));
|
||||
assert_eq!(
|
||||
os.lifecycle().suspend_task(TaskId(999)),
|
||||
Err(LifecycleError::TaskNotFound(TaskId(999)))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lifecycle_operation_missing_process_returns_typed_error() {
|
||||
let mut os = SystemOS::new(None);
|
||||
let task_id = os.create_vm_game_task(42, "Sector Crawl");
|
||||
let task_id = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
||||
let process_id = os.task_manager.get(task_id).expect("task should exist").process_id;
|
||||
|
||||
os.process_manager.mark_stopped(process_id);
|
||||
os.process_manager.remove_stopped();
|
||||
|
||||
assert_eq!(os.suspend_task(task_id), Err(LifecycleError::ProcessNotFound(process_id)));
|
||||
assert_eq!(
|
||||
os.lifecycle().suspend_task(task_id),
|
||||
Err(LifecycleError::ProcessNotFound(process_id))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resume_task_from_non_suspended_state_returns_invalid_transition() {
|
||||
let mut os = SystemOS::new(None);
|
||||
let task_id = os.create_vm_game_task(42, "Sector Crawl");
|
||||
let task_id = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
||||
|
||||
assert_eq!(
|
||||
os.resume_task(task_id),
|
||||
os.lifecycle().resume_task(task_id),
|
||||
Err(LifecycleError::InvalidTransition {
|
||||
task_id,
|
||||
from: TaskState::Foreground,
|
||||
|
||||
@@ -61,14 +61,15 @@ impl PrometeuHub {
|
||||
}
|
||||
|
||||
if let Some((title, rect, color)) = next_window {
|
||||
os.window_manager.remove_all_windows();
|
||||
let id = os.window_manager.add_window(title, rect, color);
|
||||
os.window_manager.set_focus(id);
|
||||
let mut window = os.window();
|
||||
window.remove_all_windows();
|
||||
let id = window.add_window(title, rect, color);
|
||||
window.set_focus(id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&mut self, os: &mut SystemOS, hw: &mut dyn HardwareBridge) {
|
||||
for window in &os.window_manager.windows {
|
||||
for window in os.window().windows() {
|
||||
hw.gfx_mut().fill_rect(
|
||||
window.viewport.x,
|
||||
window.viewport.y,
|
||||
@@ -90,17 +91,17 @@ impl PrometeuHub {
|
||||
|
||||
self.gui_update(os, hw);
|
||||
|
||||
if let Some(focused_id) = os.window_manager.focused {
|
||||
if let Some(focused_id) = os.window().focused_window() {
|
||||
if hw.pad().start().down {
|
||||
os.window_manager.remove_window(focused_id);
|
||||
os.window().close_window(focused_id);
|
||||
} else {
|
||||
crash = os.tick_vm(vm, signals, hw);
|
||||
crash = os.vm().tick(vm, signals, hw);
|
||||
}
|
||||
}
|
||||
|
||||
self.render(os, hw);
|
||||
hw.gfx_mut().present();
|
||||
|
||||
SystemProfileUpdate { crash, focused_window_active: os.window_manager.focused.is_some() }
|
||||
SystemProfileUpdate { crash, focused_window_active: os.window().focused_window().is_some() }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user