![]() |
OpenSWMM Engine
6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
|
Manages plugin discovery, loading, and lifecycle for one engine instance. More...
#include <PluginFactory.hpp>
Classes | |
| struct | ComponentEntry |
| List all discovered component info entries. More... | |
| struct | ComponentLibraryRecord |
Public Member Functions | |
| PluginFactory () | |
| Register builtin metadata and scan the engine library directory plus plugins/components. Does not construct plugin instances. Discovery can load dynamic-library code and run metadata entry points; filesystem/allocation/plugin exceptions propagate. Directory iteration order is not globally sorted for ordinary IO-plugin discovery. | |
| ~PluginFactory () | |
| Delete owned plugin instances before unloading per-instance IO libraries. Requires no outstanding update/callback/borrowed plugin use; global HydroCouple catalogue handles are retained separately until process exit or explicit test reset. | |
| PluginFactory (const PluginFactory &)=delete | |
| Disable copying owned plugin pointers and library references. | |
| PluginFactory & | operator= (const PluginFactory &)=delete |
| Disable copy assignment of plugin/library ownership. | |
| PluginFactory (PluginFactory &&) noexcept=default | |
| Move the registry, raw-pointer ownership lists and library entries. | |
| PluginFactory & | operator= (PluginFactory &&) noexcept=default |
| Move-assign registry and ownership containers using their default operations. | |
| void | discover (std::function< void(const std::string &)> warn_cb={}) |
| Rescan the host library directory and its plugins/components subdirectories. | |
| IPluginComponentInfo * | load_library (const std::string &path, std::function< void(const std::string &)> warn_cb={}) |
| Load/register an IO plugin or offer a non-IO library to the global component catalogue. | |
| IPluginComponentInfo * | find_component (const std::string &id_or_path, std::function< void(const std::string &)> warn_cb={}) |
| Resolve an exact registered ID/version or load an apparent platform library path. | |
| std::vector< ComponentEntry > | discovered_components () const |
| Snapshot registered metadata/capabilities in retained library order. | |
| int | load_plugins (const std::vector< PluginSpec > &specs, std::function< void(const std::string &)> warn_cb={}, const SimulationContext *io=nullptr) |
| Resolve specs and create every advertised input/output/report/state-IO capability. | |
| int | initialize_all (SimulationContext &ctx) |
| Initialize output, report and state-IO instances in that order. | |
| int | validate_all (SimulationContext &ctx) |
| Validate INITIALIZED output/report/state-IO plugins in list order. | |
| int | prepare_all (SimulationContext &ctx) |
| Prepare VALIDATED output and report plugins. | |
| int | update_all (const SimulationSnapshot &snapshot) |
| Deliver a snapshot to PREPARED/UPDATING output and report plugins. | |
| int | finalize_all (SimulationContext &ctx) |
| Finalize every output/report/state-IO plugin without a state gate. | |
| int | write_summary_all (SimulationContext &ctx) |
| Ask every report plugin to write a summary without a state gate. | |
| const std::vector< IInputPlugin * > & | input_plugins () const noexcept |
| Borrow the retained capability list without transferring ownership. | |
| const std::vector< IOutputPlugin * > & | output_plugins () const noexcept |
| Borrow the retained capability list without transferring ownership. | |
| const std::vector< IReportPlugin * > & | report_plugins () const noexcept |
| Borrow the retained capability list without transferring ownership. | |
| const std::vector< IStateIOPlugin * > & | state_io_plugins () const noexcept |
| Borrow the retained capability list without transferring ownership. | |
| int | plugin_count () const noexcept |
| Count all injected/created capability instances. | |
| bool | empty () const noexcept |
| Test whether any capability instance is retained. | |
| void | unload_all () |
| Delete all owned capability instances, clear registries/args and release IO library handles. Does not implicitly finalize plugins or wait for IOThread. Caller must drain callbacks and cease borrowed-pointer use first. Builtin metadata singletons survive; process-global component records/handles are not cleared. | |
| void | add_output_plugin (IOutputPlugin *plugin, std::vector< std::string > args={}, IPluginComponentInfo *info=nullptr) |
| Adopt a programmatically constructed output plugin without lifecycle calls. | |
| void | add_report_plugin (IReportPlugin *plugin, std::vector< std::string > args={}, IPluginComponentInfo *info=nullptr) |
| Adopt a report plugin without lifecycle calls or validation. | |
| void | add_input_plugin (IInputPlugin *plugin) |
| Adopt an input plugin without lifecycle calls or validation. | |
| void | add_state_io_plugin (IStateIOPlugin *plugin) |
| Adopt a state-IO plugin without lifecycle calls or validation. | |
Static Public Member Functions | |
| static bool | hydrocouple_enabled () noexcept |
| Report this build's optional HydroCouple component-loader support. | |
| static std::string | component_abi_stamp () |
| Copy the engine's HydroCouple component ABI fingerprint. | |
| static int | component_search_path_add (const std::string &dir) |
| Scan an explicit directory into the process-global component catalogue. | |
| static std::vector< ComponentLibraryRecord > | component_libraries () |
| Snapshot process-global loaded/refused component records under its mutex. | |
| static void | component_catalog_reset_for_testing () |
| Close globally retained component handles and reset records/default-discovery state. Tests must ensure no component instances, metadata pointers or executing code remain borrowed. Mutex serializes catalogue mutation but cannot make live instance unloading safe. The next query rediscovers defaults/environment. | |
Manages plugin discovery, loading, and lifecycle for one engine instance.
One PluginFactory per SWMMEngine instance (NOT a singleton). On construction, auto-discovers compatible plugin libraries in standard search directories.
| openswmm::PluginFactory::PluginFactory | ( | ) |
Register builtin metadata and scan the engine library directory plus plugins/components. Does not construct plugin instances. Discovery can load dynamic-library code and run metadata entry points; filesystem/allocation/plugin exceptions propagate. Directory iteration order is not globally sorted for ordinary IO-plugin discovery.
| openswmm::PluginFactory::~PluginFactory | ( | ) |
Delete owned plugin instances before unloading per-instance IO libraries. Requires no outstanding update/callback/borrowed plugin use; global HydroCouple catalogue handles are retained separately until process exit or explicit test reset.
|
delete |
Disable copying owned plugin pointers and library references.
|
defaultnoexcept |
Move the registry, raw-pointer ownership lists and library entries.
| void openswmm::PluginFactory::add_input_plugin | ( | IInputPlugin * | plugin | ) |
Adopt an input plugin without lifecycle calls or validation.
| plugin | Required nonnull uniquely owned instance, deleted on unload. Input lifecycle is managed separately from the all() output/report dispatchers. |
| void openswmm::PluginFactory::add_output_plugin | ( | IOutputPlugin * | plugin, |
| std::vector< std::string > | args = {}, | ||
| IPluginComponentInfo * | info = nullptr ) |
Adopt a programmatically constructed output plugin without lifecycle calls.
| plugin | Required nonnull, uniquely owned compatible instance; no null or duplicate checks occur. Factory deletes it on unload. |
| args | Initialization strings moved into the output's positional args slot. Caller must avoid concurrent dispatch; allocation failure can leave partially appended lists. |
| void openswmm::PluginFactory::add_report_plugin | ( | IReportPlugin * | plugin, |
| std::vector< std::string > | args = {}, | ||
| IPluginComponentInfo * | info = nullptr ) |
Adopt a report plugin without lifecycle calls or validation.
| plugin | Required nonnull uniquely owned instance, deleted on unload. Do not insert a duplicate pointer or mutate lists concurrently with dispatch. |
| void openswmm::PluginFactory::add_state_io_plugin | ( | IStateIOPlugin * | plugin | ) |
Adopt a state-IO plugin without lifecycle calls or validation.
| plugin | Required nonnull uniquely owned instance, deleted on unload. Do not insert duplicates or race active dispatch/collection access. |
|
static |
Copy the engine's HydroCouple component ABI fingerprint.
|
static |
Close globally retained component handles and reset records/default-discovery state. Tests must ensure no component instances, metadata pointers or executing code remain borrowed. Mutex serializes catalogue mutation but cannot make live instance unloading safe. The next query rediscovers defaults/environment.
|
static |
Snapshot process-global loaded/refused component records under its mutex.
|
static |
Scan an explicit directory into the process-global component catalogue.
| dir | Existing directory; platform path encoding rules apply. Defaults are scanned first so explicit candidates cannot replace default IDs. The path is recorded for bookkeeping; later queries do not automatically rescan it. |
| void openswmm::PluginFactory::discover | ( | std::function< void(const std::string &)> | warn_cb = {} | ) |
Rescan the host library directory and its plugins/components subdirectories.
| warn_cb | Optional synchronous per-load warning sink; absent sinks drop those warnings. Callback exceptions propagate. Existing entries with the exact path spelling are skipped; no instances are created and missing components are not removed. Filesystem scans are shallow and unsorted for ordinary plugins. |
| std::vector< PluginFactory::ComponentEntry > openswmm::PluginFactory::discovered_components | ( | ) | const |
Snapshot registered metadata/capabilities in retained library order.
|
inlinenoexcept |
Test whether any capability instance is retained.
| int openswmm::PluginFactory::finalize_all | ( | SimulationContext & | ctx | ) |
Finalize every output/report/state-IO plugin without a state gate.
| [in,out] | ctx | Borrowed mutable engine state. Input plugins are skipped. |
| IPluginComponentInfo * openswmm::PluginFactory::find_component | ( | const std::string & | id_or_path, |
| std::function< void(const std::string &)> | warn_cb = {} ) |
Resolve an exact registered ID/version or load an apparent platform library path.
| id_or_path | Exact string; empty returns null. Slash/backslash or a recognized platform suffix routes to load_library(); otherwise lookup is case-sensitive. |
| warn_cb | Optional synchronous warning sink for load/lookup failure. |
|
staticnoexcept |
Report this build's optional HydroCouple component-loader support.
| int openswmm::PluginFactory::initialize_all | ( | SimulationContext & | ctx | ) |
Initialize output, report and state-IO instances in that order.
| ctx | Unused context; input instances are not initialized by this dispatcher. Each instance receives its retained positional arguments and originating component metadata. |
|
inlinenoexcept |
Borrow the retained capability list without transferring ownership.
| IPluginComponentInfo * openswmm::PluginFactory::load_library | ( | const std::string & | path, |
| std::function< void(const std::string &)> | warn_cb = {} ) |
Load/register an IO plugin or offer a non-IO library to the global component catalogue.
| path | Platform path spelling, compared literally for per-instance duplicates. Native loader uses LoadLibraryA or dlopen(RTLD_NOW|RTLD_LOCAL); WebAssembly cannot dynamically load. IO metadata entry points are invoked without a separate ABI stamp check; loaded plugins must match the engine toolchain/SDK. |
| warn_cb | Optional synchronous warning sink; absent means no warning output. |
| int openswmm::PluginFactory::load_plugins | ( | const std::vector< PluginSpec > & | specs, |
| std::function< void(const std::string &)> | warn_cb = {}, | ||
| const SimulationContext * | io = nullptr ) |
Resolve specs and create every advertised input/output/report/state-IO capability.
| specs | Borrowed ordered specs; path selects metadata and init_args are retained with each created capability instance. Explicit IO role selections suppress legacy output/report discovery for that role. Existing instances remain. |
| warn_cb | Optional synchronous resolution-warning sink. |
|
delete |
Disable copy assignment of plugin/library ownership.
|
defaultnoexcept |
Move-assign registry and ownership containers using their default operations.
|
inlinenoexcept |
Borrow the retained capability list without transferring ownership.
|
inlinenoexcept |
Count all injected/created capability instances.
| int openswmm::PluginFactory::prepare_all | ( | SimulationContext & | ctx | ) |
Prepare VALIDATED output and report plugins.
| [in,out] | ctx | Borrowed mutable state; input and state-IO plugins are not prepared by this dispatcher, regardless of their state. |
|
inlinenoexcept |
Borrow the retained capability list without transferring ownership.
|
inlinenoexcept |
Borrow the retained capability list without transferring ownership.
| void openswmm::PluginFactory::unload_all | ( | ) |
Delete all owned capability instances, clear registries/args and release IO library handles. Does not implicitly finalize plugins or wait for IOThread. Caller must drain callbacks and cease borrowed-pointer use first. Builtin metadata singletons survive; process-global component records/handles are not cleared.
| int openswmm::PluginFactory::update_all | ( | const SimulationSnapshot & | snapshot | ) |
Deliver a snapshot to PREPARED/UPDATING output and report plugins.
| snapshot | Borrowed immutable packet valid only during each callback; plugins must copy data they retain. Called serially by IOThread in native builds. Input/state-IO plugins and other states are skipped. |
| int openswmm::PluginFactory::validate_all | ( | SimulationContext & | ctx | ) |
Validate INITIALIZED output/report/state-IO plugins in list order.
| [in,out] | ctx | Borrowed engine state passed to each eligible plugin; input plugins and all non-INITIALIZED instances are skipped. |
| int openswmm::PluginFactory::write_summary_all | ( | SimulationContext & | ctx | ) |
Ask every report plugin to write a summary without a state gate.
| [in,out] | ctx | Borrowed engine state used by report implementations. |