Goby v2
protobuf_pubsub_node_wrapper.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 PROTOBUFPUBSUBNODE20110506H
24 #define PROTOBUFPUBSUBNODE20110506H
25 
26 #include "goby/common/pubsub_node_wrapper.h"
27 #include "protobuf_node.h"
28 #include <boost/function.hpp>
29 
30 namespace goby
31 {
32 namespace pb
33 {
34 class StaticProtobufPubSubNodeWrapper : public common::PubSubNodeWrapper<google::protobuf::Message>
35 {
36  public:
40  {
41  }
42 
44 
45  template <typename ProtoBufMessage>
46  void subscribe(boost::function<void(const ProtoBufMessage&)> handler,
47  const std::string& group = "")
48  {
49  if (!using_pubsub())
50  {
51  glog.is(goby::common::logger::WARN) &&
52  glog << "Ignoring subscribe since we have `using_pubsub`=false" << std::endl;
53  return;
54  }
55  node_.subscribe<ProtoBufMessage>(SOCKET_SUBSCRIBE, handler, group);
56  }
57 
58  /* template<typename ProtoBufMessage> */
59  /* const ProtoBufMessage& newest() const */
60  /* { */
61  /* return node_.newest<ProtoBufMessage>(); */
62  /* } */
63 
64  private:
65  StaticProtobufNode& node_;
66 };
67 
68 class DynamicProtobufPubSubNodeWrapper : public common::PubSubNodeWrapper<google::protobuf::Message>
69 {
70  public:
74  {
75  }
76 
78 
79  private:
80  DynamicProtobufNode& node_;
81 };
82 
83 } // namespace pb
84 } // namespace goby
85 
86 #endif
common::FlexOstream glog
Access the Goby logger through this object.
The global namespace for the Goby project.
void subscribe(int socket_id, boost::function< void(const ProtoBufMessage &)> handler=boost::function< void(const ProtoBufMessage &)>(), const std::string &group="")
Subscribe to a message (of any type derived from google::protobuf::Message)