예제 #1
0
/**
 * loads a plugin into the server.
 *
 * \see plugin, unload_plugin(), loaded_plugins()
 */
XzeroPlugin *XzeroDaemon::loadPlugin(const std::string& name, std::error_code& ec)
{
    if (!pluginDirectory_.empty() && pluginDirectory_[pluginDirectory_.size() - 1] != '/')
        pluginDirectory_ += "/";

    std::string filename;
    if (name.find('/') != std::string::npos)
        filename = name + ".so";
    else
        filename = pluginDirectory_ + name + ".so";

    std::string plugin_create_name("x0plugin_init");

#if !defined(XZERO_NDEBUG)
    log(Severity::debug, "Loading plugin %s", filename.c_str());
#endif

    Library lib;
    ec = lib.open(filename);
    if (!ec)
    {
        plugin_create_t plugin_create = reinterpret_cast<plugin_create_t>(lib.resolve(plugin_create_name, ec));

        if (!ec)
        {
            XzeroPlugin *plugin = plugin_create(this, name);
            pluginLibraries_[plugin] = std::move(lib);

            return registerPlugin(plugin);
        }
    }

    return nullptr;
}
예제 #2
0
DisplayPlugin *display_plugin_create (const char *path)
{
        DisplayPlugin *display_plugin;

        if (!path) {
                error (InvalidArgument);
                return NULL;
        }
        if (!(display_plugin = memory_create (sizeof (DisplayPlugin)))) {
                error_code (FunctionCall, 1);
                return NULL;
        }
        if (!(display_plugin->plugin = plugin_create (path))) {
                memory_destroy (display_plugin);
                error_code (FunctionCall, 2);
                return NULL;
        }
        if (!(plugin_set_function (display_plugin->plugin, 
                                   (void **)&display_plugin->display_canvas, 
                                   "display_canvas"))) {
                plugin_destroy (display_plugin->plugin);
                memory_destroy (display_plugin);
                error_code (FunctionCall, 3);
                return NULL;
        }
        if (!display_plugin->plugin->load ()) {
                plugin_destroy (display_plugin->plugin);
                memory_destroy (display_plugin);
                error_code (FunctionCall, 4);
                return NULL;
        }
        return display_plugin;
}
예제 #3
0
/* ------------------------------------------------------------------------- */
PLUGIN_MENU_PUBLIC_API PLUGIN_INIT()
{
    struct plugin_t* plugin;

    /* init global data */
    glob_create(game);

    /* init plugin */
    plugin = plugin_create(game,
                           PLUGIN_NAME,
                           PLUGIN_CATEGORY,
                           PLUGIN_AUTHOR,
                           PLUGIN_DESCRIPTION,
                           PLUGIN_WEBSITE
    );
    get_global(game)->plugin = plugin;

    /* set plugin information - Change this in the file "CMakeLists.txt" */
    plugin_set_programming_language(plugin,
            PLUGIN_PROGRAMMING_LANGUAGE_C
    );
    plugin_set_version(plugin,
            PLUGIN_VERSION_MAJOR,
            PLUGIN_VERSION_MINOR,
            PLUGIN_VERSION_PATCH
    );

    register_services(plugin);
    register_events(plugin);

    return plugin;
}
예제 #4
0
파일: plugin.c 프로젝트: tpatki/flux-sched
int sched_plugin_load (struct sched_plugin_loader *sploader, const char *s)
{
    char *path = NULL;
    char *name = NULL;
    char *searchpath = getenv ("FLUX_MODULE_PATH");
    void *dso = NULL;

    if (sploader->plugin) {
        errno = EEXIST;
        goto error;
    }
    if (!searchpath) {
        flux_log (sploader->h, LOG_ERR, "FLUX_MODULE_PATH not set");
        goto error;
    }
    if (strchr (s, '/')) {
        if (!(name = flux_modname (s))) {
            flux_log (sploader->h, LOG_ERR, "%s: %s", s, dlerror ());
            errno = ENOENT;
            goto error;
        }
        if (!(path = strdup (s))) {
            errno = ENOMEM;
            goto error;
        }
    } else {
        if (!(path = flux_modfind (searchpath, s))) {
            flux_log (sploader->h, LOG_ERR,
                      "%s: not found in module search path %s", s, searchpath);
            goto error;
        }
        if (!(name = flux_modname (path)))
            goto error;
    }
    if (!(dso = dlopen (path, RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND))) {
        flux_log (sploader->h, LOG_ERR, "failed to open sched plugin: %s",
                  dlerror ());
        goto error;
    }
    flux_log (sploader->h, LOG_DEBUG, "loaded: %s", name);
    if (!(sploader->plugin = plugin_create (sploader->h, dso))) {
        dlclose (dso);
        goto error;
    }
    sploader->plugin->name = name;
    sploader->plugin->path = path;
    return 0;
error:
    if (path)
        free (path);
    if (name)
        free (name);
    return -1;
}
예제 #5
0
/* ------------------------------------------------------------------------- */
char
plugin_manager_init(struct game_t* game)
{
    /* init game's plugin container - this keeps track of all of the loaded
     * plugins */
    list_init_list(&game->plugins);

    /* init core plugin */
    game->core = plugin_create(game,
            "lightship core",
            "core",
            "TheComet",
            "Provides essential events and services to the game object",
            "https://github.com/TheComet93/lightship"
    );
    if(!game->core)
        return 0;

    return 1;
}