implements PLN-0054
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use super::*;
|
||||
use crate::CrashReport;
|
||||
use crate::fs::FsBackend;
|
||||
use crate::fs::{FsBackend, FsState, VirtualFS};
|
||||
use prometeu_hal::cartridge::Cartridge;
|
||||
use prometeu_hal::log::{LogLevel, LogSource};
|
||||
use std::collections::HashMap;
|
||||
|
||||
impl VirtualMachineRuntime {
|
||||
pub fn new_with_log_counter(
|
||||
@@ -17,11 +18,6 @@ impl VirtualMachineRuntime {
|
||||
logical_frame_active: false,
|
||||
logical_frame_remaining_cycles: 0,
|
||||
last_frame_cpu_time_us: 0,
|
||||
fs: VirtualFS::new(),
|
||||
fs_state: FsState::Unmounted,
|
||||
memcard: MemcardService::new(),
|
||||
open_files: HashMap::new(),
|
||||
next_handle: 1,
|
||||
current_app_id: 0,
|
||||
current_cartridge_title: String::new(),
|
||||
current_cartridge_app_version: String::new(),
|
||||
@@ -53,7 +49,13 @@ impl VirtualMachineRuntime {
|
||||
log_service.log(ts_ms, frame, level, source, tag, msg);
|
||||
}
|
||||
|
||||
pub fn mount_fs(&mut self, log_service: &mut LogService, backend: Box<dyn FsBackend>) {
|
||||
pub fn mount_fs(
|
||||
&mut self,
|
||||
log_service: &mut LogService,
|
||||
fs: &mut VirtualFS,
|
||||
fs_state: &mut FsState,
|
||||
backend: Box<dyn FsBackend>,
|
||||
) {
|
||||
self.log(
|
||||
log_service,
|
||||
LogLevel::Info,
|
||||
@@ -61,9 +63,9 @@ impl VirtualMachineRuntime {
|
||||
0,
|
||||
"Attempting to mount filesystem".to_string(),
|
||||
);
|
||||
match self.fs.mount(backend) {
|
||||
match fs.mount(backend) {
|
||||
Ok(_) => {
|
||||
self.fs_state = FsState::Mounted;
|
||||
*fs_state = FsState::Mounted;
|
||||
self.log(
|
||||
log_service,
|
||||
LogLevel::Info,
|
||||
@@ -75,18 +77,23 @@ impl VirtualMachineRuntime {
|
||||
Err(e) => {
|
||||
let err_msg = format!("Failed to mount filesystem: {:?}", e);
|
||||
self.log(log_service, LogLevel::Error, LogSource::Fs, 0, err_msg);
|
||||
self.fs_state = FsState::Error(e);
|
||||
*fs_state = FsState::Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unmount_fs(&mut self) {
|
||||
self.fs.unmount();
|
||||
self.fs_state = FsState::Unmounted;
|
||||
pub fn unmount_fs(&mut self, fs: &mut VirtualFS, fs_state: &mut FsState) {
|
||||
fs.unmount();
|
||||
*fs_state = FsState::Unmounted;
|
||||
}
|
||||
|
||||
pub(crate) fn update_fs(&mut self, log_service: &mut LogService) {
|
||||
if self.fs_state == FsState::Mounted && !self.fs.is_healthy() {
|
||||
pub(crate) fn update_fs(
|
||||
&mut self,
|
||||
log_service: &mut LogService,
|
||||
fs: &mut VirtualFS,
|
||||
fs_state: &mut FsState,
|
||||
) {
|
||||
if *fs_state == FsState::Mounted && !fs.is_healthy() {
|
||||
self.log(
|
||||
log_service,
|
||||
LogLevel::Error,
|
||||
@@ -94,7 +101,7 @@ impl VirtualMachineRuntime {
|
||||
0,
|
||||
"Filesystem became unhealthy, unmounting".to_string(),
|
||||
);
|
||||
self.unmount_fs();
|
||||
self.unmount_fs(fs, fs_state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,10 +112,6 @@ impl VirtualMachineRuntime {
|
||||
self.last_frame_cpu_time_us = 0;
|
||||
self.atomic_telemetry.reset();
|
||||
|
||||
self.open_files.clear();
|
||||
self.next_handle = 1;
|
||||
self.memcard.clear_all_staging();
|
||||
|
||||
self.current_app_id = 0;
|
||||
self.current_cartridge_title.clear();
|
||||
self.current_cartridge_app_version.clear();
|
||||
|
||||
Reference in New Issue
Block a user