Ejemplo n.º 1
0
		IPlugin* load(const char* path) override
		{
			g_log_info.log("plugins") << "loading plugin " << path;
			typedef IPlugin* (*PluginCreator)(Engine&);

			auto* lib = loadLibrary(path);
			if (lib)
			{
				PluginCreator creator = (PluginCreator)getLibrarySymbol(lib, "createPlugin");
				if (creator)
				{
					IPlugin* plugin = creator(m_engine);
					if (!plugin || !plugin->create())
					{
						LUMIX_DELETE(m_engine.getAllocator(), plugin);
						ASSERT(false);
						return nullptr;
					}
					m_plugins.push(plugin);
					m_libraries.push(lib);
					m_library_loaded.invoke(lib);
					g_log_info.log("plugins") << "plugin loaded";
					return plugin;
				}
			}
			unloadLibrary(lib);
			return 0;
		}
Ejemplo n.º 2
0
		IPlugin* load(const char* path) override
		{
			char path_with_ext[MAX_PATH_LENGTH];
			copyString(path_with_ext, path);
			const char* ext =
			#ifdef _WIN32
				".dll";
			#elif defined __linux__
				".so";
			#else 
				#error Unknown platform
			#endif
			if (!PathUtils::hasExtension(path, ext + 1)) catString(path_with_ext, ext);
			g_log_info.log("Core") << "loading plugin " << path_with_ext;
			typedef IPlugin* (*PluginCreator)(Engine&);
			auto* lib = loadLibrary(path_with_ext);
			if (lib)
			{
				PluginCreator creator = (PluginCreator)getLibrarySymbol(lib, "createPlugin");
				if (creator)
				{
					IPlugin* plugin = creator(m_engine);
					if (!plugin)
					{
						g_log_error.log("Core") << "createPlugin failed.";
						LUMIX_DELETE(m_engine.getAllocator(), plugin);
						ASSERT(false);
					}
					else
					{
						addPlugin(plugin);
						m_libraries.push(lib);
						m_library_loaded.invoke(lib);
						g_log_info.log("Core") << "Plugin loaded.";
						Debug::StackTree::refreshModuleList();
						return plugin;
					}
				}
				else
				{
					g_log_error.log("Core") << "No createPlugin function in plugin.";
				}
				unloadLibrary(lib);
			}
			else
			{
				auto* plugin = StaticPluginRegister::create(path, m_engine);
				if (plugin)
				{
					g_log_info.log("Core") << "Plugin loaded.";
					addPlugin(plugin);
					return plugin;
				}
				g_log_warning.log("Core") << "Failed to load plugin.";
			}
			return nullptr;
		}
Ejemplo n.º 3
0
void PionPlugin::openPlugin(const std::string& plugin_file,
							PionPluginData& plugin_data)
{
	// get the name of the plugin (for create/destroy symbol names)
	plugin_data.m_plugin_name = getPluginName(plugin_file);
	
	// attempt to open the plugin; note that this tries all search paths
	// and also tries a variety of platform-specific extensions
	plugin_data.m_lib_handle = loadDynamicLibrary(plugin_file.c_str());
	if (plugin_data.m_lib_handle == NULL) {
#ifndef PION_WIN32
		char *error_msg = dlerror();
		if (error_msg != NULL) {
			std::string error_str(plugin_file);
			error_str += " (";
			error_str += error_msg;
			error_str += ')';
			throw OpenPluginException(error_str);
		} else
#endif
		throw OpenPluginException(plugin_file);
	}
	
	// find the function used to create new plugin objects
	plugin_data.m_create_func =
		getLibrarySymbol(plugin_data.m_lib_handle,
						 PION_PLUGIN_CREATE + plugin_data.m_plugin_name);
	if (plugin_data.m_create_func == NULL) {
		closeDynamicLibrary(plugin_data.m_lib_handle);
		throw PluginMissingCreateException(plugin_file);
	}

	// find the function used to destroy existing plugin objects
	plugin_data.m_destroy_func =
		getLibrarySymbol(plugin_data.m_lib_handle,
						 PION_PLUGIN_DESTROY + plugin_data.m_plugin_name);
	if (plugin_data.m_destroy_func == NULL) {
		closeDynamicLibrary(plugin_data.m_lib_handle);
		throw PluginMissingDestroyException(plugin_file);
	}
}