Commit 138c18e7 authored by Jelte Jansen's avatar Jelte Jansen

refactor: function_name to functionName in data.h (functions on isc::data::Elements)


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@408 e5f2f494-b856-4b98-b285-d166d9295462
parent 27185721
...@@ -100,12 +100,12 @@ CommandSession::CommandSession(std::string module_name, ...@@ -100,12 +100,12 @@ CommandSession::CommandSession(std::string module_name,
// get any stored configuration from the manager // get any stored configuration from the manager
if (config_handler_) { if (config_handler_) {
ElementPtr cmd = Element::create_from_string("{ \"command\": [ \"get_config\", \"" + module_name + "\" ] }"); ElementPtr cmd = Element::createFromString("{ \"command\": [ \"get_config\", \"" + module_name + "\" ] }");
session_.group_sendmsg(cmd, "ConfigManager"); session_.group_sendmsg(cmd, "ConfigManager");
session_.group_recvmsg(env, answer, false); session_.group_recvmsg(env, answer, false);
cout << "[XX] got config: " << endl << answer->str() << endl; cout << "[XX] got config: " << endl << answer->str() << endl;
if (answer->contains("result") && if (answer->contains("result") &&
answer->get("result")->get(0)->int_value() == 0 && answer->get("result")->get(0)->intValue() == 0 &&
answer->get("result")->size() > 1) { answer->get("result")->size() > 1) {
config_handler(answer->get("result")->get(1)); config_handler(answer->get("result")->get(1));
} else { } else {
...@@ -128,7 +128,7 @@ CommandSession::check_command() ...@@ -128,7 +128,7 @@ CommandSession::check_command()
if (session_.group_recvmsg(routing, data, true)) { if (session_.group_recvmsg(routing, data, true)) {
/* ignore result messages (in case we're out of sync, to prevent /* ignore result messages (in case we're out of sync, to prevent
* pingpongs */ * pingpongs */
if (!data->get_type() == Element::map || data->contains("result")) { if (!data->getType() == Element::map || data->contains("result")) {
return 0; return 0;
} }
cout << "[XX] got something!" << endl << data->str() << endl; cout << "[XX] got something!" << endl << data->str() << endl;
...@@ -138,14 +138,14 @@ CommandSession::check_command() ...@@ -138,14 +138,14 @@ CommandSession::check_command()
// handle config update // handle config update
answer = config_handler_(data->get("config_update")); answer = config_handler_(data->get("config_update"));
} else { } else {
answer = Element::create_from_string("{ \"result\": [0] }"); answer = Element::createFromString("{ \"result\": [0] }");
} }
} }
if (data->contains("command")) { if (data->contains("command")) {
if (command_handler_) { if (command_handler_) {
answer = command_handler_(data->get("command")); answer = command_handler_(data->get("command"));
} else { } else {
answer = Element::create_from_string("{ \"result\": [0] }"); answer = Element::createFromString("{ \"result\": [0] }");
} }
} }
session_.reply(routing, answer); session_.reply(routing, answer);
......
...@@ -64,8 +64,8 @@ my_config_handler(isc::data::ElementPtr config) ...@@ -64,8 +64,8 @@ my_config_handler(isc::data::ElementPtr config)
cout << "[XX] Handle config: " << endl << config->str() << endl; cout << "[XX] Handle config: " << endl << config->str() << endl;
if (config->contains("zones")) { if (config->contains("zones")) {
plot.clear_zones(); plot.clear_zones();
BOOST_FOREACH(isc::data::ElementPtr zone_el, config->get("zones")->list_value()) { BOOST_FOREACH(isc::data::ElementPtr zone_el, config->get("zones")->listValue()) {
plot.serve(zone_el->string_value()); plot.serve(zone_el->stringValue());
} }
} }
if (config->contains("port")) { if (config->contains("port")) {
...@@ -74,33 +74,33 @@ my_config_handler(isc::data::ElementPtr config) ...@@ -74,33 +74,33 @@ my_config_handler(isc::data::ElementPtr config)
} }
if (config->contains("a_records")) { if (config->contains("a_records")) {
plot.clearARecords(); plot.clearARecords();
BOOST_FOREACH(isc::data::ElementPtr rel, config->get("a_records")->list_value()) { BOOST_FOREACH(isc::data::ElementPtr rel, config->get("a_records")->listValue()) {
plot.addARecord(rel->string_value()); plot.addARecord(rel->stringValue());
} }
} }
if (config->contains("aaaa_records")) { if (config->contains("aaaa_records")) {
plot.clearAAAARecords(); plot.clearAAAARecords();
BOOST_FOREACH(isc::data::ElementPtr rel, config->get("aaaa_records")->list_value()) { BOOST_FOREACH(isc::data::ElementPtr rel, config->get("aaaa_records")->listValue()) {
plot.addAAAARecord(rel->string_value()); plot.addAAAARecord(rel->stringValue());
} }
} }
if (config->contains("ns_records")) { if (config->contains("ns_records")) {
plot.clearNSRecords(); plot.clearNSRecords();
BOOST_FOREACH(isc::data::ElementPtr rel, config->get("ns_records")->list_value()) { BOOST_FOREACH(isc::data::ElementPtr rel, config->get("ns_records")->listValue()) {
plot.addNSRecord(rel->string_value()); plot.addNSRecord(rel->stringValue());
} }
} }
return isc::data::Element::create_from_string("{ \"result\": [0] }"); return isc::data::Element::createFromString("{ \"result\": [0] }");
} }
isc::data::ElementPtr isc::data::ElementPtr
my_command_handler(isc::data::ElementPtr command) my_command_handler(isc::data::ElementPtr command)
{ {
isc::data::ElementPtr answer = isc::data::Element::create_from_string("{ \"result\": [0] }"); isc::data::ElementPtr answer = isc::data::Element::createFromString("{ \"result\": [0] }");
cout << "[XX] Handle command: " << endl << command->str() << endl; cout << "[XX] Handle command: " << endl << command->str() << endl;
if (command->get(1)->string_value() == "print_message") { if (command->get(1)->stringValue() == "print_message") {
cout << command->get(2)->string_value() << endl; cout << command->get(2)->stringValue() << endl;
/* let's add that message to our answer as well */ /* let's add that message to our answer as well */
cout << "[XX] answer was: " << answer->str() << endl; cout << "[XX] answer was: " << answer->str() << endl;
answer->get("result")->add(command->get(2)); answer->get("result")->add(command->get(2));
......
...@@ -235,8 +235,8 @@ ParkingLot::command(pair<string,ElementPtr> cmd) { ...@@ -235,8 +235,8 @@ ParkingLot::command(pair<string,ElementPtr> cmd) {
// We could walk through both lists and remove and serve // We could walk through both lists and remove and serve
// accordingly, or simply clear all and add everything // accordingly, or simply clear all and add everything
zones.clear_zones(); zones.clear_zones();
BOOST_FOREACH(ElementPtr zone, zonelist_el->list_value()) { BOOST_FOREACH(ElementPtr zone, zonelist_el->listValue()) {
zones.serve(zone->string_value()); zones.serve(zone->stringValue());
} }
} }
} }
......
...@@ -104,7 +104,7 @@ Element::create(const std::map<std::string, ElementPtr>& m) ...@@ -104,7 +104,7 @@ Element::create(const std::map<std::string, ElementPtr>& m)
// //
// helper functions for create_from_string factory // helper functions for createFromString factory
// these should probably also be moved to member functions // these should probably also be moved to member functions
// //
...@@ -268,7 +268,7 @@ from_stringstream_list(std::istream &in, int& line, int& pos) ...@@ -268,7 +268,7 @@ from_stringstream_list(std::istream &in, int& line, int& pos)
while (c != EOF && c != ']') { while (c != EOF && c != ']') {
//cout << "at line " << line << " pos " << pos << " cur c: " << c << " next c: " << char(in.peek()) << endl; //cout << "at line " << line << " pos " << pos << " cur c: " << c << " next c: " << char(in.peek()) << endl;
if (in.peek() != ']') { if (in.peek() != ']') {
cur_list_element = Element::create_from_string(in, line, pos); cur_list_element = Element::createFromString(in, line, pos);
v.push_back(cur_list_element); v.push_back(cur_list_element);
skip_to(in, line, pos, ",]", " \t\n"); skip_to(in, line, pos, ",]", " \t\n");
} }
...@@ -293,7 +293,7 @@ from_stringstream_map(std::istream &in, int& line, int& pos) ...@@ -293,7 +293,7 @@ from_stringstream_map(std::istream &in, int& line, int& pos)
// skip the : // skip the :
in.get(); in.get();
pos++; pos++;
p.second = Element::create_from_string(in, line, pos); p.second = Element::createFromString(in, line, pos);
if (!p.second) { if (!p.second) {
throw ParseError(std::string("missing map value for ") + p.first, line, pos); throw ParseError(std::string("missing map value for ") + p.first, line, pos);
}; };
...@@ -306,14 +306,14 @@ from_stringstream_map(std::istream &in, int& line, int& pos) ...@@ -306,14 +306,14 @@ from_stringstream_map(std::istream &in, int& line, int& pos)
} }
ElementPtr ElementPtr
Element::create_from_string(std::istream &in) throw(ParseError) Element::createFromString(std::istream &in) throw(ParseError)
{ {
int line = 1, pos = 1; int line = 1, pos = 1;
return create_from_string(in, line, pos); return createFromString(in, line, pos);
} }
ElementPtr ElementPtr
Element::create_from_string(std::istream &in, int& line, int& pos) throw(ParseError) Element::createFromString(std::istream &in, int& line, int& pos) throw(ParseError)
{ {
char c = 0; char c = 0;
ElementPtr element; ElementPtr element;
...@@ -374,11 +374,11 @@ Element::create_from_string(std::istream &in, int& line, int& pos) throw(ParseEr ...@@ -374,11 +374,11 @@ Element::create_from_string(std::istream &in, int& line, int& pos) throw(ParseEr
} }
ElementPtr ElementPtr
Element::create_from_string(const std::string &in) Element::createFromString(const std::string &in)
{ {
std::stringstream ss; std::stringstream ss;
ss << in; ss << in;
return create_from_string(ss); return createFromString(ss);
} }
// //
// a general to_str() function // a general to_str() function
...@@ -387,7 +387,7 @@ std::string ...@@ -387,7 +387,7 @@ std::string
IntElement::str() IntElement::str()
{ {
std::stringstream ss; std::stringstream ss;
ss << int_value(); ss << intValue();
return ss.str(); return ss.str();
} }
...@@ -395,7 +395,7 @@ std::string ...@@ -395,7 +395,7 @@ std::string
DoubleElement::str() DoubleElement::str()
{ {
std::stringstream ss; std::stringstream ss;
ss << double_value(); ss << doubleValue();
return ss.str(); return ss.str();
} }
...@@ -414,7 +414,7 @@ StringElement::str() ...@@ -414,7 +414,7 @@ StringElement::str()
{ {
std::stringstream ss; std::stringstream ss;
ss << "\""; ss << "\"";
ss << string_value(); ss << stringValue();
ss << "\""; ss << "\"";
return ss.str(); return ss.str();
} }
...@@ -425,7 +425,7 @@ ListElement::str() ...@@ -425,7 +425,7 @@ ListElement::str()
std::stringstream ss; std::stringstream ss;
std::vector<ElementPtr> v; std::vector<ElementPtr> v;
ss << "[ "; ss << "[ ";
v = list_value(); v = listValue();
for (std::vector<ElementPtr>::iterator it = v.begin(); it != v.end(); ++it) { for (std::vector<ElementPtr>::iterator it = v.begin(); it != v.end(); ++it) {
if (it != v.begin()) { if (it != v.begin()) {
ss << ", "; ss << ", ";
...@@ -442,7 +442,7 @@ MapElement::str() ...@@ -442,7 +442,7 @@ MapElement::str()
std::stringstream ss; std::stringstream ss;
std::map<std::string, ElementPtr> m; std::map<std::string, ElementPtr> m;
ss << "{"; ss << "{";
m = map_value(); m = mapValue();
for (std::map<std::string, ElementPtr>::iterator it = m.begin(); it != m.end(); ++it) { for (std::map<std::string, ElementPtr>::iterator it = m.begin(); it != m.end(); ++it) {
if (it != m.begin()) { if (it != m.begin()) {
ss << ", "; ss << ", ";
...@@ -455,7 +455,7 @@ MapElement::str() ...@@ -455,7 +455,7 @@ MapElement::str()
} }
// //
// helpers for str_xml() functions // helpers for strXML() functions
// //
// prefix with 'prefix' number of spaces // prefix with 'prefix' number of spaces
...@@ -468,7 +468,7 @@ pre(std::ostream &out, size_t prefix) ...@@ -468,7 +468,7 @@ pre(std::ostream &out, size_t prefix)
} }
std::string std::string
IntElement::str_xml(size_t prefix) IntElement::strXML(size_t prefix)
{ {
std::stringstream ss; std::stringstream ss;
pre(ss, prefix); pre(ss, prefix);
...@@ -477,7 +477,7 @@ IntElement::str_xml(size_t prefix) ...@@ -477,7 +477,7 @@ IntElement::str_xml(size_t prefix)
} }
std::string std::string
DoubleElement::str_xml(size_t prefix) DoubleElement::strXML(size_t prefix)
{ {
std::stringstream ss; std::stringstream ss;
pre(ss, prefix); pre(ss, prefix);
...@@ -486,7 +486,7 @@ DoubleElement::str_xml(size_t prefix) ...@@ -486,7 +486,7 @@ DoubleElement::str_xml(size_t prefix)
} }
std::string std::string
BoolElement::str_xml(size_t prefix) BoolElement::strXML(size_t prefix)
{ {
std::stringstream ss; std::stringstream ss;
pre(ss, prefix); pre(ss, prefix);
...@@ -495,26 +495,26 @@ BoolElement::str_xml(size_t prefix) ...@@ -495,26 +495,26 @@ BoolElement::str_xml(size_t prefix)
} }
std::string std::string
StringElement::str_xml(size_t prefix) StringElement::strXML(size_t prefix)
{ {
std::stringstream ss; std::stringstream ss;
pre(ss, prefix); pre(ss, prefix);
ss << string_value(); ss << stringValue();
return ss.str(); return ss.str();
} }
std::string std::string
ListElement::str_xml(size_t prefix) ListElement::strXML(size_t prefix)
{ {
std::stringstream ss; std::stringstream ss;
std::vector<ElementPtr> v; std::vector<ElementPtr> v;
pre(ss, prefix); pre(ss, prefix);
ss << "<list>" << endl;; ss << "<list>" << endl;;
v = list_value(); v = listValue();
for (std::vector<ElementPtr>::iterator it = v.begin(); it != v.end(); ++it) { for (std::vector<ElementPtr>::iterator it = v.begin(); it != v.end(); ++it) {
pre(ss, prefix + 4); pre(ss, prefix + 4);
ss << "<listitem>" << endl; ss << "<listitem>" << endl;
ss << (*it)->str_xml(prefix + 8) << endl; ss << (*it)->strXML(prefix + 8) << endl;
pre(ss, prefix + 4); pre(ss, prefix + 4);
ss << "</listitem>" << endl; ss << "</listitem>" << endl;
} }
...@@ -524,18 +524,18 @@ ListElement::str_xml(size_t prefix) ...@@ -524,18 +524,18 @@ ListElement::str_xml(size_t prefix)
} }
std::string std::string
MapElement::str_xml(size_t prefix) MapElement::strXML(size_t prefix)
{ {
std::stringstream ss; std::stringstream ss;
std::map<std::string, ElementPtr> m; std::map<std::string, ElementPtr> m;
m = map_value(); m = mapValue();
pre(ss, prefix); pre(ss, prefix);
ss << "<map>" << endl; ss << "<map>" << endl;
for (std::map<std::string, ElementPtr>::iterator it = m.begin(); it != m.end(); ++it) { for (std::map<std::string, ElementPtr>::iterator it = m.begin(); it != m.end(); ++it) {
pre(ss, prefix + 4); pre(ss, prefix + 4);
ss << "<mapitem name=\"" << (*it).first << "\">" << endl; ss << "<mapitem name=\"" << (*it).first << "\">" << endl;
pre(ss, prefix); pre(ss, prefix);
ss << (*it).second->str_xml(prefix+8) << endl; ss << (*it).second->strXML(prefix+8) << endl;
pre(ss, prefix + 4); pre(ss, prefix + 4);
ss << "</mapitem>" << endl; ss << "</mapitem>" << endl;
} }
...@@ -551,7 +551,7 @@ MapElement::str_xml(size_t prefix) ...@@ -551,7 +551,7 @@ MapElement::str_xml(size_t prefix)
ElementPtr ElementPtr
MapElement::find(const std::string& id) MapElement::find(const std::string& id)
{ {
if (get_type() != map) { if (getType() != map) {
throw TypeError(); throw TypeError();
} }
size_t sep = id.find('/'); size_t sep = id.find('/');
...@@ -752,15 +752,15 @@ decode_element(std::stringstream& in, int& in_length) ...@@ -752,15 +752,15 @@ decode_element(std::stringstream& in, int& in_length)
} }
ElementPtr ElementPtr
Element::from_wire(const std::string& s) Element::fromWire(const std::string& s)
{ {
std::stringstream ss; std::stringstream ss;
ss << s; ss << s;
return from_wire(ss, s.length()); return fromWire(ss, s.length());
} }
ElementPtr ElementPtr
Element::from_wire(std::stringstream& in, int length) Element::fromWire(std::stringstream& in, int length)
{ {
// //
// Check protocol version // Check protocol version
...@@ -812,18 +812,18 @@ encode_length(unsigned int length, unsigned char type) ...@@ -812,18 +812,18 @@ encode_length(unsigned int length, unsigned char type)
} }
std::string std::string
StringElement::to_wire(int omit_length) StringElement::toWire(int omit_length)
{ {
std::stringstream ss; std::stringstream ss;
int length = string_value().length(); int length = stringValue().length();
ss << encode_length(length, ITEM_UTF8) << string_value(); ss << encode_length(length, ITEM_UTF8) << stringValue();
return ss.str(); return ss.str();
} }
std::string std::string
IntElement::to_wire(int omit_length) IntElement::toWire(int omit_length)
{ {
std::stringstream ss; std::stringstream ss;
std::stringstream text; std::stringstream text;
...@@ -836,7 +836,7 @@ IntElement::to_wire(int omit_length) ...@@ -836,7 +836,7 @@ IntElement::to_wire(int omit_length)
} }
std::string std::string
BoolElement::to_wire(int omit_length) BoolElement::toWire(int omit_length)
{ {
std::stringstream ss; std::stringstream ss;
std::stringstream text; std::stringstream text;
...@@ -844,7 +844,7 @@ BoolElement::to_wire(int omit_length) ...@@ -844,7 +844,7 @@ BoolElement::to_wire(int omit_length)
text << str(); text << str();
int length = 1; int length = 1;
ss << encode_length(length, ITEM_BOOL); ss << encode_length(length, ITEM_BOOL);
if (bool_value()) { if (boolValue()) {
ss << 0x01; ss << 0x01;
} else { } else {
ss << 0x00; ss << 0x00;
...@@ -854,7 +854,7 @@ BoolElement::to_wire(int omit_length) ...@@ -854,7 +854,7 @@ BoolElement::to_wire(int omit_length)
} }
std::string std::string
DoubleElement::to_wire(int omit_length) DoubleElement::toWire(int omit_length)
{ {
std::stringstream ss; std::stringstream ss;
std::stringstream text; std::stringstream text;
...@@ -867,14 +867,14 @@ DoubleElement::to_wire(int omit_length) ...@@ -867,14 +867,14 @@ DoubleElement::to_wire(int omit_length)
} }
std::string std::string
ListElement::to_wire(int omit_length) ListElement::toWire(int omit_length)
{ {
std::stringstream ss; std::stringstream ss;
std::vector<ElementPtr> v; std::vector<ElementPtr> v;
v = list_value(); v = listValue();
for (std::vector<ElementPtr>::iterator it = v.begin() ; for (std::vector<ElementPtr>::iterator it = v.begin() ;
it != v.end() ; ++it) { it != v.end() ; ++it) {
ss << (*it)->to_wire(0); ss << (*it)->toWire(0);
} }
if (omit_length) { if (omit_length) {
...@@ -900,7 +900,7 @@ encode_tag(const std::string &s) ...@@ -900,7 +900,7 @@ encode_tag(const std::string &s)
} }
std::string std::string
MapElement::to_wire(int omit_length) MapElement::toWire(int omit_length)
{ {
std::stringstream ss; std::stringstream ss;
std::map<std::string, ElementPtr> m; std::map<std::string, ElementPtr> m;
...@@ -913,11 +913,11 @@ MapElement::to_wire(int omit_length) ...@@ -913,11 +913,11 @@ MapElement::to_wire(int omit_length)
ss << PROTOCOL_VERSION[2] << PROTOCOL_VERSION[3]; ss << PROTOCOL_VERSION[2] << PROTOCOL_VERSION[3];
} }
m = map_value(); m = mapValue();
for (std::map<std::string, ElementPtr>::iterator it = m.begin() ; for (std::map<std::string, ElementPtr>::iterator it = m.begin() ;
it != m.end() ; ++it) { it != m.end() ; ++it) {
ss << encode_tag((*it).first); ss << encode_tag((*it).first);
ss << (*it).second->to_wire(0); ss << (*it).second->toWire(0);
} }
// //
...@@ -949,7 +949,7 @@ MapElement::find(const std::string& id, ElementPtr& t) { ...@@ -949,7 +949,7 @@ MapElement::find(const std::string& id, ElementPtr& t) {
} }
bool bool
isc::data::is_null(ElementPtr p) isc::data::isNull(ElementPtr p)
{ {
return !p; return !p;
} }
......
...@@ -48,7 +48,7 @@ namespace isc { namespace data { ...@@ -48,7 +48,7 @@ namespace isc { namespace data {
private: private:
// technically the type could be omitted; is it useful? // technically the type could be omitted; is it useful?
// should we remove it or replace it with a pure virtual // should we remove it or replace it with a pure virtual
// function get_type? // function getType?
int type; int type;