thin-provisioning-tools/era/xml_format.cc

89 lines
1.9 KiB
C++
Raw Normal View History

2014-01-23 06:16:03 +05:30
#include "era/xml_format.h"
2014-01-31 19:13:39 +05:30
#include "base/indented_stream.h"
2014-01-23 06:16:03 +05:30
using namespace boost;
using namespace era;
using namespace persistent_data;
using namespace std;
//----------------------------------------------------------------
namespace {
class xml_emitter : public emitter {
public:
xml_emitter(ostream &out)
2014-01-31 19:13:39 +05:30
: out_(out) {
2014-01-23 06:16:03 +05:30
}
void begin_superblock(std::string const &uuid,
uint32_t block_size,
pd::block_address nr_blocks,
uint32_t current_era) {
2014-01-31 19:13:39 +05:30
out_.indent();
2014-01-23 06:16:03 +05:30
out_ << "<superblock uuid=\"" << uuid << "\""
<< " block_size=\"" << block_size << "\""
<< " nr_blocks=\"" << nr_blocks << "\""
2014-01-31 19:13:39 +05:30
<< " current_era=\"" << current_era << "\">";
out_ << endl;
out_.inc();
2014-01-23 06:16:03 +05:30
}
void end_superblock() {
2014-01-31 19:13:39 +05:30
out_.dec();
out_.indent();
2014-01-23 06:16:03 +05:30
out_ << "</superblock>" << endl;
}
void begin_writeset(uint32_t era, uint32_t nr_bits) {
2014-01-31 19:13:39 +05:30
out_.indent();
out_ << "<writeset era=\"" << era << "\""
<< " nr_bits=\"" << nr_bits << "\">" << endl;
2014-01-31 19:13:39 +05:30
out_.inc();
2014-01-23 06:16:03 +05:30
}
void writeset_bit(uint32_t bit, bool value) {
2014-01-31 19:13:39 +05:30
out_.indent();
2014-01-23 06:16:03 +05:30
// FIXME: collect all the bits, then uuencode
out_ << "<bit bit=\"" << bit << "\" value=\"" << value << "\">" << endl;
}
void end_writeset() {
2014-01-31 19:13:39 +05:30
out_.dec();
out_.indent();
out_ << "</writeset>" << endl;
2014-01-23 06:16:03 +05:30
}
void begin_era_array() {
2014-01-31 19:13:39 +05:30
out_.indent();
2014-01-23 06:16:03 +05:30
out_ << "<era_array>" << endl;
2014-01-31 19:13:39 +05:30
out_.inc();
2014-01-23 06:16:03 +05:30
}
void era(pd::block_address block, uint32_t era) {
2014-01-31 19:13:39 +05:30
out_.indent();
2014-01-23 06:16:03 +05:30
out_ << "<era block=\"" << block
<< "\" era=\"" << era << "\">" << endl;
}
void end_era_array() {
2014-01-31 19:13:39 +05:30
out_.dec();
out_.indent();
2014-01-23 06:16:03 +05:30
out_ << "</era_array>" << endl;
}
private:
2014-01-31 19:13:39 +05:30
indented_stream out_;
2014-01-23 06:16:03 +05:30
};
}
//----------------------------------------------------------------
emitter::ptr
era::create_xml_emitter(std::ostream &out)
{
return emitter::ptr(new xml_emitter(out));
}
//----------------------------------------------------------------