Sunshine master
Self-hosted game stream host for Moonlight.
process.h File Reference

Declarations for the startup and shutdown of the apps started by a streaming Session. More...

#include <optional>
#include <unordered_map>
#include <boost/process/v1.hpp>
#include "config.h"
#include "platform/common.h"
#include "rtsp.h"
#include "utility.h"
Include dependency graph for process.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  proc::ctx_t
 
class  proc::proc_t
 Tracks launched child processes and terminates them during shutdown. More...
 

Macros

#define __kernel_entry
 Macro for kernel entry.
 
#define DEFAULT_APP_IMAGE_PATH   SUNSHINE_ASSETS_DIR "/box.png"
 Macro for DEFAULT APP IMAGE PATH.
 

Typedefs

typedef config::prep_cmd_t proc::cmd_t
 Parsed command arguments used when launching a child process.
 
using proc::file_t = util::safe_ptr_v2<FILE, int, fclose>
 Boost.Process pipe stream used for child-process I/O.
 

Functions

std::tuple< std::string, std::string > proc::calculate_app_id (const std::string &app_name, std::string app_image_path, int index)
 Calculate a stable id based on name and image data.
 
bool proc::check_valid_png (const std::filesystem::path &path)
 Validates a path whether it is a valid PNG.
 
std::unique_ptr< platf::deinit_tproc::init ()
 Initialize proc functions.
 
std::optional< proc::proc_tproc::parse (const std::string &file_name)
 Parse serialized text into the corresponding runtime representation.
 
void proc::refresh (const std::string &file_name)
 Refresh cached platform state from the operating system.
 
void proc::terminate_process_group (boost::process::v1::child &proc, boost::process::v1::group &group, std::chrono::seconds exit_timeout)
 Terminates all child processes in a process group.
 
std::string proc::validate_app_image_path (std::string app_image_path)
 Validate app image path.
 

Detailed Description

Declarations for the startup and shutdown of the apps started by a streaming Session.

Function Documentation

◆ calculate_app_id()

std::tuple< std::string, std::string > proc::calculate_app_id ( const std::string & app_name,
std::string app_image_path,
int index )

Calculate a stable id based on name and image data.

Returns
Tuple of id calculated without index (for use if no collision) and one with.
Parameters
app_nameApp name.
app_image_pathApp image path.
indexZero-based index of the item being addressed.

◆ check_valid_png()

bool proc::check_valid_png ( const std::filesystem::path & path)

Validates a path whether it is a valid PNG.

Parameters
pathThe path to the PNG file.
Returns
true if the file has a valid PNG signature, false otherwise.

◆ init()

std::unique_ptr< platf::deinit_t > proc::init ( )

Initialize proc functions.

Returns
Unique pointer to deinit_t to manage cleanup

◆ parse()

std::optional< proc::proc_t > proc::parse ( const std::string & file_name)

Parse serialized text into the corresponding runtime representation.

Parameters
file_nameFile name.
Returns
Parsed value or parse status.

◆ refresh()

void proc::refresh ( const std::string & file_name)

Refresh cached platform state from the operating system.

Parameters
file_nameFile name.

◆ terminate_process_group()

void proc::terminate_process_group ( boost::process::v1::child & proc,
boost::process::v1::group & group,
std::chrono::seconds exit_timeout )

Terminates all child processes in a process group.

Parameters
procThe child process itself.
groupThe group of all children in the process tree.
exit_timeoutThe timeout to wait for the process group to gracefully exit.

◆ validate_app_image_path()

std::string proc::validate_app_image_path ( std::string app_image_path)

Validate app image path.

Parameters
app_image_pathCandidate image path from the application configuration.
Returns
Existing PNG path, or the default application image when validation fails.