OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
PluginFactory.hpp
Go to the documentation of this file.
1
44#ifndef OPENSWMM_ENGINE_PLUGIN_FACTORY_HPP
45#define OPENSWMM_ENGINE_PLUGIN_FACTORY_HPP
46
47#include <string>
48#include <vector>
49#include <functional>
50
51// Forward declarations — avoid pulling in full plugin SDK in every TU
52namespace openswmm {
53 class IPluginComponentInfo;
54 class IOutputPlugin;
55 class IReportPlugin;
56 struct SimulationContext;
57 struct SimulationSnapshot;
58 struct PluginSpec;
59}
60
61namespace openswmm {
62
73public:
74 PluginFactory() = default;
76
77 // Non-copyable, movable
78 PluginFactory(const PluginFactory&) = delete;
80 PluginFactory(PluginFactory&&) noexcept = default;
81 PluginFactory& operator=(PluginFactory&&) noexcept = default;
82
83 // -----------------------------------------------------------------------
84 // Loading
85 // -----------------------------------------------------------------------
86
100 int load_plugins(
101 const std::vector<PluginSpec>& specs,
102 std::function<void(const std::string&)> warn_cb = {}
103 );
104
105 // -----------------------------------------------------------------------
106 // Lifecycle dispatch (main thread — call in order)
107 // -----------------------------------------------------------------------
108
115
120
125
135 int update_all(const SimulationSnapshot& snapshot);
136
143
150
151 // -----------------------------------------------------------------------
152 // Introspection
153 // -----------------------------------------------------------------------
154
156 const std::vector<IOutputPlugin*>& output_plugins() const noexcept {
157 return output_plugins_;
158 }
159
161 const std::vector<IReportPlugin*>& report_plugins() const noexcept {
162 return report_plugins_;
163 }
164
166 int plugin_count() const noexcept {
167 return static_cast<int>(output_plugins_.size() + report_plugins_.size());
168 }
169
171 bool empty() const noexcept { return plugin_count() == 0; }
172
174 void unload_all();
175
184 void add_output_plugin(IOutputPlugin* plugin,
185 std::vector<std::string> args = {});
186
190 void add_report_plugin(IReportPlugin* plugin);
191
192private:
193 // -----------------------------------------------------------------------
194 // Internal library handle record
195 // -----------------------------------------------------------------------
196
197 struct LibEntry {
198 void* handle = nullptr;
199 IPluginComponentInfo* info = nullptr;
200 std::string path;
201 };
202
203 std::vector<LibEntry> libs_;
204 std::vector<IOutputPlugin*> output_plugins_;
205 std::vector<IReportPlugin*> report_plugins_;
206 std::vector<std::vector<std::string>> init_args_;
207
208 // -----------------------------------------------------------------------
209 // Platform-specific helpers
210 // -----------------------------------------------------------------------
211
212 static void* platform_load(const std::string& path);
213 static void platform_unload(void* handle) noexcept;
214 static void* platform_sym(void* handle, const char* sym) noexcept;
215 static std::string platform_error() noexcept;
216};
217
218} /* namespace openswmm */
219
220#endif /* OPENSWMM_ENGINE_PLUGIN_FACTORY_HPP */
Interface for output-writing plugins.
Definition IOutputPlugin.hpp:57
Manages all dynamically loaded plugins for one engine instance.
Definition PluginFactory.hpp:72
int prepare_all(SimulationContext &ctx)
Call prepare() on all plugins (open output files, write headers).
Definition PluginFactory.cpp:227
int validate_all(SimulationContext &ctx)
Call validate() on all plugins.
Definition PluginFactory.cpp:208
~PluginFactory()
Definition PluginFactory.cpp:41
PluginFactory(PluginFactory &&) noexcept=default
void add_output_plugin(IOutputPlugin *plugin, std::vector< std::string > args={})
Inject a pre-created output plugin instance (takes ownership).
Definition PluginFactory.cpp:301
int write_summary_all(SimulationContext &ctx)
Call write_summary() on all report plugins.
Definition PluginFactory.cpp:284
const std::vector< IReportPlugin * > & report_plugins() const noexcept
All loaded report plugin instances.
Definition PluginFactory.hpp:161
int load_plugins(const std::vector< PluginSpec > &specs, std::function< void(const std::string &)> warn_cb={})
Load all plugins listed in the given specs.
Definition PluginFactory.cpp:94
bool empty() const noexcept
True if no plugins have been loaded.
Definition PluginFactory.hpp:171
void unload_all()
Unload all plugins and close library handles.
Definition PluginFactory.cpp:315
PluginFactory(const PluginFactory &)=delete
int initialize_all(SimulationContext &ctx)
Call initialize() on all output and report plugins.
Definition PluginFactory.cpp:167
int finalize_all(SimulationContext &ctx)
Call finalize() on all plugins.
Definition PluginFactory.cpp:267
const std::vector< IOutputPlugin * > & output_plugins() const noexcept
All loaded output plugin instances.
Definition PluginFactory.hpp:156
int update_all(const SimulationSnapshot &snapshot)
Deliver a snapshot to all output AND report plugins.
Definition PluginFactory.cpp:246
PluginFactory & operator=(const PluginFactory &)=delete
int plugin_count() const noexcept
Total number of loaded plugins (output + report).
Definition PluginFactory.hpp:166
void add_report_plugin(IReportPlugin *plugin)
Inject a pre-created report plugin instance (takes ownership).
Definition PluginFactory.cpp:307
Definition Controls.cpp:24
One plugin entry from the [PLUGINS] section.
Definition SimulationContext.hpp:99
Central, reentrant simulation context.
Definition SimulationContext.hpp:141
Complete simulation state snapshot at one output time step.
Definition SimulationSnapshot.hpp:90