VR-Engage  2.3
Loading...
Searching...
No Matches
vrePluginManager.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2026 MAK Technologies, Inc.
3** All rights reserved.
4******************************************************************************/
5
6//! \file vrePluginManager.h
7//! \brief Declares the frontend plugin wrapper and plugin manager.
8
9#pragma once
10
12
13#include <map>
14#include <string>
15#include <vector>
16
17class DtDynamicLibrary;
18class DtFilename;
19
20namespace makVre
21{
23
24//! \brief Function pointer type for plugin initialization.
26
27//! \brief Function pointer type for plugin post-initialization.
29
30//! \brief Function pointer type for plugin shutdown.
32
33//! \brief Symbol name of the required plugin initialization entry point.
34constexpr const char* DtVreInitPluginFunction = "initPlayerStationModule";
35
36//! \brief Symbol name of the optional plugin post-initialization entry point.
37constexpr const char* DtVrePostInitPluginFunction = "postInitPlayerStationModule";
38
39//! \brief Symbol name of the optional plugin shutdown entry point.
40constexpr const char* DtVreShutdownPluginFunction = "shutdownPlayerStationModule";
41
42//! \brief Wraps a single frontend plugin DLL and its resolved entry points.
44{
45public:
46 //! \brief Constructs a plugin wrapper for the specified library.
47 //! \param libName Name or path of the plugin library to load.
48 DtVrePlugin(const std::string& libName);
49
50 //! \brief Destroys the plugin wrapper without unloading recognized plugin libraries.
51 //!
52 //! Libraries with resolved plugin entry points and their loader objects are
53 //! intentionally retained until process exit because disconnected Boost.Signals2
54 //! connections can still reference plugin code. Failed or incompatible loads are released.
55 virtual ~DtVrePlugin();
56
57 //! \brief Resolves the plugin entry points.
58 //! \return True if the required init entry point was found.
59 virtual void init();
60
61 //! \brief Calls the plugin init entry point.
62 //! \param app The player-station application.
63 //! \return True if plugin initialization succeeded.
65
66 //! \brief Calls the plugin post-init entry point when available.
67 //! \param app The player-station application.
68 //! \return True if plugin post-initialization succeeded or was not present.
70
71 //! \brief Calls the plugin shutdown entry point when available.
72 //! \param app The player-station application.
74
75 //! \brief Returns whether the underlying dynamic library loaded successfully.
76 //! \return True if the wrapped dynamic library is valid.
77 virtual bool isValid() const;
78
79 //! \brief Returns whether the underlying dynamic library loaded successfully.
80 //! \return True if the wrapped dynamic library is valid.
81 virtual bool hasValidEntryPoints() const;
82
83 //! \brief Returns whether the plugin exposes the required init entry point.
84 //! \return True if the init entry point was resolved during init().
85 virtual bool hasInit() const;
86
87 //! \brief Returns whether the plugin exposes the optional post-init entry point.
88 //! \return True if the post-init entry point was resolved during init().
89 virtual bool hasPostInit() const;
90
91 //! \brief Returns whether the plugin exposes the optional shutdown entry point.
92 //! \return True if the shutdown entry point was resolved during init().
93 virtual bool hasShutdown() const;
94
95 //! \brief Returns the original plugin library name.
96 //! \return The library name or path used to construct the plugin.
97 virtual std::string libraryName() const;
98
99protected:
100 //! \brief The dynamic-library loader for this plugin.
101 //! \note Retained for process lifetime once a plugin entry point has been resolved.
102 DtDynamicLibrary* myDynamicLibrary;
103
104 //! \brief The original library name used to load the plugin.
105 std::string myLibraryName;
106
107 //! \brief The required plugin init entry point.
109
110 //! \brief The optional plugin post-init entry point.
112
113 //! \brief The optional plugin shutdown entry point.
115};
116
117//! \brief Owns frontend plugins for the lifetime of the player-station app.
119{
120public:
121 //! \brief Aggregates metadata and ownership for a single discovered plugin.
123 {
124 //! \brief Short filename of the plugin without directory component.
125 std::string name;
126
127 //! \brief Full path used to load the plugin.
128 std::string fullPath;
129
130 //! \brief True if the plugin exposes the init entry point.
131 bool hasInit = false;
132
133 //! \brief True if the plugin exposes the post-init entry point.
134 bool hasPostInit = false;
135
136 //! \brief True if the plugin exposes the shutdown entry point.
137 bool hasShutdown = false;
138
139 //! \brief Owning handle for the loaded plugin, or nullptr if load failed.
140 std::unique_ptr<DtVrePlugin> plugin = nullptr;
141 };
142
143 //! \brief Constructs an empty plugin manager.
145
146 //! \brief Destroys the manager and its plugin wrappers.
147 //! \note Recognized plugin DLLs remain loaded until process exit.
149
154
155 //! \brief Stores the player-station application pointer for later use by plugin entry points.
156 //! \param app Non-owning pointer to the player-station application.
157 virtual void initialize(DtPlayerStationApp* app);
158
159 //! \brief Sets the directory path that discoverPlugins() will scan.
160 //! \param directory Full path to the plugin directory, including a trailing path separator.
161 virtual void setPluginDirectory(const std::string& directory);
162
163 //! \brief Returns the plugin directory path.
164 //! \return The directory set by setPluginDirectory(), or an empty string if not yet set.
165 virtual std::string pluginDirectory() const;
166
167 //! \brief Calls the init entry point on all plugins that have been successfully loaded.
168 virtual void initializePlugins();
169
170 //! \brief Calls the post-init entry point on all loaded plugins in load order.
171 virtual void postInitializePlugins();
172
173 //! \brief Calls the shutdown entry point on all loaded plugins in load order.
174 virtual void shutdownPlugins();
175
176 //! \brief Returns the list of all discovered plugins in load order.
177 //! \return Non-owning reference to the internal plugin list.
178 const std::vector<PluginInfo>& plugins() const;
179
180 //! \brief Loads a single plugin by path if it has not already been loaded.
181 //! \param filename Name or full path of the plugin library.
182 //! \return True if the plugin was successfully loaded and has valid entry points.
183 virtual bool loadPlugin(const std::string& filename);
184
185 //! \brief Scans the configured plugin directory for DLL files and loads each one.
186 //!
187 //! Files are sorted alphabetically before loading so load order is deterministic.
188 //! Already-loaded plugins are skipped. Requires setPluginDirectory() to have been
189 //! called before invoking this method.
190 virtual void discoverPlugins();
191
192protected:
193 //! \brief Ordered list of all plugins discovered or explicitly loaded.
194 std::vector<PluginInfo> myPlugins;
195
196 //! \brief Full path to the directory scanned by discoverPlugins().
197 std::string myPluginDirectory;
198
199 //! \brief Non-owning pointer to the player-station application.
200 //!
201 //! Stored by initialize() and forwarded to each plugin's entry points.
202 //! \note The lifetime of the referenced application must exceed the lifetime of this manager.
204};
205
206} // namespace makVre
Top-level class representing the VR-Engage application.
Definition playerStationApp.h:155
virtual bool isValid() const
Returns whether the underlying dynamic library loaded successfully.
virtual void init()
Resolves the plugin entry points.
virtual bool hasValidEntryPoints() const
Returns whether the underlying dynamic library loaded successfully.
DtDynamicLibrary * myDynamicLibrary
The dynamic-library loader for this plugin.
Definition vrePluginManager.h:102
virtual bool postInitializePlugin(DtPlayerStationApp *app)
Calls the plugin post-init entry point when available.
DtVrePlugin(const std::string &libName)
Constructs a plugin wrapper for the specified library.
InitPlayerStationDllFunction myInitFunc
The required plugin init entry point.
Definition vrePluginManager.h:108
std::string myLibraryName
The original library name used to load the plugin.
Definition vrePluginManager.h:105
ShutdownPlayerStationDllFunction myShutdownFunc
The optional plugin shutdown entry point.
Definition vrePluginManager.h:114
virtual bool hasShutdown() const
Returns whether the plugin exposes the optional shutdown entry point.
virtual bool initializePlugin(DtPlayerStationApp *app)
Calls the plugin init entry point.
PostInitPlayerStationDllFunction myPostInitFunc
The optional plugin post-init entry point.
Definition vrePluginManager.h:111
virtual std::string libraryName() const
Returns the original plugin library name.
virtual bool hasInit() const
Returns whether the plugin exposes the required init entry point.
virtual bool hasPostInit() const
Returns whether the plugin exposes the optional post-init entry point.
virtual void shutdownPlugin(DtPlayerStationApp *app)
Calls the plugin shutdown entry point when available.
virtual ~DtVrePlugin()
Destroys the plugin wrapper without unloading recognized plugin libraries.
virtual void shutdownPlugins()
Calls the shutdown entry point on all loaded plugins in load order.
std::string myPluginDirectory
Full path to the directory scanned by discoverPlugins().
Definition vrePluginManager.h:197
virtual bool loadPlugin(const std::string &filename)
Loads a single plugin by path if it has not already been loaded.
virtual void initializePlugins()
Calls the init entry point on all plugins that have been successfully loaded.
std::vector< PluginInfo > myPlugins
Ordered list of all plugins discovered or explicitly loaded.
Definition vrePluginManager.h:194
virtual ~DtVrePluginManager()
Destroys the manager and its plugin wrappers.
DtVrePluginManager(DtVrePluginManager &&)=default
DtVrePluginManager()
Constructs an empty plugin manager.
DtPlayerStationApp * myApp
Non-owning pointer to the player-station application.
Definition vrePluginManager.h:203
DtVrePluginManager & operator=(const DtVrePluginManager &)=delete
DtVrePluginManager & operator=(DtVrePluginManager &&)=default
virtual void initialize(DtPlayerStationApp *app)
Stores the player-station application pointer for later use by plugin entry points.
const std::vector< PluginInfo > & plugins() const
Returns the list of all discovered plugins in load order.
virtual void postInitializePlugins()
Calls the post-init entry point on all loaded plugins in load order.
virtual void setPluginDirectory(const std::string &directory)
Sets the directory path that discoverPlugins() will scan.
virtual void discoverPlugins()
Scans the configured plugin directory for DLL files and loads each one.
virtual std::string pluginDirectory() const
Returns the plugin directory path.
DtVrePluginManager(const DtVrePluginManager &)=delete
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
!
Definition glsVreMessageUtil.h:50
constexpr const char * DtVreShutdownPluginFunction
Symbol name of the optional plugin shutdown entry point.
Definition vrePluginManager.h:40
bool(*)(DtPlayerStationApp *app) PostInitPlayerStationDllFunction
Function pointer type for plugin post-initialization.
Definition vrePluginManager.h:28
bool(*)(DtPlayerStationApp *app) InitPlayerStationDllFunction
Function pointer type for plugin initialization.
Definition vrePluginManager.h:25
void(*)(DtPlayerStationApp *app) ShutdownPlayerStationDllFunction
Function pointer type for plugin shutdown.
Definition vrePluginManager.h:31
constexpr const char * DtVreInitPluginFunction
Symbol name of the required plugin initialization entry point.
Definition vrePluginManager.h:34
constexpr const char * DtVrePostInitPluginFunction
Symbol name of the optional plugin post-initialization entry point.
Definition vrePluginManager.h:37
Aggregates metadata and ownership for a single discovered plugin.
Definition vrePluginManager.h:123
bool hasInit
True if the plugin exposes the init entry point.
Definition vrePluginManager.h:131
std::string name
Short filename of the plugin without directory component.
Definition vrePluginManager.h:125
bool hasPostInit
True if the plugin exposes the post-init entry point.
Definition vrePluginManager.h:134
std::unique_ptr< DtVrePlugin > plugin
Owning handle for the loaded plugin, or nullptr if load failed.
Definition vrePluginManager.h:140
bool hasShutdown
True if the plugin exposes the shutdown entry point.
Definition vrePluginManager.h:137
std::string fullPath
Full path used to load the plugin.
Definition vrePluginManager.h:128