Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogTheFrog committed Feb 18, 2025
1 parent 83378ca commit 65a54ad
Show file tree
Hide file tree
Showing 6 changed files with 469 additions and 323 deletions.
4 changes: 2 additions & 2 deletions src/confighttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ namespace confighttp {
});

file_handler::write_file(config::stream.file_apps.c_str(), file_tree.dump(4));
proc::refresh(config::stream.file_apps);
proc::proc.refresh(config::stream.file_apps);

output_tree["status"] = true;
send_response(response, output_tree);
Expand Down Expand Up @@ -656,7 +656,7 @@ namespace confighttp {
file_tree["apps"] = new_apps;

file_handler::write_file(config::stream.file_apps.c_str(), file_tree.dump(4));
proc::refresh(config::stream.file_apps);
proc::proc.refresh(config::stream.file_apps);

output_tree["status"] = true;
output_tree["result"] = "application " + std::to_string(index) + " deleted";
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ int main(int argc, char *argv[]) {
SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
#endif

proc::refresh(config::stream.file_apps);
proc::proc.refresh(config::stream.file_apps);

// If any of the following fail, we log an error and continue event though sunshine will not function correctly.
// This allows access to the UI to fix configuration problems or view the logs.
Expand Down
22 changes: 8 additions & 14 deletions src/nvhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,10 @@ namespace nvhttp {
}
tree.put("root.ServerCodecModeSupport", codec_mode_flags);

auto current_appid = proc::proc.running();
auto current_appid = proc::proc.get_running_app_id();
tree.put("root.PairStatus", pair_status);
tree.put("root.currentgame", current_appid);
tree.put("root.state", current_appid > 0 ? "SUNSHINE_SERVER_BUSY" : "SUNSHINE_SERVER_FREE");
tree.put("root.currentgame", current_appid.value_or(0));
tree.put("root.state", current_appid ? "SUNSHINE_SERVER_BUSY" : "SUNSHINE_SERVER_FREE");

std::ostringstream data;

Expand Down Expand Up @@ -837,10 +837,7 @@ namespace nvhttp {
return;
}

auto appid = util::from_view(get_arg(args, "appid"));

auto current_appid = proc::proc.running();
if (current_appid > 0) {
if (proc::proc.get_running_app_id()) {
tree.put("root.resume", 0);
tree.put("root.<xmlattr>.status_code", 400);
tree.put("root.<xmlattr>.status_message", "An app is already running on this host");
Expand Down Expand Up @@ -884,6 +881,7 @@ namespace nvhttp {
return;
}

auto appid = util::from_view(get_arg(args, "appid"));
if (appid > 0) {
auto err = proc::proc.execute(appid, launch_session);
if (err) {
Expand Down Expand Up @@ -917,8 +915,7 @@ namespace nvhttp {
response->close_connection_after_response = true;
});

auto current_appid = proc::proc.running();
if (current_appid == 0) {
if (!proc::proc.get_running_app_id()) {
tree.put("root.resume", 0);
tree.put("root.<xmlattr>.status_code", 503);
tree.put("root.<xmlattr>.status_message", "No running app to resume");
Expand Down Expand Up @@ -1000,12 +997,9 @@ namespace nvhttp {
tree.put("root.<xmlattr>.status_code", 200);

rtsp_stream::terminate_sessions();
proc::proc.terminate();

if (proc::proc.running() > 0) {
proc::proc.terminate();
}

// The config needs to be reverted regardless of whether "proc::proc.terminate()" was called or not.
// The config needs to be reverted regardless of whether "proc::proc.terminate()" actually terminated app or not.
display_device::revert_configuration();
}

Expand Down
Loading

0 comments on commit 65a54ad

Please sign in to comment.