Ejemplo n.º 1
0
void fast::GlobalInit()
{
	Codecs::XMLTemplateParser parser;
	std::ifstream ifs;
	ifs.open("template.2.08.xml", std::ifstream::in);
	G_TEMPLATE = parser.parse(ifs);
	ifs.close();

	assert(G_TEMPLATE);
}
Ejemplo n.º 2
0
int
TutorialApplication::run()
{
  int result = 0;
  try
  {
    ////////////////////////////////////////////////
    // Open files first to be sure they are present.
    std::ifstream templates(templateFileName_.c_str(), openMode);
    if(!templates.good())
    {
      result = -1;
      std::cerr << "ERROR: Can't open template file: "
        << templateFileName_
        << std::endl;
    }

    std::ifstream fastFile(fastFileName_.c_str(), openMode);
    if(!fastFile.good())
    {
      result = -1;
      std::cerr << "ERROR: Can't open FAST data file: "
        << fastFileName_
        << std::endl;
    }

    if(result == 0)
    {
      /////////////////////////////////////////////
      // Parse the templates from the template file
      // errors are reported by throwing exceptions
      // which are caught below.
      Codecs::XMLTemplateParser parser;
      Codecs::TemplateRegistryPtr registry = parser.parse(templates);

      /////////////////////////////////////////////
      // For the tutorial assume there is no header
      // on the incoming messages.
      Codecs::NoHeaderAnalyzer analyzer;

      //////////////////////////////////////
      // Create an application object to use
      // the incoming data.  In this case to
      // accept complete messages and interpret
      // them to standard out.
      MessageInterpreter handler(std::cout);
      // and use the interpreter as the consumer
      // of generic messages.
      Codecs::GenericMessageBuilder builder(handler);

      //////////////////////////////////////
      // Now pull all the pieces together
      // into an assembler.
      Codecs::StreamingAssembler assembler(
            registry,
            analyzer,
            builder,
            false);

      /////////////////////////////////////////////
      // set options in the assembler if necessary.
      // In this case configure the assembler to
      // reset the decoder on every incoming message
      assembler.setReset(true);

      ///////////////////////////////////////////////////////////////////////////////
      // Create an object to receive data from a raw data file (i.e to read the file)
      Communication::RawFileReceiver receiver(fastFile);

      /////////////////////////////////////////////
      // do final initialzation of the data receiver.
      receiver.start(assembler);

      /////////////////////////////////////
      // run the event loop in this thread.
      // Do not return until receiver stops.
      // The RawFileReceiver will stop at end of file.
      receiver.run();
    }
  }
  catch (std::exception & e)
  {
    std::cerr << e.what() << std::endl;
    result = -1;
  }
  return result;
}