/*
 * 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");
  }
}
AbstractListener* Loader::listenerInstance()
{
  if (!isLoaded()){
    qDebug() << "Bad library." << this->errorString() << this->fileName();
    return 0;
  } else {
    QObject* instance = this->instance();
    AbstractPlugin* plugin = qobject_cast<AbstractPlugin*>(instance);
    
    if (instance == 0){
      qDebug() << "Instance nil.";
      return 0;
    } else {
      AbstractListener* listener = plugin->listener();
      
      if (listener == 0){
	qDebug() << "Listener nil.";
	return 0;
      } else {
	return listener;
      }
    }
  }
  
  return 0;
}
/*
 * Load a plugin from a file
 * @param  path  the path to the plugin
 * @returns the plugin or NULL
 */
AbstractPlugin *DlOpenPluginLoader::LoadPlugin(const string &path) {
  lt_dlhandle module = NULL;
  AbstractPlugin *plugin;
  create_t *create;

  OLA_INFO << "Attempting to load " << path;
  module = lt_dlopenext(path.c_str());

  if (!module) {
    OLA_WARN << "failed to lt_dlopen " << path << ": " << lt_dlerror();
    return NULL;
  }

  create = reinterpret_cast<create_t*>(lt_dlsym(module, "create"));

  if (lt_dlerror()) {
    OLA_WARN << "Could not locate create symbol in " << path;
    lt_dlclose(module);
    return NULL;
  }

  // init plugin
  if ((plugin = create(m_plugin_adaptor)) == NULL) {
    lt_dlclose(module);
    return NULL;
  }

  m_plugin_handles.push_back(module);
  OLA_INFO << "Loaded plugin " << plugin->Name();
  return plugin;
}
	void ZonePlugin::removeVehicle( AbstractVehicle* vehicle )
	{
		AbstractPlugin* contentPlugin = getPlugin(0);
		if( contentPlugin != NULL )
		{
			contentPlugin->removeVehicle(vehicle);
		}
	}
void PluginManager::DisableAndStopPlugin(ola_plugin_id plugin_id) {
  AbstractPlugin *plugin = STLFindOrNull(m_loaded_plugins, plugin_id);
  if (!plugin_id) {
    return;
  }

  if (STLRemove(&m_active_plugins, plugin_id)) {
    plugin->Stop();
  }

  if (STLRemove(&m_enabled_plugins, plugin_id)) {
    plugin->SetEnabledState(false);
  }
}
/*
 * Return the description for a plugin.
 */
void OlaServerServiceImpl::GetPluginDescription(
    RpcController* controller,
    const ola::proto::PluginDescriptionRequest* request,
    ola::proto::PluginDescriptionReply* response,
    ola::rpc::RpcService::CompletionCallback* done) {
  ClosureRunner runner(done);
  AbstractPlugin *plugin =
    m_plugin_manager->GetPlugin((ola_plugin_id) request->plugin_id());

  if (plugin) {
    response->set_name(plugin->Name());
    response->set_description(plugin->Description());
  } else {
    controller->SetFailed("Plugin not loaded");
  }
}
bool PluginManager::EnableAndStartPlugin(ola_plugin_id plugin_id) {
  if (STLContains(m_active_plugins, plugin_id)) {
    // Already running, nothing to do.
    return true;
  }

  AbstractPlugin *plugin = STLFindOrNull(m_loaded_plugins, plugin_id);
  if (!plugin) {
    return false;
  }

  if (STLInsertIfNotPresent(&m_enabled_plugins, plugin_id, plugin)) {
    plugin->SetEnabledState(true);
  }

  return StartIfSafe(plugin);
}
	//-----------------------------------------------------------------------------
	void ZonePlugin::redraw (const float currentTime, const float elapsedTime) 
	{ 
		AbstractPlugin* parent = getParentPlugin();
		ZonePlugin* parentZone = dynamic_cast<ZonePlugin*>(parent);
		// the root zone
		if( parentZone == NULL )
		{
			// right now do not call the base class
			// as we want to see the children ...
			BaseClass::redrawChildren( currentTime, elapsedTime );
			if( isVisible() == false )
			{
				return;
			}
			// draw "zone area"
			// zoneUtility(  );
		}
		else
		{
			// draw "zone area"
			if( isVisible() == true )
			{
				zoneUtility(  );
			}
			BaseClass::redraw( currentTime, elapsedTime );
			if( isVisible() == false )
			{
				return;
			}
			// textual annotation
			AbstractPlugin* contentPlugin = getPlugin(0);
			size_t population = 0;
			if( contentPlugin != NULL )
			{
				osAVGroup vehicles = contentPlugin->allVehicles();
				population = vehicles.size();
			}
			std::ostringstream annote;
			annote << std::setprecision (2) << std::setiosflags (std::ios::fixed);
			annote << "Zone: " << getZoneId() << std::endl << "pos(" << position() << ")" << std::endl;
			annote << "Population: " << population << std::endl << std::ends;
			draw2dTextAt3dLocation (annote, position(), gGreen, drawGetWindowWidth(), drawGetWindowHeight());
		}

	}
