Goby v2
dccl_transitional.h
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 #ifndef DCCLTRANSITIONAL20091211H
24 #define DCCLTRANSITIONAL20091211H
25 
26 #include <map>
27 #include <ostream>
28 #include <set>
29 #include <stdexcept>
30 #include <string>
31 #include <vector>
32 
33 #include "goby/common/logger.h"
34 #include "goby/common/time.h"
35 #include "goby/moos/transitional/xml/xml_parser.h"
36 
37 #include "goby/acomms/acomms_helpers.h"
38 #include "goby/acomms/dccl.h"
39 #include "goby/acomms/protobuf/modem_message.pb.h"
40 #include "goby/acomms/protobuf/queue.pb.h"
41 #include "goby/moos/protobuf/pAcommsHandler_config.pb.h"
42 #include "goby/moos/protobuf/transitional.pb.h"
43 #include "message.h"
44 #include "message_val.h"
45 
46 #include <google/protobuf/compiler/importer.h>
47 #include <google/protobuf/descriptor.h>
48 #include <google/protobuf/dynamic_message.h>
49 
51 namespace goby
52 {
53 namespace util
54 {
55 class FlexOstream;
56 }
57 
59 namespace transitional
60 {
62 template <typename Value>
63 std::ostream& operator<<(std::ostream& out, const std::map<std::string, Value>& m)
64 {
65  typedef std::pair<std::string, Value> P;
66  BOOST_FOREACH (const P& p, m)
67  {
68  out << "\t"
69  << "key: " << p.first << std::endl
70  << "\t"
71  << "value: " << p.second << std::endl;
72  }
73  return out;
74 }
75 
76 template <typename Value>
77 std::ostream& operator<<(std::ostream& out, const std::multimap<std::string, Value>& m)
78 {
79  typedef std::pair<std::string, Value> P;
80  BOOST_FOREACH (const P& p, m)
81  {
82  out << "\t"
83  << "key: " << p.first << std::endl
84  << "\t"
85  << "value: " << p.second << std::endl;
86  }
87  return out;
88 }
89 
91 std::ostream& operator<<(std::ostream& out, const std::set<unsigned>& s);
93 std::ostream& operator<<(std::ostream& out, const std::set<std::string>& s);
94 
99 
101 {
102  public:
104 
108 
112 
117 
118 
119  void convert_to_v2_representation(pAcommsHandlerConfig* cfg);
120 
122 
123  template <typename Key> const google::protobuf::Descriptor* descriptor(const Key& k)
124  {
125  return to_iterator(k)->descriptor();
126  }
127 
130  unsigned message_count() { return messages_.size(); }
131 
133  template <typename Key> unsigned get_repeat(const Key& k) { return to_iterator(k)->repeat(); }
134 
136  std::set<unsigned> all_message_ids();
138  std::set<std::string> all_message_names();
140  template <typename Key> std::map<std::string, std::string> message_var_names(const Key& k) const
141  {
142  return to_iterator(k)->message_var_names();
143  }
144 
147  std::string id2name(unsigned id) { return to_iterator(id)->name(); }
150  unsigned name2id(const std::string& name) { return to_iterator(name)->id(); }
151 
153 
154  // returns a reference to all DCCLMessage objects.
155 
156  // this is only used if one needs more control than DCCLTransitionalCodec
157  // provides
158  std::vector<DCCLMessage>& messages() { return messages_; }
159 
160  // grab a reference to the manipulator manager used by the loaded XML messages
161  // const ManipulatorManager& manip_manager() const { return manip_manager_; }
162 
163  private:
164  void convert_xml_message_file(
165  const goby::transitional::protobuf::MessageFile& message_file, std::string* proto_file,
166  google::protobuf::RepeatedPtrField<goby::moos::protobuf::TranslatorEntry>*
167  translator_entries,
169 
170  void fill_create(
171  boost::shared_ptr<DCCLMessageVar> var,
172  std::map<std::string, goby::moos::protobuf::TranslatorEntry::CreateParser*>* parser_map,
174 
175  std::vector<DCCLMessage>::const_iterator to_iterator(const std::string& message_name) const;
176  std::vector<DCCLMessage>::iterator to_iterator(const std::string& message_name);
177  std::vector<DCCLMessage>::const_iterator to_iterator(const unsigned& id) const;
178  std::vector<DCCLMessage>::iterator to_iterator(const unsigned& id);
179 
180  void check_duplicates();
181 
182  private:
183  std::ostream* log_;
185 
186  std::vector<DCCLMessage> messages_;
187 
188  std::map<std::string, size_t> name2messages_;
189  std::map<unsigned, size_t> id2messages_;
190 
192 
193  boost::posix_time::ptime start_time_;
194 
195  // ManipulatorManager manip_manager_;
196 };
197 
198 } // namespace transitional
199 } // namespace goby
200 
201 #endif
provides an API to the Transitional Dynamic CCL Codec (looks like DCCLv1, but calls DCCLv2)...
unsigned name2id(const std::string &name)
The global namespace for the Goby project.
std::map< std::string, std::string > message_var_names(const Key &k) const