Logo Search packages:      
Sourcecode: packagesearch version File versions

vector< PluginManager::PluginData > NPlugin::PluginManager::getAvailablePlugins (  )  [protected]

This returns all plugins currently available.

These are plugins that are in the plugin directories and plugins which are loaded but not longer in any directory.

Definition at line 107 of file pluginmanager.cpp.

References _directories, _loadedPlugins, checkDlError(), NPlugin::PluginManager::PluginData::directory, and NPlugin::PluginManager::PluginData::information.

Referenced by loadPlugins(), and showControlDialog().

{
      typedef PluginContainer* (*NewPluginFkt)();
      typedef PluginInformation (*GetPluginDataFkt)();
      vector<PluginData> informations;
      for (vector<string>::const_iterator it = _directories.begin(); it != _directories.end(); ++it)
      {
            const string& directory = *it;
            dlerror();  // clear error messages
            QDir pluginDir(toQString(directory), "lib*.so");      // only care for library files
            QStringList pluginFiles = pluginDir.entryList(QDir::Files);
            // try to load the library and fetch the creator function for each file 
            // in the current directory, if both is possible the plugin is available
            for (QStringList::iterator jt = pluginFiles.begin(); jt != pluginFiles.end(); ++jt)
            {

                  PluginData pluginData;
                  string libraryFile = toString(*jt);
                  void* libraryHandle = dlopen((directory + libraryFile).c_str(), RTLD_NOW);
                  checkDlError();
                  if (libraryHandle)      // loading was possible
                  {
                        string pluginName = libraryFile.substr(3,libraryFile.length() - 6);     // remove "lib" and ".so"
                        // fetch the creator function
                        NewPluginFkt func = NewPluginFkt(dlsym( libraryHandle, ("new_" + pluginName).c_str() ));
                        if (func != 0)    // if the function could be received we have a valid plugin
                        {
                              pluginData.directory = directory;
                              GetPluginDataFkt getInformation = GetPluginDataFkt(dlsym(libraryHandle, "get_pluginInformation"));
                              if (getInformation != 0)
                                    pluginData.information = getInformation();
                              informations.push_back(pluginData);
                        }
                        dlclose(libraryHandle); // close the library again
                  }
            }
            dlerror();  // dismiss possible error messages
      }
      // iterate through the loaded plugins and add the their load information to the 
      // available plugins, if there is no matching plugin found collect the plugins
      // in newPlugins and append to the availables
      {
            vector<PluginData> newPlugins;
            for (map<PluginContainer*, PluginData>::const_iterator it = _loadedPlugins.begin();
                  it != _loadedPlugins.end(); ++it )
            {
                  // find the loaded plugin in the available ones
                  vector<PluginData>::iterator jt = informations.begin();
                  jt = find_if( jt, informations.end(), PluginEquals(it->second) );
                  if ( jt == informations.end())      // if the plugin was not found
                  {
                        newPlugins.push_back(it->second);
                  }
                  else
                  {
                        (*jt) = it->second;     // copy the information from the loaded plugin
                  }
            }
            informations.insert(informations.end(), newPlugins.begin(), newPlugins.end());
      }
      return informations;
}


Generated by  Doxygen 1.6.0   Back to index