Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogTheFrog committed Jan 29, 2025
1 parent 56d0699 commit fc0c05b
Show file tree
Hide file tree
Showing 6 changed files with 465 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 @@ -580,7 +580,7 @@ namespace confighttp {
fileTree.add_child("apps", sorted_apps);

pt::write_json(config::stream.file_apps, fileTree);
proc::refresh(config::stream.file_apps);
proc::proc.refresh(config::stream.file_apps);

outputTree.put("status", true);
send_response(response, outputTree);
Expand Down Expand Up @@ -634,7 +634,7 @@ namespace confighttp {
fileTree.push_back(std::make_pair("apps", newApps));

pt::write_json(config::stream.file_apps, fileTree);
proc::refresh(config::stream.file_apps);
proc::proc.refresh(config::stream.file_apps);

outputTree.put("status", true);
outputTree.put("result", "application "s + 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 fc0c05b

Please sign in to comment.