PeasEngine

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

Synopsis

                    PeasEngine;
                    PeasEngineClass;
PeasEngine *        peas_engine_new                     (const gchar *app_name,
                                                         const gchar **search_paths);
void                peas_engine_rescan_plugins          (PeasEngine *engine);
const GList *       peas_engine_get_plugin_list         (PeasEngine *engine);
gchar **            peas_engine_get_loaded_plugins      (PeasEngine *engine);
void                peas_engine_set_loaded_plugins      (PeasEngine *engine,
                                                         const gchar **plugin_names);
PeasPluginInfo *    peas_engine_get_plugin_info         (PeasEngine *engine,
                                                         const gchar *plugin_name);
gboolean            peas_engine_load_plugin             (PeasEngine *engine,
                                                         PeasPluginInfo *info);
gboolean            peas_engine_unload_plugin           (PeasEngine *engine,
                                                         PeasPluginInfo *info);
void                peas_engine_garbage_collect         (PeasEngine *engine);
gboolean            peas_engine_provides_extension      (PeasEngine *engine,
                                                         PeasPluginInfo *info,
                                                         GType extension_type);
PeasExtension *     peas_engine_create_extension        (PeasEngine *engine,
                                                         PeasPluginInfo *info,
                                                         GType extension_type,
                                                         const gchar *first_property,
                                                         ...);
PeasExtension *     peas_engine_create_extensionv       (PeasEngine *engine,
                                                         PeasPluginInfo *info,
                                                         GType extension_type,
                                                         guint n_parameters,
                                                         GParameter *parameters);
PeasExtension *     peas_engine_create_extension_valist (PeasEngine *engine,
                                                         PeasPluginInfo *info,
                                                         GType extension_type,
                                                         const gchar *first_property,
                                                         va_list var_args);
void                peas_engine_disable_loader          (PeasEngine *engine,
                                                         const gchar *loader_id);

Object Hierarchy

  GObject
   +----PeasEngine

Properties

  "app-name"                 gchar*                : Read / Write / Construct Only
  "loaded-plugins"           GStrv*                : Read / Write
  "plugin-list"              gpointer              : Read
  "search-paths"             GStrv*                : Read / Write / Construct Only

Signals

  "load-plugin"                                    : Run Last
  "unload-plugin"                                  : Run Last

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.

Details

PeasEngine

typedef struct _PeasEngine PeasEngine;

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


PeasEngineClass

typedef struct {
  GObjectClass parent_class;

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

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

peas_engine_new ()

PeasEngine *        peas_engine_new                     (const gchar *app_name,
                                                         const gchar **search_paths);

Returns a new PeasEngine object. See the properties description for more information about the parameters.

app_name :

The name of the application. [allow-none]

search_paths :

The paths where to look for plugins

Returns :

a newly created PeasEngine object.

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 to be loaded by the engine, so the new plugins can actually be used without restarting the application.

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.

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().

engine :

A PeasEngine.

Returns :

A newly-allocated NULL-terminated array of strings, or NULL.

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.

engine :

A PeasEngine.

plugin_names :

A NULL-terminated array of plugin names.

peas_engine_get_plugin_info ()

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

engine :

A PeasEngine.

plugin_name :

A plugin name.

Returns :

the PeasPluginInfo corresponding with a given plugin name.

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.

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.

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.

engine :

A PeasEngine.

peas_engine_provides_extension ()

gboolean            peas_engine_provides_extension      (PeasEngine *engine,
                                                         PeasPluginInfo *info,
                                                         GType 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).

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.

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.

Returns :

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

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.

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.

peas_engine_disable_loader ()

void                peas_engine_disable_loader          (PeasEngine *engine,
                                                         const gchar *loader_id);

Disable a loader, avoiding using the plugins written using the related language to be loaded. This method must be called before any plugin relying on the loader loader_id has been loaded.

For instance, the following code will prevent any python plugin from being loaded:

1
peas_engine_disable_loader (engine, "python");

engine :

A PeasEngine.

loader_id :

The id of the loader to inhibit.

Property Details

The "app-name" property

  "app-name"                 gchar*                : Read / Write / Construct Only

The application name. Filename extension and section header for PeasPluginInfo files are actually derived from this value.

For instance, if app-name is "Gedit", then info files will have the .gedit-plugin extension, and the engine will look for a "Gedit Plugin" section in it to load the plugin data.

Default value: "Peas"


The "loaded-plugins" property

  "loaded-plugins"           GStrv*                : Read / Write

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);


The "plugin-list" property

  "plugin-list"              gpointer              : Read

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.


The "search-paths" property

  "search-paths"             GStrv*                : Read / Write / Construct Only

The list of path where to look for plugins.

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

The PeasPlugin 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 both 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.

Concretely, this property contains a NULL-terminated array of strings, whose even-indexed strings are module directories, and odd-indexed ones are the associated data directories. Here is an example of such an array:

1
2
3
4
5
6
7
8
9
gchar const * const search_paths[] = {
        // Plugins in ~/.config
        g_build_filename (g_get_user_config_dir (), "example/plugins", NULL),
        g_build_filename (g_get_user_config_dir (), "example/plugins", NULL),
        // System plugins
        EXAMPLE_PREFIX "/lib/example/plugins/",
        EXAMPLE_PREFIX "/share/example/plugins/",
        NULL
};

Signal Details

The "load-plugin" signal

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

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().

engine :

A PeasEngine.

info :

A PeasPluginInfo.

user_data :

user data set when the signal handler was connected.

The "unload-plugin" signal

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

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().

engine :

A PeasEngine.

info :

A PeasPluginInfo.

user_data :

user data set when the signal handler was connected.

See Also

PeasPluginInfo