bool PluginThread::initPlugin()
{
    PluginManager* manager = Carbon::get()->getPluginManager();

    //For new plugins, executable denotes the executable plugin, class mainScript the plugin caption and secondary script the plugin type (as integer)
    AbstractPlugin* plugin = manager->findPlugin(getTaskDefinition().getFirst(), getTaskDefinition().getSecond(),
        getTaskDefinition().getThird().compare("") == 0 ? -1 : getTaskDefinition().getThird().toInt());

    if (plugin == 0)
    {
        LOG_ERROR() << "Could not initialize PluginThread because plugin to start with was not found.";
        mPlugin = 0;
        return false;
    }

    if (plugin->getPluginType() == PT_FRAME)
    {
        LOG_ERROR() << "Could not initialize PluginThread because plugin is of type AttachableFrame. AttachableFrame plugins can only be started in the main thread.";
        mPlugin = 0;
        return false;
    }

    if (plugin->getExecutionType() == AbstractPlugin::ET_NEVER)
    {
        LOG_ERROR() << "Could not initialize PluginThread because the plugin is not executable. It has to have an execution type of ONCE, LOOP or ANY.";
        mPlugin = 0;
        return false;
    }

    mPlugin = plugin;

    if (mPlugin->isQObject())
    {
        //Connect to plugin update functions
        connect(mPlugin->getQObject(), SIGNAL(paused()), this, SLOT(pluginPaused()));
        connect(mPlugin->getQObject(), SIGNAL(running()), this, SLOT(pluginRunning()));
        connect(mPlugin->getQObject(), SIGNAL(finished()), this, SLOT(pluginFinished()));
    }

    return true;
}
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);
  }
}
Exemple #11
0
AbstractPlugin::AbstractPlugin (const AbstractPlugin& p_other) : QObject (p_other.parent()),
    m_ldr (p_other.m_ldr), m_id (p_other.m_id)
{

}
	//-----------------------------------------------------------------------------
	// draw this pedestrian into scene
	void Pedestrian::draw( const float currentTime, const float elapsedTime )
	{
		SLBaseClass::draw( currentTime, elapsedTime );
#if 0
		Color kColor;
		Vec3 kPosition = position();
		bool bGotParentColor = false;
		AbstractPlugin* parentPlugin = dynamic_cast<AbstractPlugin*>(getParentEntity());
		ZonePlugin* zonePlugin = NULL;
		if( NULL != parentPlugin )
		{
			zonePlugin = dynamic_cast<ZonePlugin*>(parentPlugin->getParentPlugin());
			bGotParentColor = parentPlugin->queryVehicleColor( *this, kColor ) ;
			if( true == bGotParentColor )
			{

			}
			else
			{
				if( true == isRemoteObject() )
				{
					kColor = gGreen;
					Vec3 kTempPosition = kPosition;
					kTempPosition.y += 0.05f;
					setPosition( kTempPosition );
				}
				else
				{
					kColor = gRed;
				}
				kColor.setA( 0.5f );
			}
		}

		drawBasic2dCircularVehicle (*this, kColor);
		setPosition( kPosition );
		kColor.setA( 1.0f );
		EAnnotationMode eMode = getAnnotationMode();
		setAnnotationMode( EAnnotationMode_local );
		drawTrail( kColor, gWhite );
		setAnnotationMode( eMode );


		if( NULL != zonePlugin )
		{
			// check for zone memberships
			// textual annotation
			std::ostringstream annote;
			annote << std::setprecision (2) << std::setiosflags (std::ios::fixed);
			annote << "z[";
			for( size_t i = 0; i < 4; ++i )
			{
				if( true == getIsZoneMember(i) )
				{
					annote << i;
				}
				else
				{
					annote << " ";
				}
				if( i < 3 )
				{
					annote << "-";
				}
			}
			annote << "]\n";	

			//draw borders		
			annote << "b[";
			for( size_t i = 0; i < 4; ++i )
			{
				if( true == getIsZoneBorderMember(i) )
				{
					annote << i;
				}
				else
				{
					annote << " ";
				}
				if( i < 3 )
				{
					annote << "-";
				}
			}
			annote << "]";

			draw2dTextAt3dLocation (annote, position(), gWhite, drawGetWindowWidth(), drawGetWindowHeight());
		}
#endif
	}
