Пример #1
0
  void RuntimeSystem::addModule(const std::string& moduleClassName,
				int moduleID)
  {
    IModule* newModule = moduleFactory.buildNewModule(moduleClassName,
						      typeFactory);
    newModule->setID(moduleID);
		
    ModuleControlBlockPtr newBlock ( new ModuleControlBlock(newModule) );
		
    m_modules[moduleID] = newBlock;
    
    // no output or notdeterministic => module is a sink
    if (( newModule->getOutputs().size() == 0 ) ||
	( !newModule->isDeterministic()) ) 
      m_sinks.push_front(newBlock);
    
#if (ENGINE_VERBOSITY > 0)
    std::cout << "Added new Module (id " << moduleID << ") of Class " 
	      << moduleClassName << std::endl;
#endif
  }
Пример #2
0
  void RuntimeSystem::deleteModule(int moduleID)
  {
    // get the control block for the moduleid
    ControlBlockMap::iterator it = m_modules.find(moduleID);
    
    if (it == m_modules.end())
      {
	// a module with that id doesnt exist
	throw std::runtime_error("Module does not exist at "
				 "RuntimeSystem::deleteModule()");
      }

    // a module with that id must exist
    assert(it != m_modules.end());

    ModuleControlBlockPtr block = it->second;  
    IModule* n = block->module();

    // disconnect all modules that are connected to an output
    for (ControlBlockMap::iterator i = m_modules.begin(); 
	 i != m_modules.end(); ++i)
      {
	// is this possible?
	// if (i->second == 0) continue;
	assert(i->second != 0);

	ModuleControlBlockPtr block = i->second;
	IModule* m = block->module();	

	// check all inputs of that module
	for (unsigned int j = 0; j < m->getInputs().size(); ++j)
	  {
	    IModule::IInputPtr in = m->getInputs()[j];

	    // is it connected?
	    if (in->getConnectedModule() == n) 
	      {
		// yes, the unplug it
		in->unPlug();
		// and signal change
		block->hasChanged(j);
	      }
	  }
      }

    // disconnect all modules that are connected to an input
    for (unsigned int j = 0; j < n->getInputs().size(); ++j)
      {
	IModule::IInputPtr in = n->getInputs()[j];

	if (in->getConnectedModule() != 0)
	  in->unPlug();
      }
		
    // remove the module from the sink list	  

    if (n->getOutputs().size() == 0 || !n->isDeterministic())
	m_sinks.remove(block);

    // remove it from the module set
    // the module control block should be deleted here by its autoptr
    m_modules.erase(it);
		
#if (ENGINE_VERBOSITY > 0)
    std::cout << "Deleted Module # " << moduleID << std::endl;
#endif
  }