Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
misc.cpp File Reference

Miscellaneous definitions for Linux. More...

#include <fstream>
#include <iostream>
#include <cstdio>
#include <cerrno>
#include <csignal>
#include <cstring>
#include <algorithm>
#include <array>
#include <chrono>
#include <climits>
#include <cstdint>
#include <ctime>
#include <mutex>
#include <thread>
#include <string_view>
#include <utility>
#include <arpa/inet.h>
#include <dlfcn.h>
#include <ifaddrs.h>
#include <netinet/udp.h>
#include <pwd.h>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/asio/ip/address.hpp>
#include <boost/asio/ip/host_name.hpp>
#include <boost/process/v1/group.hpp>
#include <boost/process/v1/child.hpp>
#include <boost/process/v1/env.hpp>
#include <boost/process/v1/environment.hpp>
#include <boost/process/v1/handles.hpp>
#include <boost/process/v1/io.hpp>
#include <boost/process/v1/search_path.hpp>
#include <boost/process/v1/start_dir.hpp>
#include <fcntl.h>
#include <sys/wait.h>
#include <unistd.h>
#include <xf86drm.h>
#include "clipboard_process.h"
#include "graphics.h"
#include "misc.h"
#include "process_group.h"
#include "service_lifecycle.h"
#include "session_attach.h"
#include "src/config.h"
#include "src/entry_handler.h"
#include "src/logging.h"
#include "src/network.h"
#include "src/platform/common.h"
#include "src/video.h"
#include "vaapi.h"
#include "virtual_display.h"
#include <linux/rtnetlink.h>
Include dependency graph for misc.cpp:

Go to the source code of this file.

Classes

class  platf::qos_t
class  platf::linux_high_precision_timer

Macros

#define _GNU_SOURCE   1
#define HERMES_GNUC_EXTENSION

Typedefs

using platf::ifaddr_t = util::safe_ptr<ifaddrs, freeifaddrs>

Enumerations

enum  platf::source::source_e : std::size_t { platf::source::WAYLAND , platf::source::MAX_FLAGS }

Functions

void * dyn::handle (const std::vector< const char * > &libs)
int dyn::load (void *handle, const std::vector< std::tuple< apiproc *, const char * > > &funcs, bool strict)
int platf::open_drm_node (const char *path, int flags)
 Open a DRM device node without becoming its DRM master.
bool platf::touch_binds_to_output ()
 Whether the session binds a touchscreen or a pen to one output.
ifaddr_t platf::get_ifaddrs ()
std::filesystem::path platf::appdata ()
 Performs migration if necessary, then returns the appdata directory.
std::string platf::from_sockaddr (const sockaddr *const)
std::pair< std::uint16_t, std::string > platf::from_sockaddr_ex (const sockaddr *const)
std::string platf::get_mac_address (const std::string_view &address)
 The MAC address of the interface that holds address.
std::string platf::get_local_ip_for_gateway ()
bp::child platf::run_command (bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group)
void platf::open_url (const std::string &url)
 Open a url in the default web browser.
void platf::adjust_thread_priority (thread_priority_e priority)
void platf::streaming_will_start ()
void platf::streaming_will_stop ()
void platf::restart_on_exit ()
void platf::restart ()
int platf::set_env (const std::string &name, const std::string &value)
 Set an environment variable.
int platf::unset_env (const std::string &name)
 Unset an environment variable.
bool platf::request_process_group_exit (std::uintptr_t native_handle)
 Attempt to gracefully terminate a process group.
bool platf::process_group_running (std::uintptr_t native_handle)
 Check if a process group still has running children.
