Sunshine v2025.118.151840
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#include <optional>
12#include <unordered_map>
13
14#include <boost/process/v1.hpp>
15
16#include "config.h"
17#include "platform/common.h"
18#include "rtsp.h"
19#include "utility.h"
20
21namespace proc {
23
24 typedef config::prep_cmd_t cmd_t;
37 struct ctx_t {
38 std::vector<cmd_t> prep_cmds;
39
52 std::vector<std::string> detached;
53
54 std::string name;
55 std::string cmd;
56 std::string working_dir;
57 std::string output;
58 std::string image_path;
59 std::string id;
60 bool elevated;
61 bool auto_detach;
62 bool wait_all;
63 std::chrono::seconds exit_timeout;
64 };
65
66 class proc_t {
67 public:
68 KITTY_DEFAULT_CONSTR_MOVE_THROW(proc_t)
69
70 proc_t(
71 boost::process::v1::environment &&env,
72 std::vector<ctx_t> &&apps):
73 _app_id(0),
74 _env(std::move(env)),
75 _apps(std::move(apps)) {}
76
77 int
78 execute(int app_id, std::shared_ptr<rtsp_stream::launch_session_t> launch_session);
79
83 int
84 running();
85
86 ~proc_t();
87
88 const std::vector<ctx_t> &
89 get_apps() const;
90 std::vector<ctx_t> &
91 get_apps();
92 std::string
93 get_app_image(int app_id);
94 std::string
95 get_last_run_app_name();
96 void
97 terminate();
98
99 private:
100 int _app_id;
101
102 boost::process::v1::environment _env;
103 std::vector<ctx_t> _apps;
104 ctx_t _app;
105 std::chrono::steady_clock::time_point _app_launch_time;
106
107 // If no command associated with _app_id, yet it's still running
108 bool placebo {};
109
110 boost::process::v1::child _process;
111 boost::process::v1::group _process_group;
112
113 file_t _pipe;
114 std::vector<cmd_t>::const_iterator _app_prep_it;
115 std::vector<cmd_t>::const_iterator _app_prep_begin;
116 };
117
122 std::tuple<std::string, std::string>
123 calculate_app_id(const std::string &app_name, std::string app_image_path, int index);
124
125 std::string
126 validate_app_image_path(std::string app_image_path);
127 void
128 refresh(const std::string &file_name);
129 std::optional<proc::proc_t>
130 parse(const std::string &file_name);
131
136 std::unique_ptr<platf::deinit_t>
137 init();
138
145 void
146 terminate_process_group(boost::process::v1::child &proc, boost::process::v1::group &group, std::chrono::seconds exit_timeout);
147
148 extern proc_t proc;
149} // namespace proc
Definition process.h:66
int running()
Definition process.cpp:272
Definition utility.h:496
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:61
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:557
Declarations for RTSP streaming.
Definition config.h:209
Definition process.h:37
std::vector< std::string > detached
Definition process.h:52
Declarations for utility functions.