Raxol.Core.Runtime.Plugins.LifecycleHelper (Raxol v0.2.0)

View Source

Handles plugin lifecycle operations (loading, unloading, reloading) for the Plugin Manager.

Summary

Functions

Checks if all dependencies for a plugin are met by the currently loaded plugins. Returns :ok or {:error, :missing_dependencies, missing_list}.

Discovers, sorts, and loads all plugins from the default directory.

Loads plugin configuration (placeholder).

Sorts a list of plugin modules based on their declared dependencies.

Functions

check_dependencies(plugin_id, metadata, loaded_plugins_map)

Checks if all dependencies for a plugin are met by the currently loaded plugins. Returns :ok or {:error, :missing_dependencies, missing_list}.

find_plugin_id_by_module(plugins, module)

initialize_plugins(plugins, metadata, plugin_states, load_order, command_table, plugin_config)

Discovers, sorts, and loads all plugins from the default directory.

Accepts the initial Manager state maps and returns the updated maps (including plugin_paths) after loading, or an error tuple if discovery, sorting, or loading fails.

Returns {:ok, %{...updated_maps..., plugin_paths: map()}} | {:error, reason}

load_plugin(plugin_id_or_module, config, plugins, metadata, plugin_states, load_order, command_table, plugin_config)

Loads a plugin by its ID (string) or module (atom).

Accepts the current plugin state maps and config, returns updated maps or an error. Returns {:ok, %{plugins: map(), metadata: map(), plugin_states: map(), load_order: list(), plugin_config: map()}} | {:error, reason}.

load_plugin_config()

Loads plugin configuration (placeholder).

reload_plugin_from_disk(plugin_id, plugins, metadata, plugin_states, load_order, command_table, plugin_config, plugin_paths)

Reloads a plugin identified by its ID.

Handles unloading and then loading again, potentially with code reloading. Accepts the current plugin state maps and config, returns updated maps or an error. Requires the plugin_paths map to find the source file. Returns {:ok, %{...updated_maps...}} | {:error, reason}.

sort_plugins(plugins_with_metadata)

Sorts a list of plugin modules based on their declared dependencies.

Accepts a list of {plugin_module, plugin_metadata} tuples. Returns {:ok, sorted_plugin_modules} or {:error, :circular_dependency, cycle}. Uses a topological sort algorithm.

unload_plugin(plugin_id, plugins, metadata, plugin_states, load_order, command_table)

Unloads a plugin identified by its ID.

Accepts the current plugin state maps, returns updated maps or an error. Returns {:ok, %{plugins: map(), metadata: map(), plugin_states: map(), load_order: list()}} | {:error, reason}.