PeasEngine: Peas Reference Manual

## PeasEngine PeasEngine — Engine at the heart of the Peas plugin system. |

## Functions

PeasEngine * | peas_engine_new ()
PeasEngine * | peas_engine_new_with_nonglobal_loaders ()
PeasEngine * | peas_engine_get_default ()
void | peas_engine_add_search_path ()
void | peas_engine_prepend_search_path ()
void | peas_engine_enable_loader ()
void | peas_engine_rescan_plugins ()
const GList * | peas_engine_get_plugin_list ()
gchar ** | peas_engine_get_loaded_plugins ()
void | peas_engine_set_loaded_plugins ()
PeasPluginInfo * | peas_engine_get_plugin_info ()
gboolean | peas_engine_load_plugin ()
gboolean | peas_engine_unload_plugin ()
void | peas_engine_garbage_collect ()
gboolean | peas_engine_provides_extension ()
PeasExtension * | peas_engine_create_extension ()
PeasExtension * | peas_engine_create_extensionv ()
PeasExtension * | peas_engine_create_extension_valist ()

## Properties

GStrv | loaded-plugins | Read / Write
gboolean | nonglobal-loaders | Read / Write / Construct Only
gpointer | plugin-list | Read

## Signals

void | load-plugin | Run Last
void | unload-plugin | Run Last

## Types and Values

struct | PeasEngine
struct | PeasEngineClass

## Object Hierarchy

        GObject
        ╰── PeasEngine

## Description

The PeasEngine is the object which manages the plugins.

Its role is twofold:

- it will fetch all the information about the available plugins from all the registered plugin directories;

- it will provide you an API to load, control and unload your plugins and their extensions from within your application.

## Functions

### peas_engine_new ()

    PeasEngine *
    peas_engine_new (void);

Return a new instance of PeasEngine. If no default PeasEngine has been instantiated yet, the first call of this function will set the default engine as the new instance of PeasEngine.

#### Returns

a new instance of PeasEngine.

### peas_engine_new_with_nonglobal_loaders ()

    PeasEngine *
    peas_engine_new_with_nonglobal_loaders
                                   (void);

Return a new instance of PeasEngine which will use non-global plugin loaders instead of the default global ones. This allows multiple threads to each have a PeasEngine and be used without internal locking.

Note: due to CPython's GIL the python and python3 plugin loaders are always global.

#### Returns

a new instance of PeasEngine that uses non-global loaders.

Since: 1.14

### peas_engine_get_default ()

    PeasEngine *
    peas_engine_get_default (void);

Return the existing instance of PeasEngine or a subclass of it. If no PeasEngine subclass has been instantiated yet, the first call of this function will return a new instance of PeasEngine.

Note: this function should never be used when multiple threads are using libpeas API as it is not thread-safe.

#### Returns

the existing instance of PeasEngine.

[transfer none]

### peas_engine_add_search_path ()

    void
    peas_engine_add_search_path (PeasEngine *engine,
                                 const gchar *module_dir,
                                 const gchar *data_dir);

This function appends a search path to the list of paths where to look for plugins.

A so-called "search path" actually consists of both a module directory (where the shared libraries or language modules lie) and a data directory (where the plugin data is).

The plugin will be able to use a correct data dir depending on where it is installed, hence allowing to keep the plugin agnostic when it comes to installation location: the same plugin can be installed either in the system path or in the user's home directory, without taking other special care than using `peas_plugin_info_get_data_dir()` when looking for its data files.

If `data_dir` is `NULL`, then it is set to the same value as `module_dir` .

#### Parameters

engine | A PeasEngine. |
module_dir | the plugin module directory. |
data_dir | the plugin data directory. | [allow-none]

### peas_engine_prepend_search_path ()

    void
    peas_engine_prepend_search_path (PeasEngine *engine,
                                     const gchar *module_dir,
                                     const gchar *data_dir);

This function prepends a search path to the list of paths where to look for plugins.

See Also: `peas_engine_add_search_path()`

#### Parameters

engine | A PeasEngine. |
module_dir | the plugin module directory. |
data_dir | the plugin data directory. | [allow-none]

Since: 1.6

### peas_engine_enable_loader ()

    void
    peas_engine_enable_loader (PeasEngine *engine,
                               const gchar *loader_name);

Enable a loader, enables a loader for plugins. The C plugin loader is always enabled. The other plugin loaders are: lua5.1 and python and python3.

For instance, the following code will enable python plugins to be loaded:

    1
    peas_engine_enable_loader (engine, "python");

Note: plugin loaders used to be shared across PeasEngines so enabling a loader on one PeasEngine would enable it on all PeasEngines. This behavior has been kept to avoid breaking applications, however a warning has been added to help applications transition.

#### Parameters

engine | A PeasEngine. |
loader_name | The name of the loader to enable. |

### peas_engine_rescan_plugins ()

    void
    peas_engine_rescan_plugins (PeasEngine *engine);

