|
game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
|
Manages a single running game process. More...
#include <game_process.h>
Public Types | |
| enum class | NotificationType { Info , Warning , Error } |
| Type of notification to display. More... | |
| enum class | State { NotStarted , Starting , Running , Stopping , Stopped , Error } |
| Current state of the game process. More... | |
Public Member Functions | |
| GameProcess (const Game &game) | |
| Constructor - creates a process for the given game. | |
| ~GameProcess () | |
| Destructor - stops the process if still running. | |
| void | attachToRunningProcess (int pid, const std::string &processName="") |
| Attach to an already-running process. | |
| const Game & | getGame () const |
| Get the game associated with this process. | |
| const LaunchInfo & | getLastLaunchInfo () const |
| Get information about what was applied during the last launch. | |
| int | getProcessId () const |
| Get the process ID. | |
| double | getRunningTimeSeconds () const |
| Get how long the process has been running. | |
| State | getState () const |
| Get current process state. | |
| int | getTrackedProcessId () const |
| Get the tracked game process ID. | |
| const std::string & | getTrackedProcessName () const |
| Get the name of the tracked game process. | |
| bool | isRunning () const |
| Check if process is currently running. | |
| bool | kill () |
| Force kill the game process. | |
| bool | launch () |
| Launch the game process. | |
| void | setOnExit (std::function< void(int exitCode)> callback) |
| Set callback for process exit. | |
| void | setOnNotification (std::function< void(NotificationType, const std::string &)> callback) |
| Set callback for notifications. | |
| void | setOnStateChanged (std::function< void(State)> callback) |
| Set callback for state changes. | |
| bool | stop () |
| Stop the game process gracefully. | |
| void | update () |
| Check if process is still running and update statistics. | |
Protected Member Functions | |
| void | notify (NotificationType type, const std::string &message) const |
Manages a single running game process.
Creates and monitors a game process, handling platform-specific launching (native, Wine, Proton) and tracking play time statistics.
Definition at line 79 of file game_process.h.
|
strong |
Type of notification to display.
| Enumerator | |
|---|---|
| Info | |
| Warning | |
| Error | |
Definition at line 279 of file game_process.h.
|
strong |
Current state of the game process.
Definition at line 90 of file game_process.h.
| GameProcess::GameProcess | ( | const Game & | game | ) |
Constructor - creates a process for the given game.
| game | Game to launch (will be copied to prevent dangling references) |
Definition at line 279 of file game_process.cpp.
| GameProcess::~GameProcess | ( | ) |
Destructor - stops the process if still running.
Automatically calls stop() if the process is still running.
Definition at line 287 of file game_process.cpp.
References isRunning(), and stop().
| void GameProcess::attachToRunningProcess | ( | int | pid, |
| const std::string & | processName = "" ) |
Attach to an already-running process.
| pid | The process ID of the running game |
| processName | Optional name of the executable (e.g., "Wow.exe") |
Used to track games that were launched externally (e.g., via Lutris) or were already running when the application started. Sets state to Running and begins tracking.
Definition at line 743 of file game_process.cpp.
References Logger::debug(), Logger::error(), Logger::info(), anonymous_namespace{game_process.cpp}::GameModeAPI::instance(), FrameMetricsService::instance(), parseProcessStartTime(), anonymous_namespace{game_process.cpp}::GameModeAPI::requestStartFor(), and Running.
|
inline |
Get the game associated with this process.
Definition at line 244 of file game_process.h.
|
inline |
Get information about what was applied during the last launch.
Definition at line 235 of file game_process.h.
Referenced by GameProcessManager::getRunningProcessSnapshot().
|
inline |
Get the process ID.
Definition at line 199 of file game_process.h.
Referenced by GameProcessManager::getRunningProcessSnapshot().
| double GameProcess::getRunningTimeSeconds | ( | ) | const |
Get how long the process has been running.
Definition at line 961 of file game_process.cpp.
References isRunning().
|
inline |
Get current process state.
Definition at line 181 of file game_process.h.
|
inline |
Get the tracked game process ID.
For launcher games (Battle.net, EA App, etc.), this returns the actual game process PID which may differ from getProcessId().
Definition at line 211 of file game_process.h.
Referenced by GameProcessManager::getRunningProcessSnapshot().
|
inline |
Get the name of the tracked game process.
Definition at line 220 of file game_process.h.
Referenced by GameProcessManager::getRunningProcessSnapshot().
|
inline |
Check if process is currently running.
Definition at line 190 of file game_process.h.
References Running.
Referenced by ~GameProcess(), getRunningTimeSeconds(), kill(), and stop().
| bool GameProcess::kill | ( | ) |
Force kill the game process.
Forcefully terminates the process:
Use this only if stop() fails or hangs.
Definition at line 675 of file game_process.cpp.
References Logger::info(), isRunning(), kill(), Stopped, and Logger::warn().
| bool GameProcess::launch | ( | ) |
Launch the game process.
Launches the game using the appropriate platform runner:
On success, the process state becomes Running and startTime is recorded. On failure, the process state becomes Error.
Definition at line 373 of file game_process.cpp.
References DOSBox, Error, Logger::error(), ProcessExecutor::executeWithOutput(), ProcessResult::exitCode, Logger::info(), anonymous_namespace{game_process.cpp}::GameModeAPI::instance(), FrameMetricsService::instance(), Native, notify(), NotStarted, ProcessResult::output, Proton, anonymous_namespace{game_process.cpp}::GameModeAPI::requestStartFor(), Running, ScummVM, FrameMetricsService::startCollection(), Starting, Stopped, and Wine.
|
protected |
Definition at line 302 of file game_process.cpp.
Referenced by launch().
|
inline |
Set callback for process exit.
| callback | Function to call when process exits (receives exit code) |
The callback is invoked when the process terminates naturally.
Definition at line 270 of file game_process.h.
|
inline |
Set callback for notifications.
| callback | Function to call when a notification should be displayed |
This allows the process to communicate status messages to the UI layer without depending on any specific notification implementation.
Definition at line 293 of file game_process.h.
|
inline |
Set callback for state changes.
| callback | Function to call when state changes |
The callback is invoked whenever the process state transitions.
Definition at line 259 of file game_process.h.
| bool GameProcess::stop | ( | ) |
Stop the game process gracefully.
Sends a termination signal to the process:
Updates game statistics (play time, last played) before stopping. State becomes Stopped after this call.
Definition at line 590 of file game_process.cpp.
References Logger::info(), FrameMetricsService::instance(), isRunning(), kill(), FrameMetricsService::stopCollection(), Stopped, Stopping, and Logger::warn().
Referenced by ~GameProcess().
| void GameProcess::update | ( | ) |
Check if process is still running and update statistics.
This should be called every frame (or at least regularly) to:
Automatically transitions state to Stopped if process has exited.
Definition at line 993 of file game_process.cpp.
References Logger::info(), FrameMetricsService::instance(), Running, FrameMetricsService::stopCollection(), Stopped, and Logger::warn().