Engine → Modules → module_manager.h
module_manager¶
| Type | Class |
| Namespace | conjure::modules |
| Include File Path | engine/include/conjure/modules/module_manager.h |
| Source File Path | engine/src/modules/module_manager.cpp |
| API ↗ | Loading and managing modules |
Syntax¶
Constructors¶
| Access | Signature | Description |
|---|---|---|
| public | module_manager(
const module_manager_desc &desc,
core::event_bus &events); |
Important
Copy constructor and assignment has been deleted.
Destructors¶
| Access | Signature | Description |
|---|---|---|
| public | ~module_manager(); |
Variables¶
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | mConsumers | std:: | {} | |
| private | mDesc | module_manager_desc | {} | |
| private | mEvents | core::event_bus * | nullptr | |
| private | mHasPending | std::atomic<bool> | false | |
| private | m | u32 | 1 | |
| private | mPending | std:: | {} | |
| private | mRegistry | module_registry | {} | |
| private | mServices | service_table | {} | |
| private | m | std:: | {} |
Functions¶
Public¶
add_consumer¶
add_consumer¶void add_consumer(
module_consumer &consumer);Adds a consumer; consumers attach in add order and detach in reverse. Asserts when a module is LOADED or the consumer was already added.
add_manifest¶
add_manifest¶[[nodiscard]] core::result<module_id> add_manifest(
const std::filesystem::path &manifestPath);Registers a module from its module.json; the module root is the file's directory. A manifest that excludes the host platform is registered as SKIPPED.
add_static_module¶
add_static_module¶[[nodiscard]] core::result<module_id> add_static_module(
const static_module_desc &desc);Registers a module compiled into the host. The descriptor must outlive the manager. MANIFEST_INVALID, INVALID_NAME or DUPLICATE_NAME on a bad manifest.
any_loaded¶
any_loaded¶[[nodiscard]] bool any_loaded() const noexcept;True while at least one module is LOADED.
apply_pending¶
apply_pending¶void apply_pending();Performs every request in order. Costs one relaxed atomic load when idle. Requests for stale ids are dropped with a warning; failures are logged and kept in last_error().
desc¶
desc¶[[nodiscard]] const module_manager_desc &desc() const noexcept;discover¶
discover¶[[nodiscard]] core::result<u32> discover(
const std::filesystem::path &searchDirectory);Registers every immediate subdirectory of searchDirectory that holds a module.json, in name order, and returns how many were added. Per-module errors are collected into one error (valid modules are still added); a missing directory is MANIFEST_NOT_FOUND.
export_layout¶
export_layout¶[[nodiscard]] core::result<void> export_layout(
const std::filesystem::path &outputDirectory,
build_config targetConfig) const;Writes <out>/modules/<name>/ (manifest without editorOnly, the bin/<platform>-<arch>-<config>/ directory and the managed assemblies) for every LOADED module that is not an engine module, not editor-only and not static. The bin directory is copied entry by entry with its subfolders, following links, and leaves out every file or folder named *.lib, *.exp, *.ilk, *.a, *.pdb or *.dSYM (ASCII case ignored): dependent libraries and data files ship, link and debug by-products and native symbols do not. Files already in the output are overwritten. Other files of an earlier export stay, except that such by-products anywhere under the output bin directory are removed first (links there are not followed), unless that directory is the module's own bin directory or holds it. BINARY_NOT_FOUND names the missing configuration; EXPORT_FAILED any create, write, list, resolve, remove or copy error, an entry that is neither a file nor a folder (a broken link), a link back to a folder being copied and a missing managed assembly. A failure leaves the files copied before it in place. Paths past Windows' MAX_PATH are read and written in their extended-length form; a manifest that cannot be written carries the JSON writer's message, which names the path in that form.
load¶
load¶[[nodiscard]] core::result<void> load(
module_id id);Loads the module and the transitive closure of its dependencies in order, stopping at the first failure (earlier successes stay loaded).
load_all¶
load_all¶[[nodiscard]] core::result<void> load_all();Resolves every registered module and loads them in order, continuing past failures. Returns the first error.
pending_count¶
pending_count¶[[nodiscard]] usize pending_count() const noexcept;Number of requests waiting for apply_pending().
provide_service¶
provide_service¶template <typename ServiceType> void provide_service(
ServiceType &service);Provides a host service to module contexts. Asserts when a module is LOADED.
registry¶
registry¶[[nodiscard]] const module_registry ®istry() const noexcept;[[nodiscard]] module_registry ®istry() noexcept;Mutable registry for consumers recording ownership in attach().
reload¶
reload¶[[nodiscard]] core::result<void> reload(
module_id id,
reload_scope scope);Reloads the module and its LOADED dependents: detach with snapshots in reverse load order, close and reopen the binaries (FULL), attach in order and restore. A failing load leaves that module and the rest UNLOADED with their snapshots kept for the next successful load. The id stays valid across a reload.
remove_consumer¶
remove_consumer¶void remove_consumer(
module_consumer &consumer);Removes a consumer. Asserts when a module is LOADED.
request_reload¶
request_reload¶void request_reload(
module_id id,
reload_scope scope);request_unload¶
request_unload¶void request_unload(
module_id id,
unload_policy policy);services¶
services¶[[nodiscard]] const service_table &services() const noexcept;unload¶
unload¶[[nodiscard]] core::result<void> unload(
module_id id,
unload_policy policy);Unloads a LOADED module without LOADED dependents. Pre-checks (HAS_DEPENDENTS, the consumers' can_detach) are side-effect free.
[[nodiscard]] core::result<void> unload(
module_id id);unload_all¶
unload_all¶void unload_all();Unloads every LOADED module in reverse load order without the can_detach pre-check (consumers detach as under REMOVE_INSTANCES). Called by the destructor.
Private¶
apply_one¶
apply_one¶void apply_one(
const pending_operation &operation);check_sync_point¶
check_sync_point¶[[nodiscard]] bool check_sync_point(
const char *operation) const;checked_record¶
checked_record¶[[nodiscard]] core::result<module_record *> checked_record(
module_id id);close_binary¶
close_binary¶void close_binary(
module_record &record);collect_reload_cascade¶
collect_reload_cascade¶void collect_reload_cascade(
module_record &record,
std::vector<module_id> &cascade) const;detach_record¶
detach_record¶void detach_record(
module_record &record,
bool reloading,
reload_context *snapshot);enqueue¶
enqueue¶void enqueue(
pending_operation operation);fail_record¶
fail_record¶void fail_record(
module_record &record,
core::error failure);failed_dependency_of¶
failed_dependency_of¶[[nodiscard]] const module_record *failed_dependency_of(
const module_record &record) const noexcept;link_dependencies¶
link_dependencies¶void link_dependencies(
module_record &record);load_one¶
load_one¶[[nodiscard]] core::result<void> load_one(
module_record &record);load_resolved¶
load_resolved¶[[nodiscard]] core::result<void> load_resolved(
const std::vector<module_id> &order,
bool stopAtFailure);precheck_unload¶
precheck_unload¶[[nodiscard]] core::result<void> precheck_unload(
module_record &record,
unload_policy policy);register_manifest¶
register_manifest¶[[nodiscard]] core::result<module_id> register_manifest(
module_manifest manifest,
const std::filesystem::path &rootDirectory,
const static_module_desc *staticDesc);reload_full¶
reload_full¶[[nodiscard]] core::result<void> reload_full(
const std::vector<module_id> &cascade);reload_managed¶
reload_managed¶[[nodiscard]] core::result<void> reload_managed(
const std::vector<module_id> &cascade);unlink_dependencies¶
unlink_dependencies¶void unlink_dependencies(
module_record &record);unload_checked¶
unload_checked¶[[nodiscard]] core::result<void> unload_checked(
module_record &record);