Ejemplo n.º 1
0
void PluginManager::LoadAll() {
  m_enabled_plugins.clear();

  // The first pass populates the m_plugin map, and builds a list of enabled
  // plugins.
  vector<PluginLoader*>::iterator iter;
  for (iter = m_plugin_loaders.begin(); iter != m_plugin_loaders.end();
       ++iter) {
    (*iter)->SetPluginAdaptor(m_plugin_adaptor);
    vector<AbstractPlugin*> plugins = (*iter)->LoadPlugins();

    vector<AbstractPlugin*>::iterator plugin_iter = plugins.begin();
    for (; plugin_iter != plugins.end(); ++plugin_iter) {
      AbstractPlugin *plugin = *plugin_iter;
      if (!STLInsertIfNotPresent(&m_loaded_plugins, plugin->Id(), plugin)) {
        OLA_WARN << "Skipping plugin " << plugin->Name()
                 << " because it's already been loaded";
        delete plugin;
        continue;
      }

      if (!plugin->LoadPreferences()) {
        OLA_WARN << "Failed to load preferences for " << plugin->Name();
        continue;
      }

      if (!plugin->IsEnabled()) {
        OLA_INFO << "Skipping " << plugin->Name() << " because it was disabled";
        continue;
      }
      STLInsertIfNotPresent(&m_enabled_plugins, plugin->Id(), plugin);
    }
  }

  // The second pass checks for conflicts and starts each plugin
  PluginMap::iterator plugin_iter = m_enabled_plugins.begin();
  for (; plugin_iter != m_enabled_plugins.end(); ++plugin_iter) {
    StartIfSafe(plugin_iter->second);
  }
}
Ejemplo n.º 2
0
void PluginManager::LoadAll() {
  vector<AbstractPlugin*> enabled_plugins;
  set<ola_plugin_id> enabled_plugin_ids;

  // The first pass populates the m_plugin map, and builds a list of enabled
  // plugins.
  vector<PluginLoader*>::iterator iter;
  for (iter = m_plugin_loaders.begin(); iter != m_plugin_loaders.end();
       ++iter) {
    (*iter)->SetPluginAdaptor(m_plugin_adaptor);
    vector<AbstractPlugin*> plugins = (*iter)->LoadPlugins();

    vector<AbstractPlugin*>::iterator plugin_iter = plugins.begin();
    for (; plugin_iter != plugins.end(); ++plugin_iter) {
      AbstractPlugin *plugin = *plugin_iter;
      if (!STLInsertIfNotPresent(&m_loaded_plugins, plugin->Id(), plugin)) {
        OLA_WARN << "Skipping plugin " << plugin->Name()
                 << " because it's already been loaded";
        continue;
      }

      if (!plugin->LoadPreferences()) {
        OLA_WARN << "Failed to load preferences for " << plugin->Name();
        continue;
      }

      if (!plugin->IsEnabled()) {
        OLA_INFO << "Skipping " << plugin->Name() << " because it was disabled";
        continue;
      }
      enabled_plugins.push_back(plugin);
      enabled_plugin_ids.insert(plugin->Id());
    }
  }

  // The second pass checks for conflicts and starts each plugin
  vector<AbstractPlugin*>::iterator plugin_iter = enabled_plugins.begin();
  for (; plugin_iter != enabled_plugins.end(); ++plugin_iter) {
    AbstractPlugin *plugin = *plugin_iter;

    // check for conflicts
    bool conflict = false;
    set<ola_plugin_id> conflict_list;
    plugin->ConflictsWith(&conflict_list);
    set<ola_plugin_id>::const_iterator set_iter = conflict_list.begin();
    for (; set_iter != conflict_list.end(); ++set_iter) {
      if (STLContains(enabled_plugin_ids, *set_iter)) {
        OLA_WARN << "Skipping " << plugin->Name() <<
          " because it conflicts with " << GetPlugin(*set_iter)->Name() <<
          " which is also enabled";
        conflict = true;
        break;
      }
    }

    if (conflict)
      continue;

    OLA_INFO << "Trying to start " << plugin->Name();
    if (!plugin->Start())
      OLA_WARN << "Failed to start " << plugin->Name();
    else
      OLA_INFO << "Started " << plugin->Name();
    STLReplace(&m_active_plugins, plugin->Id(), plugin);
  }
}