bool platf::request_user_service_stop ()
struct sockaddr_in platf::to_sockaddr (boost::asio::ip::address_v4 address, uint16_t port)
struct sockaddr_in6 platf::to_sockaddr (boost::asio::ip::address_v6 address, uint16_t port)
bool platf::send_batch (batched_send_info_t &send_info)
bool platf::send (send_info_t &send_info)
std::unique_ptr< deinit_t > platf::enable_socket_qos (uintptr_t native_socket, boost::asio::ip::address &address, uint16_t port, qos_data_type_e data_type, bool dscp_tagging)
 Enable QoS on the given socket for traffic to the specified destination.
std::string platf::get_host_name ()
 Returns the current computer name in UTF-8.
std::vector< std::string > platf::wl_display_names ()
std::shared_ptr< display_t > platf::wl_display (mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config)
bool platf::verify_wl ()
std::vector< std::string > platf::display_names (mem_type_e hwdevice_type)
bool platf::needs_encoder_reenumeration ()
 Check if GPUs/drivers have changed since the last call to this function.
std::shared_ptr< display_t > platf::display (mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config)
 Get the display_t instance for the given hwdevice_type. If display_name is empty, use the first monitor that's compatible you can find If you require to use this parameter in a separate thread, make a copy of it.
std::unique_ptr< deinit_t > platf::init ()
std::unique_ptr< high_precision_timer > platf::create_high_precision_timer ()
 Create platform-specific timer capable of high-precision sleep.
std::string platf::get_clipboard ()
bool platf::set_clipboard (const std::string &content)
bool platf::clipboard_available ()
session_environment_t platf::detect_session_environment ()
 Detect the current session/compositor environment.
appliance_readiness_t platf::appliance_readiness ()
 Assess appliance-mode readiness without changing any state.

Variables

window_system_e window_system

Detailed Description

Miscellaneous definitions for Linux.

Definition in file misc.cpp.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE   1

Definition at line 8 of file misc.cpp.

◆ HERMES_GNUC_EXTENSION

#define HERMES_GNUC_EXTENSION

Definition at line 85 of file misc.cpp.

Typedef Documentation

◆ ifaddr_t

using platf::ifaddr_t = util::safe_ptr<ifaddrs, freeifaddrs>

Definition at line 208 of file misc.cpp.

Enumeration Type Documentation

◆ source_e

enum platf::source::source_e : std::size_t
Enumerator
WAYLAND 

Wayland.

MAX_FLAGS 

The maximum number of flags.

Definition at line 1543 of file misc.cpp.

Function Documentation

◆ adjust_thread_priority()

void platf::adjust_thread_priority ( thread_priority_e priority)

Definition at line 562 of file misc.cpp.

◆ appdata()

fs::path platf::appdata ( )

Performs migration if necessary, then returns the appdata directory.

This is used for the log directory, so it cannot invoke Boost logging!

Returns
The path of the appdata directory that should be used.

Definition at line 301 of file misc.cpp.

◆ appliance_readiness()

appliance_readiness_t platf::appliance_readiness ( )

Assess appliance-mode readiness without changing any state.

Returns
Readiness details. On non-Linux platforms all fields are false and the diagnostic is "unsupported".

Definition at line 1972 of file misc.cpp.

◆ clipboard_available()

bool platf::clipboard_available ( )

Definition at line 1871 of file misc.cpp.

◆ create_high_precision_timer()

std::unique_ptr< high_precision_timer > platf::create_high_precision_timer ( )

Create platform-specific timer capable of high-precision sleep.

Returns
A unique pointer to timer

Definition at line 1811 of file misc.cpp.

◆ detect_session_environment()

session_environment_t platf::detect_session_environment ( )

Detect the current session/compositor environment.

Returns
The detected environment. On non-Linux platforms this reports unknown.

Definition at line 1882 of file misc.cpp.

◆ display()

std::shared_ptr< display_t > platf::display ( mem_type_e hwdevice_type,
const std::string & display_name,
const video::config_t & config )

Get the display_t instance for the given hwdevice_type. If display_name is empty, use the first monitor that's compatible you can find If you require to use this parameter in a separate thread, make a copy of it.

