void GadgetInstrumentationStreamController::set_parameter(const char* gadgetname, const char* parameter, const char* value)
 {
   Gadget* g = this->find_gadget(gadgetname);
   if (!g) {
     throw std::runtime_error("Unable to find Gadget for setting parameter");
   }
   g->set_parameter(parameter,value,false);
 }
Exemplo n.º 2
0
int GadgetStreamController::configure(std::string config_xml_string)
{

  //Store a copy
  config_xml_ = config_xml_string;
  
  GadgetronXML::GadgetStreamConfiguration cfg;
  try {
    deserialize(config_xml_string.c_str(), cfg);  
  }  catch (const std::runtime_error& e) {
    GERROR("Failed to parse Gadget Stream Configuration: %s\n", e.what());
    return GADGET_FAIL;
  }

  GINFO("Found %d readers\n", cfg.reader.size());
  GINFO("Found %d writers\n", cfg.writer.size());
  GINFO("Found %d gadgets\n", cfg.gadget.size());
  
  //Configuration of readers
  for (std::vector<GadgetronXML::Reader>::iterator i = cfg.reader.begin();
       i != cfg.reader.end();
       ++i) 
    {

      long slot = 0;
      std::string dllname("");
      std::string classname("");

      slot = i->slot;
      dllname = i->dll;
      classname = i->classname;

      GINFO("--Found reader declaration\n");
      GINFO("  Reader dll: %s\n", dllname.c_str());
      GINFO("  Reader class: %s\n", classname.c_str());
      GINFO("  Reader slot: %d\n", slot);

      GadgetMessageReader* r =
	load_dll_component<GadgetMessageReader>(dllname.c_str(),
						classname.c_str());
      
      if (!r) {
	GERROR("Failed to load GadgetMessageReader from DLL\n");
	return GADGET_FAIL;
      }
      
      readers_.insert(slot, r);
      
    }	
  //Configuration of readers end


  //Configuration of writers
  for (std::vector<GadgetronXML::Writer>::iterator i = cfg.writer.begin();
       i != cfg.writer.end();
       ++i) 
    {
      long slot = 0;
      std::string dllname("");
      std::string classname("");
      
      slot = i->slot;
      dllname = i->dll;
      classname = i->classname;

      GINFO("--Found writer declaration\n");
      GINFO("  Writer dll: %s\n", dllname.c_str());
      GINFO("  Writer class: %s\n", classname.c_str());
      GINFO("  Writer slot: %d\n", slot);
      
      GadgetMessageWriter* w =
	load_dll_component<GadgetMessageWriter>(dllname.c_str(),
						classname.c_str());
      
      if (!w) {
	GERROR("Failed to load GadgetMessageWriter from DLL\n");
	return GADGET_FAIL;
      }
      
      writer_task_.register_writer(slot, w);
    }
  //Configuration of writers end

  //Let's configure the stream
  GDEBUG("Processing %d gadgets in reverse order\n",cfg.gadget.size());

  for (std::vector<GadgetronXML::Gadget>::reverse_iterator i = cfg.gadget.rbegin();
       i != cfg.gadget.rend();
       ++i) 
    {
      std::string gadgetname("");
      std::string dllname("");
      std::string classname("");

      gadgetname = i->name;
      dllname = i->dll;
      classname = i->classname;

      GINFO("--Found gadget declaration\n");
      GINFO("  Gadget Name: %s\n", gadgetname.c_str());
      GINFO("  Gadget dll: %s\n", dllname.c_str());
      GINFO("  Gadget class: %s\n", classname.c_str());

      GadgetModule* m = create_gadget_module(dllname.c_str(),
					     classname.c_str(),
					     gadgetname.c_str());
      
      if (!m) {
	GERROR("Failed to create GadgetModule from %s:%s\n",
	       classname.c_str(),
	       dllname.c_str());
	return GADGET_FAIL;
      }
      
      Gadget* g = dynamic_cast<Gadget*>(m->writer());//Get the gadget out of the module
      
      GINFO("  Gadget parameters: %d\n", i->property.size());
      for (std::vector<GadgetronXML::GadgetronParameter>::iterator p = i->property.begin();
	   p != i->property.end();
	   ++p)
	{
	  std::string pname(p->name);
	  std::string pval(p->value);
	  GINFO("Setting parameter %s = %s\n", pname.c_str(),pval.c_str());
	  g->set_parameter(pname.c_str(),pval.c_str(),false);
	}
      
      // set the global gadget parameters for every gadget
      std::map<std::string, std::string>::const_iterator iter;
      for ( iter=global_gadget_parameters_.begin(); iter!=global_gadget_parameters_.end(); iter++ )
        {
	  std::string key = iter->first;
	  std::string value = iter->second;
	  g->set_parameter(key.c_str(), value.c_str(), false);
        }

      if (stream_.push(m) < 0) {
	GERROR("Failed to push Gadget %s onto stream\n", gadgetname.c_str());
	delete m;
	return GADGET_FAIL;
      }
      
    }

  GINFO("Gadget Stream configured\n");
  stream_configured_ = true;

  return GADGET_OK;
}