void MultipleAvroFileWriter::commit() {
  RMF_TRACE("Writing frame " << frame_.index);
  for (unsigned int i = 0; i < categories_.size(); ++i) {
    if (categories_[i].dirty) {
      if (!categories_[i].writer) {
        std::string name = get_category_dynamic_file_path(Category(i));
        try {
          categories_[i].writer.reset(
              new internal_avro::DataFileWriter<RMF_avro_backend::Data>(
                  name.c_str(), internal_avro::compileJsonSchemaFromString(
                                    data_deprecated_avro::data_json)));
        }
        catch (const std::exception& e) {
          RMF_THROW(Message(e.what()) << Component(name), IOException);
        }
      }
      // show(categories_[i].data);
      RMF_INTERNAL_CHECK(categories_[i].data.frame == frame_.index,
                         "Trying to write category that is at wrong frame.");
      categories_[i].writer->write(categories_[i].data);
      categories_[i].writer->flush();
    }
    categories_[i].data = RMF_avro_backend::Data();
    // go to the about to be added frame
    categories_[i].data.frame = frame_.index + 1;
  }
  for (unsigned int i = 0; i < static_categories_.size(); ++i) {
    if (static_categories_dirty_[i]) {
      std::string name = get_category_static_file_path(Category(i));
      try {
        internal_avro::DataFileWriter<RMF_avro_backend::Data> writer(
            name.c_str(), internal_avro::compileJsonSchemaFromString(
                              data_deprecated_avro::data_json));
        writer.write(static_categories_[i]);
        writer.flush();
      }
      catch (const std::exception& e) {
        RMF_THROW(Message(e.what()) << Component(name), IOException);
      }
      // std::cout << "Writing data for " << get_category_name(Category(i)) <<
      // std::endl;
      // show(static_categories_[i]);
      static_categories_dirty_[i] = false;
    }
  }
  RMF_COMMIT(File, file);
  RMF_COMMIT(Nodes, nodes);
  if (frames_dirty_) {
    if (!frame_writer_) {
      frame_writer_.reset(
          new internal_avro::DataFileWriter<RMF_avro_backend::Frame>(
              get_frames_file_path().c_str(),
              internal_avro::compileJsonSchemaFromString(
                  data_deprecated_avro::frame_json)));
    }
    frame_writer_->write(frame_);
    frames_dirty_ = false;
  }
}
Beispiel #2
0
boost::shared_ptr<SharedData> create_buffer(BufferHandle buffer) {
    boost::shared_ptr<backends::IO> io = backends::create_buffer(buffer);
    if (!io) {
        RMF_THROW(Message("Can't create buffer"), IOException);
    }
    return boost::make_shared<SharedData>(io, "buffer", true, true);
}
Beispiel #3
0
boost::shared_ptr<SharedData> create_file(const std::string& name) {
    boost::shared_ptr<backends::IO> io = backends::create_file(name);
    if (!io) {
        RMF_THROW(Message("Can't create file") << File(name), IOException);
    }
    return boost::make_shared<SharedData>(io, name, true, true);
}
Beispiel #4
0
boost::shared_ptr<SharedData> read_buffer(BufferConstHandle buffer) {
    boost::shared_ptr<backends::IO> io = backends::read_buffer(buffer);
    if (!io) {
        RMF_THROW(Message("Can't read buffer"), IOException);
    }
    boost::shared_ptr<SharedData> ret =
        boost::make_shared<SharedData>(io, "buffer", false, false);
    return ret;
}
Beispiel #5
0
boost::shared_ptr<SharedData> read_file(const std::string& name) {
    boost::shared_ptr<backends::IO> io = backends::read_file(name);
    if (!io) {
        RMF_THROW(Message("Can't read file") << File(name), IOException);
    }
    boost::shared_ptr<SharedData> ret =
        boost::make_shared<SharedData>(io, name, false, false);
    return ret;
}
Beispiel #6
0
void SingleAvroFile::reload() {
  if (!write_to_buffer_ && !text_) {
    bool success;
    try {
      rmf_avro::DataFileReader<RMF_avro_backend::All>
      rd(get_file_path().c_str(), get_All_schema());
      success = rd.read(all_);
    } catch (std::exception &e) {
      RMF_THROW(Message(e.what()) << File(get_file_path()),
                IOException);
    }
    if (!success) {
      RMF_THROW(Message("Can't read input file on reload"), IOException);
    }
  } else if (!write_to_buffer_ && text_) {
    boost::shared_ptr<rmf_avro::Decoder> decoder
      = rmf_avro::jsonDecoder(get_All_schema());
    std::auto_ptr<rmf_avro::InputStream> stream
      = rmf_avro::fileInputStream(get_file_path().c_str());
    decoder->init(*stream);
    bool success=false;
    try {
      rmf_avro::decode(*decoder, all_);
      success = true;
    } catch (std::exception &e) {
      RMF_THROW(Message(e.what()) << File(get_file_path()),
                IOException);
    }
    if (!success) {
      RMF_THROW(Message("Can't read input file on reload"), IOException);
    }
  } else {
    std::istringstream iss(*buffer_, std::ios_base::binary);
    boost::scoped_ptr<rmf_avro::InputStream>
      is(rmf_avro::istreamInputStream(iss).release());
    boost::shared_ptr<rmf_avro::Decoder> decoder = rmf_avro::binaryDecoder();
    decoder->init(*is);
    rmf_avro::decode(*decoder, all_);
  }
  initialize_categories();
  initialize_node_keys();
  dirty_ = false;
}
FrameIDs MultipleAvroFileWriter::get_children(FrameID /*node*/) const {
  RMF_THROW(Message("RMF2 writer doesn't support getting frame children."),
            UsageException);
}
void MultipleAvroFileWriter::add_child_frame(FrameID) {
  RMF_THROW(Message(
                "RMF2 writer doesn't support adding other frames than "
                "the current as a child."),
            UsageException);
}