//------------------------------------------------------------------------------
// Pass the data record to all of our subcomponents for processing; they all
// should be of type OutputHandler (see processComponents() above)
//------------------------------------------------------------------------------
void OutputHandler::processRecord(const DataRecordHandle* const dataRecord)
{
   // Check the data filters to see if we should process this type record
   if ( isDataTypeEnabled(dataRecord) ) {

      // First, call our own implementation
      processRecordImp(dataRecord);

      // Next, pass the data record to our subcomponent OutputHandlers
      // for further processing
      base::PairStream* subcomponents = getComponents();
      if (subcomponents != nullptr) {
         for (base::List::Item* item = subcomponents->getFirstItem(); item != nullptr; item = item->getNext()) {

            base::Pair* pair = static_cast<base::Pair*>(item->getValue());
            OutputHandler* sc = static_cast<OutputHandler*>(pair->object());

            sc->processRecord(dataRecord);
         }
         subcomponents->unref();
         subcomponents = nullptr;
      }

   }
}
示例#2
0
//------------------------------------------------------------------------------
// Close the data file
//------------------------------------------------------------------------------
void FileWriter::closeFile()
{
   if (isOpen()) {

      // ---
      // Write the EOD message, if it hasn't already been.
      if (!eodFlag) {
         eodFlag = true;

         // write something to signify don't read any more (e.g., last message)
         Pb::DataRecord* lastMsg = new Pb::DataRecord();

         // This will be the token representing the last message, but it can be
         // anything that is not one of the other event messages
         lastMsg->set_id(REID_END_OF_DATA);

         // Time is also required, although not used:
         Pb::Time* time = lastMsg->mutable_time();
         time->set_exec_time(0);
         time->set_sim_time(0);
         time->set_utc_time(0);

         // get a handle
         DataRecordHandle* handle = new DataRecordHandle(lastMsg);

         // write the message
         processRecordImp(handle);
         handle->unref();
         handle = nullptr;
      }

      // now close the file
      sout->close();
      fileOpened = false;
      fileFailed = false;

   }
}