Sunshine latest
Self-hosted game stream host for Moonlight.
process.h
Go to the documentation of this file.
1
5#pragma once
6
7#ifndef __kernel_entry
8 #define __kernel_entry
9#endif
10
11// standard includes
12#include <optional>
13#include <unordered_map>
14
15// lib includes
16#include <boost/process/v1.hpp>
17
18// local includes
19#include "config.h"
20#include "platform/common.h"
21#include "rtsp.h"
22#include "utility.h"
23
24namespace proc {
26
27 typedef config::prep_cmd_t cmd_t;
28
41 struct ctx_t {
42 std::vector<cmd_t> prep_cmds;
43
56 std::vector<std::string> detached;
57
58 std::string name;
59 std::string cmd;
60 std::string working_dir;
61 std::string output;
62 std::string image_path;
63 std::string id;
64 bool elevated;
65 bool auto_detach;
66 bool wait_all;
67 std::chrono::seconds exit_timeout;
68 };
69
70 class proc_t {
71 public:
72 KITTY_DEFAULT_CONSTR_MOVE_THROW(proc_t)
73
74 proc_t(
75 boost::process::v1::environment &&env,
76 std::vector<ctx_t> &&apps
77 ):
78 _app_id(0),
79 _env(std::move(env)),
80 _apps(std::move(apps)) {
81 }
82
83 int execute(int app_id, std::shared_ptr<rtsp_stream::launch_session_t> launch_session);
84
88 int running();
89
90 ~proc_t();
91
92 const std::vector<ctx_t> &get_apps() const;
93 std::vector<ctx_t> &get_apps();
94 std::string get_app_image(int app_id);
95 std::string get_last_run_app_name();
96 void terminate();
97
98 private:
99 int _app_id;
100
101 boost::process::v1::environment _env;
102 std::vector<ctx_t> _apps;
103 ctx_t _app;
104 std::chrono::steady_clock::time_point _app_launch_time;
105
106 // If no command associated with _app_id, yet it's still running
107 bool placebo {};
108
109 boost::process::v1::child _process;
110 boost::process::v1::group _process_group;
111
112 file_t _pipe;
113 std::vector<cmd_t>::const_iterator _app_prep_it;
114 std::vector<cmd_t>::const_iterator _app_prep_begin;
115 };
116
121 std::tuple<std::string, std::string> calculate_app_id(const std::string &app_name, std::string app_image_path, int index);
122
123 std::string validate_app_image_path(std::string app_image_path);
124 void refresh(const std::string &file_name);
125 std::optional<proc::proc_t> parse(const std::string &file_name);
126
131 std::unique_ptr<platf::deinit_t> init();
132
139 void terminate_process_group(boost::process::v1::child &proc, boost::process::v1::group &group, std::chrono::seconds exit_timeout);
140
141 extern proc_t proc;
142} // namespace proc
Definition process.h:70
int running()
Definition process.cpp:263
Definition utility.h:530
Declarations for common platform specific utilities.
Declarations for the configuration of Sunshine.
void 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.
Definition process.cpp:60
std::tuple< std::string, std::string > 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.
Definition process.cpp:535
Declarations for RTSP streaming.
Definition config.h:212
Definition process.h:41
std::vector< std::string > detached
Definition process.h:56
Declarations for utility functions.