23 #ifndef PROTOBUFNODE20110418H 24 #define PROTOBUFNODE20110418H 26 #include <boost/bind.hpp> 27 #include <boost/function.hpp> 28 #include <boost/unordered_map.hpp> 30 #include "goby/common/core_helpers.h" 31 #include "goby/common/logger.h" 32 #include "goby/util/dynamic_protobuf_manager.h" 34 #include "goby/common/node_interface.h" 35 #include "subscription.h" 51 virtual void protobuf_inbox(
const std::string& protobuf_type_name,
const std::string& body,
52 int socket_id,
const std::string& group) = 0;
55 void subscribe(
const std::string& identifier,
int socket_id);
56 void subscribe(
const std::string& protobuf_type_name,
int socket_id,
const std::string& group);
59 void inbox(common::MarshallingScheme marshalling_scheme,
const std::string& identifier,
60 const std::string& body,
int socket_id);
74 template <
typename ProtoBufMessage>
75 void subscribe(
int socket_id,
76 boost::function<
void(
const ProtoBufMessage&)> handler =
77 boost::function<
void(
const ProtoBufMessage&)>(),
78 const std::string& group =
"");
80 template <
typename ProtoBufMessage,
class C>
81 void subscribe(
int socket_id,
void (C::*mem_func)(
const ProtoBufMessage&), C* obj,
82 const std::string& group =
"")
84 subscribe<ProtoBufMessage>(socket_id, boost::bind(mem_func, obj, _1), group);
87 template <
typename ProtoBufMessage>
88 void on_receipt(
int socket_id,
89 boost::function<
void(
const ProtoBufMessage&)> handler =
90 boost::function<
void(
const ProtoBufMessage&)>(),
91 const std::string& group =
"");
93 template <
typename ProtoBufMessage,
class C>
94 void on_receipt(
int socket_id,
void (C::*mem_func)(
const ProtoBufMessage&), C* obj,
95 const std::string& group =
"")
97 on_receipt<ProtoBufMessage>(socket_id, boost::bind(mem_func, obj, _1), group);
102 ProtobufNode::send(msg, socket_id, group);
116 void protobuf_inbox(
const std::string& protobuf_type_name,
const std::string& body,
117 int socket_id,
const std::string& group);
122 boost::unordered_multimap<std::string, boost::shared_ptr<SubscriptionBase> > subscriptions_;
132 void subscribe(
int socket_id,
133 boost::function<
void(boost::shared_ptr<google::protobuf::Message> msg)> handler,
134 const std::string& group);
137 void subscribe(
int socket_id,
138 void (C::*mem_func)(boost::shared_ptr<google::protobuf::Message> msg), C* obj,
139 const std::string& group)
141 subscribe(socket_id, boost::bind(mem_func, obj, _1), group);
144 void on_receipt(
int socket_id,
145 boost::function<
void(boost::shared_ptr<google::protobuf::Message> msg)> handler,
146 const std::string& group);
149 void on_receipt(
int socket_id,
150 void (C::*mem_func)(boost::shared_ptr<google::protobuf::Message> msg), C* obj,
151 const std::string& group)
153 on_receipt(socket_id, boost::bind(mem_func, obj, _1), group);
159 void protobuf_inbox(
const std::string& protobuf_type_name,
const std::string& body,
160 int socket_id,
const std::string& group);
165 boost::unordered_multimap<
166 std::string, boost::function<void(boost::shared_ptr<google::protobuf::Message> msg)> >
173 template <
typename ProtoBufMessage>
174 void goby::pb::StaticProtobufNode::on_receipt(
176 boost::function<
void(
const ProtoBufMessage&)> handler
178 const std::string& group)
182 const std::string& protobuf_type_name = ProtoBufMessage::descriptor()->full_name();
184 glog.is(goby::common::logger::DEBUG1) &&
glog <<
"registering on_receipt handler for " 185 << protobuf_type_name << std::endl;
188 boost::shared_ptr<SubscriptionBase> subscription(
190 subscriptions_.insert(std::make_pair(protobuf_type_name, subscription));
193 template <
typename ProtoBufMessage>
195 boost::function<
void(
const ProtoBufMessage&)> handler
197 const std::string& group)
199 const std::string& protobuf_type_name = ProtoBufMessage::descriptor()->full_name();
200 on_receipt(socket_id, handler, group);
202 glog.is(goby::common::logger::DEBUG1) &&
glog <<
"subscribing for " << protobuf_type_name
205 ProtobufNode::subscribe(protobuf_type_name, socket_id, group);
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)