//-----------------------------------------------------------------------------
// draw this pedestrian into scene
void NetPedestrian::draw( OpenSteer::AbstractRenderer* pRenderer, 
	const float currentTime, const float elapsedTime )
{
	BaseClass::draw( pRenderer, currentTime, elapsedTime );
	Color kColor;
	Vec3 kPosition = this->position();
	bool bGotParentColor = false;
	AbstractPlugin* parentPlugin = dynamic_cast<AbstractPlugin*>(this->getParentEntity());
	ZonePlugin* zonePlugin = NULL;
	if( NULL != parentPlugin )
	{
		zonePlugin = dynamic_cast<ZonePlugin*>(parentPlugin->getParentPlugin());
		bGotParentColor = parentPlugin->queryVehicleColor( *this, kColor ) ;
		if( true == bGotParentColor )
		{

		}
		else
		{
			if( true == this->isRemoteObject() )
			{
				kColor = gGreen;
				Vec3 kTempPosition = kPosition;
				kTempPosition.y += 0.05f;
				this->setPosition( kTempPosition );
			}
			else
			{
				kColor = gRed;
			}
			kColor.setA( 0.5f );
		}
	}

	pRenderer->drawBasic2dCircularVehicle (*this, kColor);
	this->setPosition( kPosition );
	kColor.setA( 1.0f );
	OpenSteer::EAnnotationMode eMode = this->getAnnotationMode();
	this->setAnnotationMode( OpenSteer::EAnnotationMode_local );
	this->drawTrail( pRenderer, kColor, gWhite );
	this->setAnnotationMode( eMode );


	if( NULL != zonePlugin )
	{
		// check for zone memberships
		// textual annotation
		std::ostringstream annote;
		annote << std::setprecision (2) << std::setiosflags (std::ios::fixed);
		annote << "[";
		for( size_t i = 0; i < 4; ++i )
		{
			if( true == this->getIsZoneMember(i) )
			{
				annote << i;
			}
			else
			{
				annote << " ";
			}
			if( i < 3 )
			{
				annote << "-";
			}
		}
		annote << "]";
		pRenderer->draw2dTextAt3dLocation (annote, this->position(), gWhite, 
			pRenderer->drawGetWindowWidth(), pRenderer->drawGetWindowHeight());
	}
}
Exemple #14
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);
  }
}