Logo Search packages:      
Sourcecode: packagesearch version File versions

PluginContainer * NPlugin::PluginManager::loadPlugin ( const string &  directory,
const string &  libraryName 
) [protected]

This loads the plugin and informs the plugin users about the loading.

The plugin will be added to the list of loaded plugins.

directory the directory where the plugin is located
libraryName the name of the library (without lib and .so)
a pointer to the plugin loaded, 0 if loading failed
You should have called loadSettings before because else this function will be unloaded.

Definition at line 170 of file pluginmanager.cpp.

References _loadedPlugins, _pluginSettings, _pProvider, checkDlError(), NPlugin::PluginManager::PluginData::directory, NPlugin::PluginManager::PluginData::information, NPlugin::PluginManager::PluginData::libraryHandle, NPlugin::IProvider::pluginUser(), NPlugin::PluginManager::PluginData::pPlugin, and removeFromDisabled().

Referenced by loadPlugins().

      typedef PluginContainer* (*NewPluginFkt)();
      typedef PluginInformation (*GetPluginDataFkt)();
      PluginContainer* pPlugin = 0; // if the plugin could not be loaded 0 will be returned
      PluginData pluginData;
      dlerror();  // dismiss pending errors
      void* libraryHandle = dlopen((directory + "lib" + libraryName + ".so").c_str(), RTLD_LAZY);
      if (!checkDlError())
      {     // no error occured
            string pluginName = libraryName;    // remove "lib" and ".so"
            // get the function for creating the plugin
            NewPluginFkt func = NewPluginFkt(dlsym(libraryHandle, ("new_" + pluginName).c_str() ));
            if (func != 0)    // if no error occured on load (i.e. the symbol was present)
                  pPlugin = func(); // fetch the plugin
                  cout << "Loaded plugin: " << pPlugin->title() <<endl;
                  pluginData.directory = directory;
                  pluginData.libraryHandle = libraryHandle;
                  pluginData.pPlugin = pPlugin;
                  GetPluginDataFkt getInformation = GetPluginDataFkt(
                        dlsym(libraryHandle, "get_pluginInformation"));
                  if (getInformation != 0)
                        pluginData.information = getInformation();
            else  // an error occured
                  if (libraryHandle)
                  dlerror();  // dismiss possible errors
      if (pPlugin)      // if loading was successfull, add the plugin to the map
            // and remove it from the disbled plugins if neccessary
            if (!pPlugin->init(_pProvider))     // if the container failed to initialize
                  // disable plugin to prevent further attemps to load this plugin
                  delete pPlugin;
                  pPlugin = 0;
                  map<string, const QDomElement>::const_iterator it = _pluginSettings.find(pPlugin->name());
                  if ( it != _pluginSettings.end() )
                  _loadedPlugins.insert(make_pair(pPlugin, pluginData));
      return pPlugin;

Generated by  Doxygen 1.6.0   Back to index