Goby v2
queue_xml_callbacks.cpp
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 #include "queue_xml_callbacks.h"
24 
25 using namespace xercesc;
26 using namespace goby::transitional::xml;
27 
28 // this is called when the parser encounters the start tag, e.g. <message>
29 void goby::transitional::QueueContentHandler::startElement(
30  const XMLCh* const uri, // namespace URI
31  const XMLCh* const localname, // tagname w/ out NS prefix
32  const XMLCh* const qname, // tagname + NS pefix
33  const Attributes& attrs) // elements's attributes
34 {
35  //const XMLCh* val;
36  Tag current_tag = tags_map_[toNative(localname)];
37  parents_.insert(current_tag);
38 
39  switch (current_tag)
40  {
41  default: break;
42 
43  case tag_message:
45  q_.back().mutable_key()->set_type(goby::transitional::protobuf::QUEUE_DCCL);
46  break;
47  }
48 
49  current_text.clear();
50 }
51 
52 void goby::transitional::QueueContentHandler::endElement(
53  const XMLCh* const uri, // namespace URI
54  const XMLCh* const localname, // tagname w/ out NS prefix
55  const XMLCh* const qname) // tagname + NS pefix
56 {
57  std::string trimmed_data = boost::trim_copy(current_text);
58 
59  Tag current_tag = tags_map_[toNative(localname)];
60  parents_.erase(current_tag);
61 
62  using goby::util::as;
63  using google::protobuf::uint32;
64 
65  switch (current_tag)
66  {
67  default: break;
68 
69  case tag_ack: q_.back().set_ack(as<bool>(trimmed_data)); break;
70 
71  case tag_blackout_time: q_.back().set_blackout_time(as<uint32>(trimmed_data)); break;
72 
73  case tag_max_queue: q_.back().set_max_queue(as<uint32>(trimmed_data)); break;
74 
75  case tag_newest_first: q_.back().set_newest_first(as<bool>(trimmed_data)); break;
76 
77  case tag_id: q_.back().mutable_key()->set_id(as<uint32>(trimmed_data)); break;
78 
79  case tag_priority_base:
80  case tag_priority_time_const:
81  // deprecated
82  break;
83 
84  case tag_name:
85  if (!in_message_var() && !in_header_var())
86  q_.back().set_name(trimmed_data);
87  break;
88 
89  case tag_ttl: q_.back().set_ttl(as<uint32>(trimmed_data)); break;
90 
91  case tag_value_base: q_.back().set_value_base(as<double>(trimmed_data)); break;
92  }
93 }