Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
entry_handler.cpp
Go to the documentation of this file.
1
5// standard includes
6#include <csignal>
7#include <format>
8#include <iostream>
9#include <thread>
10
11// local includes
12#include "config.h"
13#include "confighttp.h"
14#include "entry_handler.h"
15#include "globals.h"
16#include "httpcommon.h"
17#include "logging.h"
18#include "network.h"
19#include "platform/common.h"
20
21using namespace std::literals;
22
23void launch_ui(const std::optional<std::string> &path) {
24 std::string url = std::format("https://localhost:{}", static_cast<int>(net::map_port(confighttp::PORT_HTTPS)));
25 if (path) {
26 url += *path;
27 }
28 platf::open_url(url);
29}
30
31namespace args {
32 int creds(const char *name, int argc, char *argv[]) {
33 if (argc < 2 || argv[0] == "help"sv || argv[1] == "help"sv) {
34 help(name);
35 }
36
37 http::save_user_creds(config::sunshine.credentials_file, argv[0], argv[1]);
38
39 return 0;
40 }
41
42 int help(const char *name) {
44 return 0;
45 }
46
47 int version() {
48 // version was already logged at startup
49 return 0;
50 }
51
52} // namespace args
53
54namespace lifetime {
55 char **argv;
56 std::atomic_int desired_exit_code;
57
58 void exit_sunshine(int exit_code, bool async) {
59 // Store the exit code of the first exit_sunshine() call
60 int zero = 0;
61 desired_exit_code.compare_exchange_strong(zero, exit_code);
62
63 // Raise SIGINT to start termination
64 std::raise(SIGINT);
65
66 // Termination will happen asynchronously, but the caller may
67 // have wanted synchronous behavior.
68 while (!async) {
69 std::this_thread::sleep_for(1s);
70 }
71 }
72
73 void debug_trap() {
74 std::raise(SIGTRAP);
75 // If debug trap still doesn't work, abort
76 abort();
77 }
78
79 char **get_argv() {
80 return argv;
81 }
82} // namespace lifetime
83
85 BOOST_LOG(info) << "Package Publisher: "sv << HERMES_PUBLISHER_NAME;
86 BOOST_LOG(info) << "Publisher Website: "sv << HERMES_PUBLISHER_WEBSITE;
87 BOOST_LOG(info) << "Get support: "sv << HERMES_PUBLISHER_ISSUE_URL;
88}
Declarations for common platform specific utilities.
void open_url(const std::string &url)
Open a url in the default web browser.
Definition misc.cpp:546
Declarations for the configuration of Sunshine.
Declarations for the Web UI Config HTTP server.
void launch_ui(const std::optional< std::string > &path)
Launch the Web UI.
void log_publisher_data()
Log the publisher metadata provided from CMake.
Declarations for entry handling functions.
Declarations for globally accessible variables and functions.
Declarations for common HTTP.
Declarations for logging related functions.
Functions for handling command line arguments.
int creds(const char *name, int argc, char *argv[])
Reset the user credentials.
int version()
Print the version to stdout, then exit.
int help(const char *name)
Print help to stdout, then exit.
Functions for handling the lifetime of Sunshine.
void debug_trap()
Breaks into the debugger or terminates Sunshine if no debugger is attached.
void exit_sunshine(int exit_code, bool async)
Terminates Sunshine gracefully with the provided exit code.
char ** get_argv()
Get the argv array passed to main().
void print_help(const char *name)
Print help to stdout.
Definition logging.cpp:211
std::uint16_t map_port(int port)
Map a specified port based on the base port.
Definition network.cpp:350
Declarations for networking related functions.