Commit 92c996dc authored by Alexandre Savard's avatar Alexandre Savard

[#3649] Pass emitter as an argument for serialization

parent 455ae5be
......@@ -155,7 +155,7 @@ class Account : public Serializable{
*/
virtual ~Account();
virtual void serialize(Engine *engine) = 0;
virtual void serialize(Conf::YamlEmitter *emitter) = 0;
virtual void unserialize(Conf::MappingNode *map) = 0;
......
......@@ -33,6 +33,7 @@
#include "yamlparser.h"
#include "yamlemitter.h"
#include "yamlnode.h"
class Engine;
......@@ -42,7 +43,7 @@ class Serializable {
public:
virtual void serialize(Engine *engine) = 0;
virtual void serialize(Conf::YamlEmitter *emitter) = 0;
virtual void unserialize(Conf::MappingNode *map) = 0;
......
......@@ -120,8 +120,30 @@ void YamlEmitter::writeAccount(MappingNode *map)
}
void YamlEmitter::writePreference(MappingNode *map)
{
std::string preferencestr("preferences");
if(map->getType() == MAPPING)
throw YamlEmitterException("Node type is not a mapping while writing preferences");
int preferenceid = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)preferencestr.c_str(), -1, YAML_PLAIN_SCALAR_STYLE);
int preferencemapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE);
yaml_document_append_mapping_pair (&document, topLevelMapping, preferenceid, preferencemapping);
Mapping *internalmap = map->getMapping();
Mapping::iterator iter = internalmap->begin();
while(iter != internalmap->end()) {
addMappingItem(preferencemapping, iter->first, iter->second);
iter++;
}
}
void YamlEmitter::addMappingItem(int mappingid, Key key, YamlNode *node)
void YamlEmitter::addMappingItem(int mappingid, Key key, YamlNode *node)
{
if(node->getType() == SCALAR) {
......@@ -148,6 +170,8 @@ void YamlEmitter::writeAccount(MappingNode *map)
iter++;
}
}
else
throw YamlEmitterException("Unknown node type while adding mapping node");
}
......
......@@ -77,7 +77,7 @@ class YamlEmitter {
void writeAccount(MappingNode *map);
void writePreference();
void writePreference(MappingNode *map);
void writeAddressbook();
......
......@@ -47,7 +47,7 @@ IAXAccount::~IAXAccount()
_link = NULL;
}
void IAXAccount::serialize(Engine *engine)
void IAXAccount::serialize(Conf::YamlEmitter *emitter)
{
}
......
......@@ -44,7 +44,7 @@ class IAXAccount : public Account
~IAXAccount();
virtual void serialize(Engine *engine);
virtual void serialize(Conf::YamlEmitter *emitter);
virtual void unserialize(Conf::MappingNode *map);
......
......@@ -50,7 +50,7 @@ Preferences::Preferences() : _accountOrder("")
Preferences::~Preferences() {}
void Preferences::serialize(Engine *engine)
void Preferences::serialize(Conf::YamlEmitter *emiter)
{
Conf::MappingNode preferencemap(NULL);
......@@ -86,6 +86,7 @@ void Preferences::serialize(Engine *engine)
preferencemap.setKeyValue(zeroConfenableKey, &zeroConfenable);
preferencemap.setKeyValue(md5HashKey, &md5Hash);
}
void Preferences::unserialize(Conf::MappingNode *map)
......@@ -118,4 +119,6 @@ void Preferences::unserialize(Conf::MappingNode *map)
val = (Conf::ScalarNode *)(map->getValue(md5HashKey));
if(val) { _md5Hash = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
}
......@@ -54,7 +54,7 @@ class Preferences : public Serializable {
~Preferences();
virtual void serialize(Engine *engine);
virtual void serialize(Conf::YamlEmitter *emitter);
virtual void unserialize(Conf::MappingNode *map);
......
......@@ -40,7 +40,7 @@ Credentials::Credentials() : credentialCount(0) {}
Credentials::~Credentials() {}
void Credentials::serialize(Engine *engine)
void Credentials::serialize(Conf::YamlEmitter *emitter)
{
}
......@@ -132,7 +132,7 @@ SIPAccount::~SIPAccount()
free (_tlsSetting);
}
void SIPAccount::serialize(Engine *engine) {
void SIPAccount::serialize(Conf::YamlEmitter *emitter) {
Conf::MappingNode accountmap(NULL);
......
......@@ -134,7 +134,7 @@ class Credentials : public Serializable
~Credentials();
virtual void serialize(Engine *engine);
virtual void serialize(Conf::YamlEmitter *emitter);
virtual void unserialize(Conf::MappingNode *map);
......@@ -170,7 +170,7 @@ class SIPAccount : public Account
*/
virtual ~SIPAccount();
virtual void serialize(Engine *engine);
virtual void serialize(Conf::YamlEmitter *emitter);
virtual void unserialize(Conf::MappingNode *map);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment