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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user