/* * Return the state for a plugin. */ void OlaServerServiceImpl::GetPluginState( RpcController* controller, const ola::proto::PluginStateRequest* request, ola::proto::PluginStateReply* response, ola::rpc::RpcService::CompletionCallback* done) { ClosureRunner runner(done); ola_plugin_id plugin_id = (ola_plugin_id) request->plugin_id(); AbstractPlugin *plugin = m_plugin_manager->GetPlugin(plugin_id); if (plugin) { response->set_name(plugin->Name()); response->set_enabled(plugin->IsEnabled()); response->set_active(m_plugin_manager->IsActive(plugin_id)); response->set_preferences_source(plugin->PreferenceSource()); vector<AbstractPlugin*> conflict_list; m_plugin_manager->GetConflictList(plugin_id, &conflict_list); vector<AbstractPlugin*>::const_iterator iter = conflict_list.begin(); for (; iter != conflict_list.end(); ++iter) { PluginInfo *plugin_info = response->add_conflicts_with(); AddPlugin(*iter, plugin_info); } } else { controller->SetFailed("Plugin not loaded"); } }
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); } }
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); } }