Skip to content

Engine → Modules → module_manager.h

module_manager

Syntax

class CONJURE_API module_manager

Constructors

AccessSignatureDescription
publicmodule_manager( const module_manager_desc &desc, core::event_bus &events);

Important

Copy constructor and assignment has been deleted.

Destructors

AccessSignatureDescription
public~module_manager();

Variables

AccessNameTypeDefaultDescription
privatemConsumersstd::vector<module_consumer *>{}
privatemDescmodule_manager_desc{}
privatemEventscore::event_bus *nullptr
privatemHasPendingstd::atomic<bool>false
privatemNextLoadOrderu321
privatemPendingstd::vector<pending_operation>{}
privatemRegistrymodule_registry{}
privatemServicesservice_table{}
privatemShadowInstancestd::unique_ptr<detail::shadow_cache_instance>{}

Functions

Public

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

[[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

[[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

[[nodiscard]] bool any_loaded() const noexcept;

True while at least one module is LOADED.

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

[[nodiscard]] const module_manager_desc &desc() const noexcept;

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

[[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

[[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

[[nodiscard]] core::result<void> load_all();

Resolves every registered module and loads them in order, continuing past failures. Returns the first error.

pending_count

[[nodiscard]] usize pending_count() const noexcept;

Number of requests waiting for apply_pending().

provide_service

template <typename ServiceType> void provide_service(
    ServiceType &service);

Provides a host service to module contexts. Asserts when a module is LOADED.

registry

[[nodiscard]] const module_registry &registry() const noexcept;
[[nodiscard]] module_registry &registry() noexcept;

Mutable registry for consumers recording ownership in attach().

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

void remove_consumer(
    module_consumer &consumer);

Removes a consumer. Asserts when a module is LOADED.

request_load

void request_load(
    module_id id);

request_reload

void request_reload(
    module_id id,
    reload_scope scope);

request_unload

void request_unload(
    module_id id,
    unload_policy policy);

services

[[nodiscard]] const service_table &services() const noexcept;

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

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

void apply_one(
    const pending_operation &operation);

check_sync_point

[[nodiscard]] bool check_sync_point(
    const char *operation) const;

checked_record

[[nodiscard]] core::result<module_record *> checked_record(
    module_id id);

close_binary

void close_binary(
    module_record &record);

collect_reload_cascade

void collect_reload_cascade(
    module_record &record,
    std::vector<module_id> &cascade) const;

detach_record

void detach_record(
    module_record &record,
    bool reloading,
    reload_context *snapshot);

enqueue

void enqueue(
    pending_operation operation);

fail_record

void fail_record(
    module_record &record,
    core::error failure);

failed_dependency_of

[[nodiscard]] const module_record *failed_dependency_of(
    const module_record &record) const noexcept;

load_one

[[nodiscard]] core::result<void> load_one(
    module_record &record);

load_resolved

[[nodiscard]] core::result<void> load_resolved(
    const std::vector<module_id> &order,
    bool stopAtFailure);

precheck_unload

[[nodiscard]] core::result<void> precheck_unload(
    module_record &record,
    unload_policy policy);

register_manifest

[[nodiscard]] core::result<module_id> register_manifest(
    module_manifest manifest,
    const std::filesystem::path &rootDirectory,
    const static_module_desc *staticDesc);

reload_full

[[nodiscard]] core::result<void> reload_full(
    const std::vector<module_id> &cascade);

reload_managed

[[nodiscard]] core::result<void> reload_managed(
    const std::vector<module_id> &cascade);

unload_checked

[[nodiscard]] core::result<void> unload_checked(
    module_record &record);