Rescan all the registered directories to find new or updated plugins.

Calling this function will make the newly installed plugin infos be loaded by the engine, so the new plugins can be used without restarting the application.

#### Parameters

engine | A PeasEngine. |

### peas_engine_get_plugin_list ()

    const GList *
    peas_engine_get_plugin_list (PeasEngine *engine);

Returns the list of PeasPluginInfo known to the engine.

#### Parameters

engine | A PeasEngine. |

#### Returns

a GList of PeasPluginInfo. Note that the list belongs to the engine and should not be freed.

[transfer none][element-type Peas.PluginInfo]

### peas_engine_get_loaded_plugins ()

    gchar **
    peas_engine_get_loaded_plugins (PeasEngine *engine);

Returns the list of the names of all the loaded plugins, or an array containing a single `NULL` element if there is no plugin currently loaded.

Please note that the returned array is a newly allocated one: you will need to free it using `g_strfreev()`.

#### Parameters

engine | A PeasEngine. |

#### Returns

A newly-allocated `NULL`-terminated array of strings.

[transfer full][array zero-terminated=1]

### peas_engine_set_loaded_plugins ()

    void
    peas_engine_set_loaded_plugins (PeasEngine *engine,
                                    const gchar **plugin_names);

Sets the list of loaded plugins for `engine` . When this function is called, the PeasEngine will load all the plugins whose names are in `plugin_names` , and ensures all other active plugins are unloaded.

If `plugin_names` is `NULL`, all plugins will be unloaded.

#### Parameters

engine | A PeasEngine. |
plugin_names | A `NULL`-terminated array of plugin names, or `NULL`. | [allow-none][array zero-terminated=1]

### peas_engine_get_plugin_info ()

    PeasPluginInfo *
    peas_engine_get_plugin_info (PeasEngine *engine,
                                 const gchar *plugin_name);

Gets the PeasPluginInfo corresponding with `plugin_name` , or `NULL` if `plugin_name` was not found.

#### Parameters

engine | A PeasEngine. |
plugin_name | A plugin name. |

#### Returns

the PeasPluginInfo corresponding with a given plugin module name.

[transfer none]

### peas_engine_load_plugin ()

    gboolean
    peas_engine_load_plugin (PeasEngine *engine,
                             PeasPluginInfo *info);

Loads the plugin corresponding to `info` if it's not currently loaded. Emits the "load-plugin" signal; loading the plugin actually occurs in the default signal handler.

[virtual load_plugin]

#### Parameters

engine | A PeasEngine. |
info | A PeasPluginInfo. |

#### Returns

whether the plugin has been successfully loaded.

### peas_engine_unload_plugin ()

    gboolean
    peas_engine_unload_plugin (PeasEngine *engine,
                               PeasPluginInfo *info);

Unloads the plugin corresponding to `info` . Emits the "unload-plugin" signal; unloading the plugin actually occurs in the default signal handler.

[virtual unload_plugin]

#### Parameters

engine | A PeasEngine. |
info | A PeasPluginInfo. |

#### Returns

whether the plugin has been successfully unloaded.

### peas_engine_garbage_collect ()

    void
    peas_engine_garbage_collect (PeasEngine *engine);

This function triggers garbage collection on all the loaders currently owned by the PeasEngine. This can be used to force the loaders to destroy managed objects that still hold references to objects that are about to disappear.

#### Parameters

engine | A PeasEngine. |

### peas_engine_provides_extension ()

    gboolean
    peas_engine_provides_extension (PeasEngine *engine,
                                    PeasPluginInfo *info,
                                    GType extension_type);

Returns if `info` provides an extension for `extension_type` . If the `info` is not loaded than `FALSE` will always be returned.

#### Parameters

engine | A PeasEngine. |
info | A PeasPluginInfo. |
extension_type | The extension GType. |

#### Returns

if `info` provides an extension for `extension_type` .

### peas_engine_create_extension ()

    PeasExtension *
    peas_engine_create_extension (PeasEngine *engine,
                                  PeasPluginInfo *info,
                                  GType extension_type,
                                  const gchar *first_property,
                                  ...);

If the plugin identified by `info` implements the `extension_type` interface, then this function will return a new instance of this implementation, wrapped in a new PeasExtension instance. Otherwise, it will return `NULL`.

When creating the new instance of the `extension_type` subtype, the provided construct properties will be passed to the extension construction handler (exactly like if you had called `g_object_new()` yourself).

The new extension instance produced by this function will always be returned wrapped in a PeasExtension proxy, following the current libpeas principle of never giving you the actual object (also because it might as well *not* be an actual object).

[skip]

#### Parameters

engine | A PeasEngine. |
info | A loaded PeasPluginInfo. |
extension_type | The implemented extension GType. |
first_property | the name of the first property. |
... | the value of the first property, followed optionally by more name/value pairs, followed by `NULL`. |

