implements PLN-0148
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use crate::os::LifecycleError;
|
||||
use crate::os::SystemOS;
|
||||
use crate::task::TaskId;
|
||||
use crate::vm_session::{VmSession, VmSessionError};
|
||||
|
||||
pub struct SessionsFacade<'a> {
|
||||
pub(in crate::os) os: &'a mut SystemOS,
|
||||
@@ -7,15 +9,27 @@ pub struct SessionsFacade<'a> {
|
||||
|
||||
impl<'a> SessionsFacade<'a> {
|
||||
pub fn create_vm_game_task(&mut self, app_id: u32, title: impl Into<String>) -> TaskId {
|
||||
self.try_create_vm_game_task(app_id, title)
|
||||
.expect("newly created game task should have an associated process")
|
||||
}
|
||||
|
||||
pub fn try_create_vm_game_task(
|
||||
&mut self,
|
||||
app_id: u32,
|
||||
title: impl Into<String>,
|
||||
) -> Result<TaskId, LifecycleError> {
|
||||
if let Some(session) = self.os.vm_sessions.resident_game_for_app(app_id) {
|
||||
return Ok(session.task_id);
|
||||
}
|
||||
|
||||
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_game_foreground_task(task_id)
|
||||
.expect("newly created game task should have an associated process");
|
||||
self.os.lifecycle().set_game_foreground_task(task_id)?;
|
||||
self.create_vm_session_for_task(task_id)
|
||||
.expect("newly created game task should create a VM session");
|
||||
|
||||
task_id
|
||||
Ok(task_id)
|
||||
}
|
||||
|
||||
pub fn create_vm_shell_task(&mut self, app_id: u32, title: impl Into<String>) -> TaskId {
|
||||
@@ -26,6 +40,8 @@ impl<'a> SessionsFacade<'a> {
|
||||
.lifecycle()
|
||||
.set_shell_foreground_task(task_id)
|
||||
.expect("newly created shell task should have an associated process");
|
||||
self.create_vm_session_for_task(task_id)
|
||||
.expect("newly created shell task should create a VM session");
|
||||
|
||||
task_id
|
||||
}
|
||||
@@ -41,4 +57,28 @@ impl<'a> SessionsFacade<'a> {
|
||||
|
||||
task_id
|
||||
}
|
||||
|
||||
pub fn vm_session_for_task(&self, task_id: TaskId) -> Option<&VmSession> {
|
||||
self.os.vm_sessions.for_task(task_id)
|
||||
}
|
||||
|
||||
pub fn resident_game_session_for_app(&self, app_id: u32) -> Option<&VmSession> {
|
||||
self.os.vm_sessions.resident_game_for_app(app_id)
|
||||
}
|
||||
|
||||
pub fn vm_session_count(&self) -> usize {
|
||||
self.os.vm_sessions.len()
|
||||
}
|
||||
|
||||
fn create_vm_session_for_task(&mut self, task_id: TaskId) -> Result<(), VmSessionError> {
|
||||
let task = self.os.task_manager.get(task_id).expect("session task should exist").clone();
|
||||
let process = self
|
||||
.os
|
||||
.process_manager
|
||||
.get(task.process_id)
|
||||
.expect("session process should exist")
|
||||
.clone();
|
||||
|
||||
self.os.vm_sessions.create_for_task(&task, &process, "").map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user