Parameters
display_nameThe name of the monitor that SHOULD be displayed
configStream configuration
Returns
The display_t instance based on hwdevice_type.

Definition at line 1658 of file misc.cpp.

◆ display_names()

std::vector< std::string > platf::display_names ( mem_type_e hwdevice_type)

Definition at line 1613 of file misc.cpp.

◆ enable_socket_qos()

std::unique_ptr< deinit_t > platf::enable_socket_qos ( uintptr_t native_socket,
boost::asio::ip::address & address,
uint16_t port,
qos_data_type_e data_type,
bool dscp_tagging )

Enable QoS on the given socket for traffic to the specified destination.

Enables QoS on the given socket for traffic to the specified destination.

Parameters
native_socketThe native socket handle.
addressThe destination address for traffic sent on this socket.
portThe destination port for traffic sent on this socket.
data_typeThe type of traffic sent on this socket.
dscp_taggingSpecifies whether to enable DSCP tagging on outgoing traffic.

Definition at line 1470 of file misc.cpp.

◆ from_sockaddr()

std::string platf::from_sockaddr ( const sockaddr * const ip_addr)

Definition at line 383 of file misc.cpp.

◆ from_sockaddr_ex()

std::pair< std::uint16_t, std::string > platf::from_sockaddr_ex ( const sockaddr * const ip_addr)

Definition at line 396 of file misc.cpp.

◆ get_clipboard()

std::string platf::get_clipboard ( )

Definition at line 1816 of file misc.cpp.

◆ get_host_name()

std::string platf::get_host_name ( )

Returns the current computer name in UTF-8.

Returns
Computer name or a placeholder upon failure.

Definition at line 1533 of file misc.cpp.

◆ get_ifaddrs()

ifaddr_t platf::get_ifaddrs ( )

Definition at line 210 of file misc.cpp.

◆ get_local_ip_for_gateway()

std::string platf::get_local_ip_for_gateway ( )

Definition at line 441 of file misc.cpp.

◆ get_mac_address()

std::string platf::get_mac_address ( const std::string_view & address)

The MAC address of the interface that holds address.

Addresses are compared as addresses, not text, so a link-local address printed with its scope (fe80::1eth0) finds its interface.

Parameters
addressThe host address a client reached.
Returns
The MAC address, or 00:00:00:00:00:00 when no interface holds it.

Definition at line 412 of file misc.cpp.

◆ handle()

void * dyn::handle ( const std::vector< const char * > & libs)

Definition at line 95 of file misc.cpp.

◆ init()

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

Definition at line 1722 of file misc.cpp.

◆ load()

int dyn::load ( void * handle,
const std::vector< std::tuple< apiproc *, const char * > > & funcs,
bool strict )

Definition at line 118 of file misc.cpp.

◆ needs_encoder_reenumeration()

bool platf::needs_encoder_reenumeration ( )

Check if GPUs/drivers have changed since the last call to this function.

Returns if GPUs/drivers have changed since the last call to this function.

Returns
true if a change has occurred or if it is unknown whether a change occurred.

Definition at line 1653 of file misc.cpp.

◆ open_drm_node()

int platf::open_drm_node ( const char * path,
int flags )

Open a DRM device node without becoming its DRM master.

The kernel makes whoever opens a primary node (/dev/dri/cardN) while no one holds master that device's master. Hermes never sets modes, but a master it holds keeps logind from handing the device back to the compositor when its session becomes active again: switch to a text console during a stream and back, and the compositor is locked out of that GPU until the stream ends. So drop master straight away, as logind and KWin do for the fds they open. The fd is close-on-exec, so launched apps cannot inherit it.

Parameters
pathThe device node.
flagsopen(2) flags; O_CLOEXEC is added.
Returns
An owned file descriptor, or -1 with errno set.

Definition at line 138 of file misc.cpp.

◆ open_url()

void platf::open_url ( const std::string & url)

Open a url in the default web browser.