#### Returns

a new instance of PeasExtension wrapping the `extension_type` instance, or `NULL`.

### peas_engine_create_extensionv ()

    PeasExtension *
    peas_engine_create_extensionv (PeasEngine *engine,
                                   PeasPluginInfo *info,
                                   GType extension_type,
                                   guint n_parameters,
                                   GParameter *parameters);

If the plugin identified by `info` implements the `extension_type` interface, then this function will return a new instance of this implementation, wrapped in a new PeasExtension instance. Otherwise, it will return `NULL`.

See `peas_engine_create_extension()` for more information.

[rename-to peas_engine_create_extension]

#### Parameters

engine | A PeasEngine. |
info | A loaded PeasPluginInfo. |
extension_type | The implemented extension GType. |
n_parameters | the length of the `parameters` array. |
parameters | an array of GParameter. | [allow-none][array length=n_parameters]

#### Returns

a new instance of PeasExtension wrapping the `extension_type` instance, or `NULL`.

[transfer full]

### peas_engine_create_extension_valist ()

    PeasExtension *
    peas_engine_create_extension_valist (PeasEngine *engine,
                                         PeasPluginInfo *info,
                                         GType extension_type,
                                         const gchar *first_property,
                                         va_list var_args);

If the plugin identified by `info` implements the `extension_type` interface, then this function will return a new instance of this implementation, wrapped in a new PeasExtension instance. Otherwise, it will return `NULL`.

See `peas_engine_create_extension()` for more information.

[skip]

#### Parameters

engine | A PeasEngine. |
info | A loaded PeasPluginInfo. |
extension_type | The implemented extension GType. |
first_property | the name of the first property. |
var_args | the value of the first property, followed optionally by more name/value pairs, followed by `NULL`. |

#### Returns

a new instance of PeasExtension wrapping the `extension_type` instance, or `NULL`.

## Types and Values

### struct PeasEngine

    struct PeasEngine;

The PeasEngine structure contains only private data and should only be accessed using the provided API.

### struct PeasEngineClass

    struct PeasEngineClass {
      GObjectClass parent_class;

      void     (*load_plugin)                 (PeasEngine     *engine,
                                               PeasPluginInfo *info);

      void     (*unload_plugin)               (PeasEngine     *engine,
                                               PeasPluginInfo *info);
    };

Class structure for PeasEngine.

#### Members

GObjectClass `parent_class`; | The parent class. |
`load_plugin` () | Signal class handler for the “load-plugin” signal. |
`unload_plugin` () | Signal class handler for the “unload-plugin” signal. |

## Property Details

### The `“loaded-plugins”` property

      “loaded-plugins”           GStrv

The list of loaded plugins.

This will be modified when `peas_engine_load_plugin()` or `peas_engine_unload_plugin()` is called.

This can be used with GSettings to save the loaded plugins by binding to this property after instantiating the engine by doing:

    1
    2
    3
    4
    5
    g_settings_bind (gsettings_object,
                     LOADED_PLUGINS_KEY,
                     engine,
                     "loaded-plugins",
                     G_SETTINGS_BIND_DEFAULT);

Note: notify will not be called when the engine is being destroyed.

Flags: Read / Write

### The `“nonglobal-loaders”` property

      “nonglobal-loaders”        gboolean

If non-global plugin loaders should be used.

See `peas_engine_new_with_nonglobal_loaders()` for more information.

Flags: Read / Write / Construct Only

Default value: FALSE

Since: 1.14

### The `“plugin-list”` property

      “plugin-list”              gpointer

The list of found plugins.

This will be modified when `peas_engine_rescan_plugins()` is called.

Note that the list belongs to the engine and should not be modified or freed.

Flags: Read

## Signal Details

### The `“load-plugin”` signal

    void
    user_function (PeasEngine     *engine,
                   PeasPluginInfo *info,
                   gpointer        user_data)

The load-plugin signal is emitted when a plugin is being loaded.

The plugin is being loaded in the default handler. Hence, if you want to perform some action before the plugin is loaded, you should use `g_signal_connect()`, but if you want to perform some action *after* the plugin is loaded (the most common case), you should use `g_signal_connect_after()`.

#### Parameters

engine | A PeasEngine. |
info | A PeasPluginInfo. |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“unload-plugin”` signal

    void
    user_function (PeasEngine     *engine,
                   PeasPluginInfo *info,
                   gpointer        user_data)

The unload-plugin signal is emitted when a plugin is being unloaded.

The plugin is being unloaded in the default handler. Hence, if you want to perform some action before the plugin is unloaded (the most common case), you should use `g_signal_connect()`, but if you want to perform some action after the plugin is unloaded (the most common case), you should use `g_signal_connect_after()`.

#### Parameters

engine | A PeasEngine. |
info | A PeasPluginInfo. |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

## See Also

PeasPluginInfo