Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ Allow overwriting fs layout; rename SERVER_DATA_MANAGER to SESSION_MANAGER #2344

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions alvr/dashboard/src/data_sources.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alvr_common::{debug, error, info, parking_lot::Mutex, warn, RelaxedAtomic};
use alvr_events::{Event, EventType};
use alvr_packets::ServerRequest;
use alvr_server_io::ServerDataManager;
use alvr_server_io::ServerSessionManager;
use eframe::egui;
use std::{
env,
Expand All @@ -16,17 +16,17 @@ use tungstenite::http::Uri;

const REQUEST_TIMEOUT: Duration = Duration::from_millis(200);

enum DataSource {
Local(Box<ServerDataManager>),
enum SessionSource {
Local(Box<ServerSessionManager>),
Remote, // Note: the remote (server) is probably living as a separate process in the same PC
}

pub fn get_local_data_source() -> ServerDataManager {
pub fn get_local_session_source() -> ServerSessionManager {
let session_file_path =
alvr_filesystem::filesystem_layout_from_dashboard_exe(&env::current_exe().unwrap())
.session();

ServerDataManager::new(&session_file_path)
ServerSessionManager::new(Some(session_file_path))
}

fn report_event_local(
Expand All @@ -49,12 +49,12 @@ fn report_event_local(
fn report_session_local(
context: &egui::Context,
sender: &mpsc::Sender<PolledEvent>,
data_manager: &mut ServerDataManager,
session_manager: &mut ServerSessionManager,
) {
report_event_local(
context,
sender,
EventType::Session(Box::new(data_manager.session().clone())),
EventType::Session(Box::new(session_manager.session().clone())),
)
}

Expand Down Expand Up @@ -83,14 +83,14 @@ impl DataSources {
let (requests_sender, requests_receiver) = mpsc::channel();
let server_connected = Arc::new(RelaxedAtomic::new(false));

let server_data_manager = get_local_data_source();
let port = server_data_manager.settings().connection.web_server_port;
let data_source = Arc::new(Mutex::new(DataSource::Local(Box::new(server_data_manager))));
let session_manager = get_local_session_source();
let port = session_manager.settings().connection.web_server_port;
let session_source = Arc::new(Mutex::new(SessionSource::Local(Box::new(session_manager))));

let requests_thread = thread::spawn({
let running = Arc::clone(&running);
let context = context.clone();
let data_source = Arc::clone(&data_source);
let session_source = Arc::clone(&session_source);
let events_sender = events_sender.clone();
move || {
let uri = format!("http://127.0.0.1:{port}/api/dashboard-request");
Expand All @@ -102,31 +102,31 @@ impl DataSources {
while let Ok(request) = requests_receiver.try_recv() {
debug!("Dashboard request: {request:?}");

if let DataSource::Local(data_manager) = &mut *data_source.lock() {
if let SessionSource::Local(session_manager) = &mut *session_source.lock() {
match request {
ServerRequest::Log(_) => (),
ServerRequest::GetSession => {
report_session_local(&context, &events_sender, data_manager);
report_session_local(&context, &events_sender, session_manager);
}
ServerRequest::UpdateSession(session) => {
*data_manager.session_mut() = *session;
*session_manager.session_mut() = *session;

report_session_local(&context, &events_sender, data_manager);
report_session_local(&context, &events_sender, session_manager);
}
ServerRequest::SetValues(descs) => {
if let Err(e) = data_manager.set_values(descs) {
if let Err(e) = session_manager.set_values(descs) {
error!("Failed to set session value: {e}")
}

report_session_local(&context, &events_sender, data_manager);
report_session_local(&context, &events_sender, session_manager);
}
ServerRequest::UpdateClientList { hostname, action } => {
data_manager.update_client_list(hostname, action);
session_manager.update_client_list(hostname, action);

report_session_local(&context, &events_sender, data_manager);
report_session_local(&context, &events_sender, session_manager);
}
ServerRequest::GetAudioDevices => {
if let Ok(list) = data_manager.get_audio_devices_list() {
if let Ok(list) = session_manager.get_audio_devices_list() {
report_event_local(
&context,
&events_sender,
Expand Down Expand Up @@ -261,7 +261,7 @@ impl DataSources {

let ping_thread = thread::spawn({
let running = Arc::clone(&running);
let data_source = Arc::clone(&data_source);
let data_source = Arc::clone(&session_source);
let server_connected = Arc::clone(&server_connected);
move || {
const PING_INTERVAL: Duration = Duration::from_secs(1);
Expand All @@ -277,13 +277,13 @@ impl DataSources {

{
let mut data_source_lock = data_source.lock();
if connected && matches!(*data_source_lock, DataSource::Local(_)) {
if connected && matches!(*data_source_lock, SessionSource::Local(_)) {
info!("Server connected");
*data_source_lock = DataSource::Remote;
} else if !connected && matches!(*data_source_lock, DataSource::Remote) {
*data_source_lock = SessionSource::Remote;
} else if !connected && matches!(*data_source_lock, SessionSource::Remote) {
info!("Server disconnected");
*data_source_lock =
DataSource::Local(Box::new(get_local_data_source()));
SessionSource::Local(Box::new(get_local_session_source()));
}
}

Expand Down
12 changes: 6 additions & 6 deletions alvr/dashboard/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ fn main() {
logging_backend::init_logging(server_events_sender.clone());

{
let mut data_manager = data_sources::get_local_data_source();
let mut session_manager = data_sources::get_local_session_source();

data_manager.clean_client_list();
session_manager.clean_client_list();

#[cfg(target_os = "linux")]
{
Expand All @@ -51,7 +51,7 @@ fn main() {
.any(|adapter| adapter.get_info().vendor == 0x10de);

if has_nvidia {
data_manager
session_manager
.session_mut()
.session_settings
.extra
Expand All @@ -60,14 +60,14 @@ fn main() {
}
}

if data_manager.session().server_version != *ALVR_VERSION {
let mut session_ref = data_manager.session_mut();
if session_manager.session().server_version != *ALVR_VERSION {
let mut session_ref = session_manager.session_mut();
session_ref.server_version = ALVR_VERSION.clone();
session_ref.client_connections.clear();
session_ref.session_settings.extra.open_setup_wizard = true;
}

if data_manager
if session_manager
.settings()
.extra
.steamvr_launcher
Expand Down
2 changes: 1 addition & 1 deletion alvr/dashboard/src/steamvr_launcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Launcher {
#[cfg(target_os = "linux")]
linux_steamvr::linux_hardware_checks();

let mut data_source = data_sources::get_local_data_source();
let mut data_source = data_sources::get_local_session_source();

let launch_action = &data_source
.settings()
Expand Down
2 changes: 1 addition & 1 deletion alvr/filesystem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn dashboard_fname() -> &'static str {
}

// Layout of the ALVR installation. All paths are absolute
#[derive(Clone)]
#[derive(Clone, Default, Debug)]
pub struct Layout {
// directory containing the dashboard executable
pub executables_dir: PathBuf,
Expand Down
38 changes: 33 additions & 5 deletions alvr/server_core/src/c_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(dead_code, unused_variables)]
#![allow(clippy::missing_safety_doc)]

use crate::{logging_backend, ServerCoreContext, ServerCoreEvent, SERVER_DATA_MANAGER};
use crate::{logging_backend, ServerCoreContext, ServerCoreEvent, SESSION_MANAGER};
use alvr_common::{
log,
once_cell::sync::Lazy,
Expand All @@ -13,7 +13,9 @@ use alvr_session::CodecType;
use std::{
collections::{HashMap, VecDeque},
ffi::{c_char, CStr, CString},
path::PathBuf,
ptr,
str::FromStr,
sync::mpsc,
time::{Duration, Instant},
};
Expand Down Expand Up @@ -247,9 +249,35 @@ pub extern "C" fn alvr_get_settings_json(buffer: *mut c_char) -> u64 {
string_to_c_str(buffer, &serde_json::to_string(&crate::settings()).unwrap())
}

/// This must be called before alvr_initialize()
#[no_mangle]
pub extern "C" fn alvr_initialize_logging() {
logging_backend::init_logging();
pub unsafe extern "C" fn alvr_initialize_environment(
config_dir: *const c_char,
log_dir: *const c_char,
) {
let config_dir = PathBuf::from_str(CStr::from_ptr(config_dir).to_str().unwrap()).unwrap();
let log_dir = PathBuf::from_str(CStr::from_ptr(log_dir).to_str().unwrap()).unwrap();

crate::initialize_environment(alvr_filesystem::Layout {
config_dir,
log_dir,
..Default::default()
});
}

/// Either session_log_path or crash_log_path can be null, in which case log is outputted to
/// stdout/stderr on Windows.
#[no_mangle]
pub unsafe extern "C" fn alvr_initialize_logging(
session_log_path: *const c_char,
crash_log_path: *const c_char,
) {
let session_log_path = (!session_log_path.is_null())
.then(|| PathBuf::from_str(CStr::from_ptr(session_log_path).to_str().unwrap()).unwrap());
let crash_log_path = (!crash_log_path.is_null())
.then(|| PathBuf::from_str(CStr::from_ptr(crash_log_path).to_str().unwrap()).unwrap());

logging_backend::init_logging(session_log_path, crash_log_path);
}

#[no_mangle]
Expand All @@ -258,8 +286,8 @@ pub unsafe extern "C" fn alvr_initialize() -> AlvrTargetConfig {
*SERVER_CORE_CONTEXT.write() = Some(context);
*EVENTS_RECEIVER.lock() = Some(receiver);

let data_manager_lock = SERVER_DATA_MANAGER.read();
let restart_settings = &data_manager_lock.session().openvr_config;
let session_manager_lock = SESSION_MANAGER.read();
let restart_settings = &session_manager_lock.session().openvr_config;

AlvrTargetConfig {
game_render_width: restart_settings.target_eye_resolution_width,
Expand Down
Loading
Loading