implements PLN-0055 systemos lifecycle api
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
use crate::process::ProcessId;
|
||||
use crate::task::{TaskId, TaskState};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum LifecycleOperation {
|
||||
SetForeground,
|
||||
Suspend,
|
||||
Resume,
|
||||
Close,
|
||||
Crash,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum LifecycleError {
|
||||
TaskNotFound(TaskId),
|
||||
ProcessNotFound(ProcessId),
|
||||
InvalidTransition { task_id: TaskId, from: TaskState, operation: LifecycleOperation },
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
mod lifecycle;
|
||||
mod system_os;
|
||||
|
||||
pub use lifecycle::{LifecycleError, LifecycleOperation};
|
||||
pub use system_os::SystemOS;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
use crate::CrashReport;
|
||||
use crate::VirtualMachineRuntime;
|
||||
use crate::fs::{FsBackend, FsState, VirtualFS};
|
||||
use crate::os::{LifecycleError, LifecycleOperation};
|
||||
use crate::process::ProcessManager;
|
||||
use crate::services::memcard::MemcardService;
|
||||
use crate::services::window_manager::WindowManager;
|
||||
use crate::task::TaskId;
|
||||
use crate::task::TaskManager;
|
||||
use crate::task::{TaskId, TaskState};
|
||||
use prometeu_hal::cartridge::Cartridge;
|
||||
use prometeu_hal::log::{LogLevel, LogService, LogSource};
|
||||
use prometeu_hal::telemetry::CertificationConfig;
|
||||
@@ -102,7 +103,8 @@ impl SystemOS {
|
||||
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.task_manager.set_foreground(task_id);
|
||||
self.set_foreground_task(task_id)
|
||||
.expect("newly created game task should have an associated process");
|
||||
|
||||
task_id
|
||||
}
|
||||
@@ -111,7 +113,8 @@ impl SystemOS {
|
||||
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.task_manager.set_foreground(task_id);
|
||||
self.set_foreground_task(task_id)
|
||||
.expect("newly created shell task should have an associated process");
|
||||
|
||||
task_id
|
||||
}
|
||||
@@ -120,8 +123,81 @@ impl SystemOS {
|
||||
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.task_manager.set_foreground(task_id);
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user