VR-Engage  2.2
Loading...
Searching...
No Matches
appLauncherComponent.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file appLauncherComponent.h
7//! \brief Defines the DtAppLauncherComponent class that launches external applications when a player engages in a role.
8//!
9//! The component provides functionality to launch, position, and control external applications within the VR
10//! environment. It can be configured to specify application paths, window geometry, and behavior when disengaging from
11//! roles.
12//!
13//! \ingroup vreCommonComponents
14
15#pragma once
16
19
20// Must be included before any Qt header
21
22#include <QObject>
23#include <QProcess>
24
25#include <string>
26
27namespace makVrv
28{
29class DtDe;
30}
31
32namespace makVre
33{
34class DtInitTable;
35class DtPlayerStation;
36
38{
39//! \ingroup RoleConfigParams
40//! \defgroup AppLauncherComponentRoleParams App Launcher Component Role Parameters
41//! \roleInherits{PlayerComponentRoleParams}
42//! Configuration Options for app launcher component role.
43//! @{
44
45//! \vreRoleParam{application,string,"",appLauncherComponent,Path to the application executable to launch when engaging in the role.}
46constexpr const char* application = "application";
47
48//! \vreRoleParam{arguments,string,"",appLauncherComponent,Command-line arguments to pass to the launched application.}
49constexpr const char* arguments = "arguments";
50
51//! \vreRoleParam{height,int,768,appLauncherComponent,Desired height in pixels for the launched application window.}
52constexpr const char* height = "height";
53
54//! \vreRoleParam{positionX,int,100,appLauncherComponent,Desired X position in pixels for the launched application window.}
55constexpr const char* positionX = "positionX";
56
57//! \vreRoleParam{positionY,int,300,appLauncherComponent,Desired Y position in pixels for the launched application window.}
58constexpr const char* positionY = "positionY";
59
60//! \vreRoleParam{shutdownOnDisengage,bool,true,appLauncherComponent,Whether to terminate the launched application when disengaging from the role.}
61constexpr const char* shutdownOnDisengage = "shutdownOnDisengage";
62
63//! \vreRoleParam{vreBackOnTopDelay,float,8.0,appLauncherComponent,Delay in seconds before bringing the VR Engage window back to the foreground after launching the application.}
64constexpr const char* vreBackOnTopDelay = "vreBackOnTopDelay";
65
66//! \vreRoleParam{width,int,1024,appLauncherComponent,Desired width in pixels for the launched application window.}
67constexpr const char* width = "width";
68
69//! \vreRoleParam{windowTitle,string,"",appLauncherComponent,Window title of the launched application used for finding and positioning the window.}
70constexpr const char* windowTitle = "windowTitle";
71
72//! \vreRoleParam{workingDirectory,string,"",appLauncherComponent,Working directory for the launched application process.}
73constexpr const char* workingDirectory = "workingDirectory";
74
75//! @}
76} // namespace AppLauncherComponentConfig
77
78//! \brief Type identifier for DtAppLauncherComponent component
79constexpr const char* DtAppLauncherComponentType = "DtAppLauncherComponent";
80
81//! \brief Component for launching and managing external applications within the VR engagement environment
82//!
83//! DtAppLauncherComponent allows the system to launch external applications when a player engages in a role.
84//! It provides capabilities to configure application paths, working directories, command-line arguments,
85//! as well as control the window positioning, sizing, and lifecycle management of the launched application.
87{
88 Q_OBJECT
89
90public:
91 //! \brief Constructor for DtAppLauncherComponent
92 //!
93 //! Initializes component properties with default values.
95
96 //! \brief Virtual destructor for DtAppLauncherComponent
97 //!
98 //! Ensures proper cleanup of resources when the component is destroyed.
99 virtual ~DtAppLauncherComponent() override;
100
101 //! \brief Initializes the component with configuration from Lua
102 //!
103 //! Sets up the component based on provided configuration, including application path,
104 //! working directory, command-line arguments, window geometry, and behavior settings.
105 //! Launches the configured application and sets up signal connections for process events.
106 //!
107 //! \param station Pointer to the player station this component belongs to
108 //! \param config Configuration table containing initialization parameters
109 //! \return True if initialization succeeds, false otherwise
110 virtual bool initialize(DtPlayerStation* station, DtInitTable& config) override;
111
112 //! \brief Updates the component state
113 //!
114 //! Called each frame to handle component logic. Manages window positioning
115 //! and ensures the VR Engage window returns to foreground after a configured delay.
116 //!
117 //! \param dt Delta time in seconds since the last tick
118 virtual void tick(double dt) override;
119
120 //! \brief Repositions and resizes the launched application window
121 //!
122 //! Attempts to find the window by title and applies the configured position and size.
123 //!
124 //! \return True if the window was found and positioned, false otherwise
126
127 //! \brief Shuts down the component
128 //!
129 //! Removes attribute callbacks and terminates the launched process
130 //! if configured to do so when disengaging.
131 virtual void shutdown() override;
132
133 //! \brief Returns the component type identifier
134 //! \return The component type string
135 virtual const char* type() const override;
136
137public slots:
138 //! \brief Slot called when the launched process has started
139 //!
140 //! Logs a success message when the external process starts successfully.
142
143 //! \brief Slot called when the launched process fails to start
144 //!
145 //! Logs a warning when the external process fails to start.
146 //!
147 //! \param error The process error that occurred
148 void handleProcessFailed(QProcess::ProcessError error);
149
150 //! \brief Slot called when the launched process finishes execution
151 //!
152 //! Cleans up resources and removes the process reference from the attribute store.
153 //!
154 //! \param exitCode The exit code returned by the process
155 //! \param exitStatus The exit status of the process
156 void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
157
158protected:
159 //! \brief Called when the current application-level state changes
160 //!
161 //! Handles state transitions, particularly when entering the ENGAGED state.
162 //!
163 //! \param state The new application state
164 virtual void onCurrentStateChanged(std::string state);
165
166protected:
167 //! \brief Flag indicating whether to shut down the launched application when disengaging
169
170 //! \brief Pointer to the QProcess object representing the launched application
171 QProcess* myProcess;
172
173 //! \brief Flag indicating whether the window has been positioned
175
176 //! \brief Desired height for the launched application window in pixels
178
179 //! \brief Desired width for the launched application window in pixels
181
182 //! \brief Desired X position for the launched application window
184
185 //! \brief Desired Y position for the launched application window
187
188 //! \brief Window title of the launched application used for finding the window handle
189 std::string myWindowTitle;
190
191 //! \brief Delay in seconds before bringing the VR Engage window back to the foreground
193};
194
195} // namespace makVre
virtual void onCurrentStateChanged(std::string state)
Called when the current application-level state changes.
void handleProcessFailed(QProcess::ProcessError error)
Slot called when the launched process fails to start.
bool myShutdownOnDisengage
Flag indicating whether to shut down the launched application when disengaging.
Definition appLauncherComponent.h:168
virtual bool initialize(DtPlayerStation *station, DtInitTable &config) override
Initializes the component with configuration from Lua.
void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
Slot called when the launched process finishes execution.
std::string myWindowTitle
Window title of the launched application used for finding the window handle.
Definition appLauncherComponent.h:189
int myHeight
Desired height for the launched application window in pixels.
Definition appLauncherComponent.h:177
void handleProcessStarted()
Slot called when the launched process has started.
int myPositionY
Desired Y position for the launched application window.
Definition appLauncherComponent.h:186
DtAppLauncherComponent()
Constructor for DtAppLauncherComponent.
float myBackOnTopDelay
Delay in seconds before bringing the VR Engage window back to the foreground.
Definition appLauncherComponent.h:192
virtual bool repositionAndResizeWindow()
Repositions and resizes the launched application window.
QProcess * myProcess
Pointer to the QProcess object representing the launched application.
Definition appLauncherComponent.h:171
int myWidth
Desired width for the launched application window in pixels.
Definition appLauncherComponent.h:180
int myPositionX
Desired X position for the launched application window.
Definition appLauncherComponent.h:183
virtual void shutdown() override
Shuts down the component.
bool myWindowPositioned
Flag indicating whether the window has been positioned.
Definition appLauncherComponent.h:174
virtual const char * type() const override
Returns the component type identifier.
virtual void tick(double dt) override
Updates the component state.
virtual ~DtAppLauncherComponent() override
Virtual destructor for DtAppLauncherComponent.
Table-based access to Lua state for configuration data.
Definition initializer.h:38
DtPlayerComponent()
Constructor.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
constexpr const char * positionX
Definition appLauncherComponent.h:55
constexpr const char * workingDirectory
Definition appLauncherComponent.h:73
constexpr const char * windowTitle
Definition appLauncherComponent.h:70
constexpr const char * positionY
Definition appLauncherComponent.h:58
constexpr const char * shutdownOnDisengage
Definition appLauncherComponent.h:61
constexpr const char * width
Definition appLauncherComponent.h:67
constexpr const char * height
Definition appLauncherComponent.h:52
constexpr const char * application
Definition appLauncherComponent.h:46
constexpr const char * arguments
Definition appLauncherComponent.h:49
constexpr const char * vreBackOnTopDelay
Definition appLauncherComponent.h:64
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Definition appLauncherComponent.h:38
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtAppLauncherComponentType
Type identifier for DtAppLauncherComponent component.
Definition appLauncherComponent.h:79
Definition appLauncherComponent.h:28
Defines the DtPlayerComponent base class for VR-Engage role components.