23 #include "message_xml_callbacks.h" 25 #include "goby/util/as.h" 31 void goby::transitional::DCCLMessageContentHandler::startElement(
32 const XMLCh*
const uri,
33 const XMLCh*
const localname,
34 const XMLCh*
const qname,
35 const Attributes& attrs)
40 static const XMLCh* algorithm = fromNative(
"algorithm");
41 static const XMLCh* mandatory_content = fromNative(
"mandatory_content");
42 static const XMLCh* key = fromNative(
"key");
43 static const XMLCh* stype = fromNative(
"type");
45 Tag current_tag = tags_map_[toNative(localname)];
46 parents_.insert(current_tag);
54 messages.push_back(DCCLMessage());
57 case tag_layout:
break;
59 case tag_publish: messages.back().add_publish();
break;
68 messages.back().add_message_var(toNative(localname));
69 if ((val = attrs.getValue(algorithm)) != 0)
71 std::vector<std::string> vec;
72 std::string str = boost::erase_all_copy(toNative(val),
" ");
73 boost::split(vec, str, boost::is_any_of(
","));
74 messages.back().last_message_var().set_algorithms(vec);
80 if ((val = attrs.getValue(mandatory_content)) != 0)
81 messages.back().set_trigger_mandatory(toNative(val));
84 case tag_repeat: messages.back().set_repeat_enabled(
true);
break;
86 case tag_all: messages.back().last_publish().set_use_all_names(
true);
break;
91 if (in_message_var() && ((val = attrs.getValue(key)) != 0))
92 messages.back().last_message_var().set_source_key(toNative(val));
93 else if (in_header_var() && ((val = attrs.getValue(key)) != 0))
94 messages.back().header_var(curr_head_piece_).set_source_key(toNative(val));
95 else if (in_publish() && ((val = attrs.getValue(stype)) != 0))
97 if (toNative(val) ==
"double")
98 messages.back().last_publish().set_type(cpp_double);
99 else if (toNative(val) ==
"string")
100 messages.back().last_publish().set_type(cpp_string);
101 else if (toNative(val) ==
"long")
102 messages.back().last_publish().set_type(cpp_long);
103 else if (toNative(val) ==
"bool")
104 messages.back().last_publish().set_type(cpp_bool);
108 case tag_message_var:
111 if ((val = attrs.getValue(algorithm)) != 0)
113 std::vector<std::string> vec;
114 std::string str = boost::erase_all_copy(toNative(val),
" ");
115 boost::split(vec, str, boost::is_any_of(
","));
116 messages.back().last_publish().add_algorithms(vec);
120 messages.back().last_publish().add_algorithms(std::vector<std::string>());
126 curr_head_piece_ = HEAD_TIME;
127 if ((val = attrs.getValue(algorithm)) != 0)
129 std::vector<std::string> vec;
130 std::string str = boost::erase_all_copy(toNative(val),
" ");
131 boost::split(vec, str, boost::is_any_of(
","));
133 messages.back().header_var(curr_head_piece_).set_algorithms(vec);
138 curr_head_piece_ = HEAD_SRC_ID;
139 if ((val = attrs.getValue(algorithm)) != 0)
141 std::vector<std::string> vec;
142 std::string str = boost::erase_all_copy(toNative(val),
" ");
143 boost::split(vec, str, boost::is_any_of(
","));
144 messages.back().header_var(curr_head_piece_).set_algorithms(vec);
150 curr_head_piece_ = HEAD_DEST_ID;
151 if ((val = attrs.getValue(algorithm)) != 0)
153 std::vector<std::string> vec;
154 std::string str = boost::erase_all_copy(toNative(val),
" ");
155 boost::split(vec, str, boost::is_any_of(
","));
156 messages.back().header_var(curr_head_piece_).set_algorithms(vec);
161 case tag_destination_var:
162 if ((val = attrs.getValue(key)) != 0)
163 messages.back().header_var(HEAD_DEST_ID).set_name(toNative(val));
167 current_text.clear();
170 void goby::transitional::DCCLMessageContentHandler::endElement(
171 const XMLCh*
const uri,
172 const XMLCh*
const localname,
173 const XMLCh*
const qname)
175 std::string trimmed_data = boost::trim_copy(current_text);
177 Tag current_tag = tags_map_[toNative(localname)];
178 parents_.erase(current_tag);
183 messages.back().preprocess();
186 case tag_layout:
break;
188 case tag_publish:
break;
196 case tag_string:
break;
198 case tag_max_delta: messages.back().last_message_var().set_max_delta(trimmed_data);
break;
200 case tag_format: messages.back().last_publish().set_format(trimmed_data);
break;
202 case tag_id: messages.back().set_id(trimmed_data);
break;
204 case tag_incoming_hex_moos_var: messages.back().set_in_var(trimmed_data);
break;
206 case tag_max_length: messages.back().last_message_var().set_max_length(trimmed_data);
break;
208 case tag_num_bytes: messages.back().last_message_var().set_num_bytes(trimmed_data);
break;
210 case tag_max: messages.back().last_message_var().set_max(trimmed_data);
break;
212 case tag_message_var: messages.back().last_publish().add_name(trimmed_data);
break;
214 case tag_min: messages.back().last_message_var().set_min(trimmed_data);
break;
217 case tag_publish_var:
219 if (in_message_var())
220 messages.back().last_message_var().set_source_var(trimmed_data);
221 else if (in_header_var())
222 messages.back().header_var(curr_head_piece_).set_source_var(trimmed_data);
223 else if (in_publish())
224 messages.back().last_publish().set_var(trimmed_data);
228 case tag_destination_var:
229 messages.back().header_var(HEAD_DEST_ID).set_source_var(trimmed_data);
233 if (!in_message_var() && !in_header_var())
234 messages.back().set_name(trimmed_data);
235 else if (in_message_var())
236 messages.back().last_message_var().set_name(trimmed_data);
237 else if (in_header_var())
238 messages.back().header_var(curr_head_piece_).set_name(trimmed_data);
241 case tag_outgoing_hex_moos_var: messages.back().set_out_var(trimmed_data);
break;
243 case tag_precision: messages.back().last_message_var().set_precision(trimmed_data);
break;
245 case tag_size: messages.back().set_size(trimmed_data);
break;
247 case tag_trigger_var: messages.back().set_trigger_var(trimmed_data);
break;
249 case tag_trigger_time: messages.back().set_trigger_time(trimmed_data);
break;
251 case tag_trigger: messages.back().set_trigger(trimmed_data);
break;
254 if (parents_.count(tag_static))
255 messages.back().last_message_var().set_static_val(trimmed_data);
256 else if (parents_.count(tag_enum))
257 messages.back().last_message_var().add_enum(trimmed_data);
260 case tag_array_length:
261 messages.back().last_message_var().set_array_length(trimmed_data);