start an xml format

This commit is contained in:
Joe Thornber 2011-10-10 15:06:07 +01:00
parent d255180e37
commit 687525fdb0
4 changed files with 130 additions and 2 deletions

View File

@ -12,7 +12,8 @@ SOURCE=\
metadata_dump.cc \
metadata_disk_structures.cc \
space_map_disk.cc \
transaction_manager.cc
transaction_manager.cc \
xml_format.cc
OBJECTS=$(subst .cc,.o,$(SOURCE))
TOP_DIR:=$(PWD)

View File

@ -1,6 +1,7 @@
#include "metadata.h"
#include "human_readable_format.h"
#include "xml_format.h"
using namespace persistent_data;
using namespace thin_provisioning;
@ -125,7 +126,7 @@ namespace {
void
metadata::dump()
{
emitter::ptr e = create_human_readable_emitter(cout);
emitter::ptr e = create_xml_emitter(cout);
details_extractor::ptr de(new details_extractor);

110
xml_format.cc Normal file
View File

@ -0,0 +1,110 @@
#include "xml_format.h"
#include <iostream>
using namespace std;
using namespace thin_provisioning;
//----------------------------------------------------------------
namespace {
class xml_emitter : public emitter {
public:
xml_emitter(ostream &out)
: out_(out),
indent_(0) {
}
void begin_superblock(string const &uuid,
uint64_t time,
uint64_t trans_id,
uint32_t data_block_size) {
out_ << "begin superblock: " << uuid
<< ", " << time
<< ", " << trans_id
<< ", " << data_block_size
<< endl;
}
void end_superblock() {
out_ << "end superblock" << endl;
}
void begin_device(uint32_t dev_id,
uint64_t mapped_blocks,
uint64_t trans_id,
uint64_t creation_time,
uint64_t snap_time) {
indent();
out_ << "<device dev_id =\"" << dev_id << "\""
<< " mapped_blocks=\"" << mapped_blocks << "\""
<< " transaction=\"" << trans_id << "\""
<< " creation_time=\"" << creation_time << "\""
<< " snap_time=\"" << snap_time << "\">" << endl;
inc();
}
void end_device() {
dec();
out_ << "</device>" << endl;
}
void begin_named_mapping(string const &name) {
out_ << "begin named mapping"
<< endl;
}
void end_named_mapping() {
out_ << "end named mapping"
<< endl;
}
void identifier(string const &name) {
out_ << "identifier: " << name << endl;
}
void range_map(uint64_t origin_begin, uint64_t data_begin, uint64_t len) {
indent();
out_ << "<range_mapping origin_begin=\"" << origin_begin << "\""
<< " data_begin=\"" << data_begin << "\""
<< " length=\"" << len << "\"/>"
<< endl;
}
void single_map(uint64_t origin_block, uint64_t data_block) {
indent();
out_ << "<single_mapping origin_block=\"" << origin_block << "\""
<< " data_block=\"" << data_block << "\"/>" << endl;
}
private:
void indent() {
for (unsigned i = 0; i < indent_ * 2; i++)
out_ << ' ';
}
void inc() {
indent_++;
}
void dec() {
indent_--;
}
ostream &out_;
unsigned indent_;
};
}
//----------------------------------------------------------------
thin_provisioning::emitter::ptr
thin_provisioning::create_xml_emitter(ostream &out)
{
return emitter::ptr(new xml_emitter(out));
}
//----------------------------------------------------------------

16
xml_format.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef XML_FORMAT_H
#define XML_FORMAT_H
#include "emitter.h"
#include <iosfwd>
//----------------------------------------------------------------
namespace thin_provisioning {
emitter::ptr create_xml_emitter(std::ostream &out);
}
//----------------------------------------------------------------
#endif