Parameters
urlThe url to open.

Definition at line 546 of file misc.cpp.

◆ process_group_running()

bool platf::process_group_running ( std::uintptr_t native_handle)

Check if a process group still has running children.

Parameters
native_handleThe native handle of the process group.
Returns
true if processes are still running.

Definition at line 1064 of file misc.cpp.

◆ request_process_group_exit()

bool platf::request_process_group_exit ( std::uintptr_t native_handle)

Attempt to gracefully terminate a process group.

Parameters
native_handleThe native handle of the process group.
Returns
true if termination was successfully requested.

Definition at line 1054 of file misc.cpp.

◆ request_user_service_stop()

bool platf::request_user_service_stop ( )

Ask the user manager to stop Hermes when Quit was selected inside its service.

Definition at line 1068 of file misc.cpp.

◆ restart()

void platf::restart ( )

Definition at line 1040 of file misc.cpp.

◆ restart_on_exit()

void platf::restart_on_exit ( )

Definition at line 1006 of file misc.cpp.

◆ run_command()

bp::child platf::run_command ( bool elevated,
bool interactive,
const std::string & cmd,
boost::filesystem::path & working_dir,
const bp::environment & env,
FILE * file,
std::error_code & ec,
bp::group * group )

Definition at line 521 of file misc.cpp.

◆ send()

bool platf::send ( send_info_t & send_info)

Definition at line 1333 of file misc.cpp.

◆ send_batch()

bool platf::send_batch ( batched_send_info_t & send_info)

Definition at line 1126 of file misc.cpp.

◆ set_clipboard()

bool platf::set_clipboard ( const std::string & content)

Definition at line 1853 of file misc.cpp.

◆ set_env()

int platf::set_env ( const std::string & name,
const std::string & value )

Set an environment variable.

Parameters
nameThe name of the environment variable.
valueThe value to set the environment variable to.
Returns
0 on success, non-zero on failure.

Definition at line 1046 of file misc.cpp.

◆ streaming_will_start()

void platf::streaming_will_start ( )

Definition at line 994 of file misc.cpp.

◆ streaming_will_stop()

void platf::streaming_will_stop ( )

Definition at line 1000 of file misc.cpp.

◆ to_sockaddr() [1/2]

struct sockaddr_in platf::to_sockaddr ( boost::asio::ip::address_v4 address,
uint16_t port )

Definition at line 1101 of file misc.cpp.

◆ to_sockaddr() [2/2]

struct sockaddr_in6 platf::to_sockaddr ( boost::asio::ip::address_v6 address,
uint16_t port )

Definition at line 1113 of file misc.cpp.

◆ touch_binds_to_output()

bool platf::touch_binds_to_output ( )

Whether the session binds a touchscreen or a pen to one output.

Such a device reports where on its own surface it was touched, so the compositor has to decide which output that surface stands for. KWin and Mutter bind it to a single output, and the coordinates Hermes sends are then relative to the streamed output alone. Everywhere else the device spans the whole desktop and the streamed output's offset within it is part of the coordinate.

Definition at line 198 of file misc.cpp.

◆ unset_env()

int platf::unset_env ( const std::string & name)

Unset an environment variable.

Parameters
nameThe name of the environment variable.
Returns
0 on success, non-zero on failure.

Definition at line 1050 of file misc.cpp.

◆ verify_wl()

bool platf::verify_wl ( )

Definition at line 1575 of file misc.cpp.

◆ wl_display()

std::shared_ptr< display_t > platf::wl_display ( mem_type_e hwdevice_type,
const std::string & display_name,
const video::config_t & config )

Definition at line 568 of file wlgrab.cpp.

◆ wl_display_names()

std::vector< std::string > platf::wl_display_names ( )

Definition at line 591 of file wlgrab.cpp.

Variable Documentation

◆ window_system

window_system_e window_system

Definition at line 92 of file misc.cpp.