Logo Search packages:      
Sourcecode: inkscape version File versions

bool Inkscape::Extension::Implementation::Plugin::load ( Inkscape::Extension::Extension module  )  [virtual]

Oh, so someone actually wants to use this plugin! We better go and grab it then!

Parameters:
module Unused except to pass to the plugin's load function.
Returns:
Whether the load was successful. Hopefully always TRUE.
Okay, first things first, are modules supported on this platform? That is a good first check. Also, is this plugin already loaded? If so don't reload it.

If all those are true we need to figure out the filename that needs to be loaded. This involves going through the definition of the plugin for the name field. It is then run though the build_path function to add the .so or .dll on the end. The path that is used is the INKSCAPE_PLUGINDIR.

The module is then loaded into RAM by Glib. I'm sure there is lots of magic involved here -- but we don't have to worry about it, we just check to make sure it worked.

After it is loaded into memory the function lookup table is grabbed and then the load function for the plugin is called.

Reimplemented from Inkscape::Extension::Implementation::Implementation.

Definition at line 61 of file plugin.cpp.

References _module, _symTable, Inkscape::Extension::Extension::get_repr(), inkscape_plugin_function_table::load, Inkscape::Extension::Extension::loaded(), and inkscape_plugin_function_table::version.

{
    if (!Glib::Module::get_supported()) {
        return FALSE;
    }

    if (module->loaded()) {
        return TRUE;
    }

    SPRepr * child_repr = sp_repr_children(module->get_repr());
    const gchar * name = NULL;
    while (child_repr != NULL) {
        if (!strcmp(sp_repr_name(child_repr), "plugin")) {
            child_repr = sp_repr_children(child_repr);
            while (child_repr != NULL) {
                if (!strcmp(sp_repr_name(child_repr), "name")) {
                    name = sp_repr_content(sp_repr_children(child_repr));
                }
                child_repr = sp_repr_next(child_repr);
            }
        }
        child_repr = sp_repr_next(child_repr);
    }

    if (name == NULL) {
        return FALSE;
    }

    std::string path = Glib::Module::build_path(INKSCAPE_PLUGINDIR, name);
    // std::cout << "Load path: " << path << std::endl;
    _module = new Glib::Module(path);

    if (!(bool)_module || _module == NULL) {
        printf("Loading failed\n");
        return FALSE;
    }

    /* Grab symbols */
    void * voidpntr;
    if (!_module->get_symbol(INKSCAPE_PLUGIN_NAME_STR, voidpntr)) {
        // printf("Error loading library\n");
        // std::cout << "Last error: " << _module->get_last_error() << std::endl;
        return FALSE;
    }
    _symTable = (inkscape_plugin_function_table *)voidpntr;

    if (_symTable->version != INKSCAPE_PLUGIN_VERSION) {
        /* Someday this could adapt older versions so that we could
           be compatible -- but not today */
        return FALSE;
    }

    if (_symTable->load != NULL) {
        return (bool)_symTable->load((inkscape_extension *)module);
    }

    return TRUE;
}


Generated by  Doxygen 1.6.0   Back to index