Go to the documentation of this file.
25 #ifndef GOBY_MIDDLEWARE_TRANSPORT_SERIALIZATION_HANDLERS_H
26 #define GOBY_MIDDLEWARE_TRANSPORT_SERIALIZATION_HANDLERS_H
32 #include <unordered_map>
55 template <
typename Metadata>
57 typename std::
enable_if_t<std::is_void<Metadata>::value>>
63 virtual std::string::const_iterator post(std::string::const_iterator b,
64 std::string::const_iterator
e)
const = 0;
65 #ifndef _LIBCPP_VERSION
66 virtual std::vector<char>::const_iterator post(std::vector<char>::const_iterator b,
67 std::vector<char>::const_iterator
e)
const = 0;
69 virtual const char* post(
const char* b,
const char*
e)
const = 0;
73 template <
typename Metadata>
75 typename std::
enable_if_t<!std::is_void<Metadata>::value>>
81 virtual std::string::const_iterator post(std::string::const_iterator b,
82 std::string::const_iterator
e,
83 const Metadata& metadata)
const = 0;
84 #ifndef _LIBCPP_VERSION
85 virtual std::vector<char>::const_iterator post(std::vector<char>::const_iterator b,
86 std::vector<char>::const_iterator
e,
87 const Metadata& metadata)
const = 0;
89 virtual const char* post(
const char* b,
const char*
e,
const Metadata& metadata)
const = 0;
95 template <
typename Metadata =
void>
102 virtual const std::string&
type_name()
const = 0;
105 virtual int scheme()
const = 0;
115 std::thread::id
thread_id()
const {
return thread_id_; }
119 const std::thread::id thread_id_{std::this_thread::get_id()};
123 template <
typename Metadata>
135 template <
typename Data,
int scheme_
id>
147 subscriber_(subscriber)
152 std::string::const_iterator
post(std::string::const_iterator b,
153 std::string::const_iterator
e)
const override
158 #ifndef _LIBCPP_VERSION
159 std::vector<char>::const_iterator
post(std::vector<char>::const_iterator b,
160 std::vector<char>::const_iterator
e)
const override
166 const char*
post(
const char* b,
const char*
e)
const override {
return _post(b,
e); }
174 const std::string&
type_name()
const override {
return type_name_; }
176 int scheme()
const override {
return scheme_id; }
179 template <
typename CharIterator>
180 CharIterator _post(CharIterator bytes_begin, CharIterator bytes_end)
const
182 CharIterator actual_end;
184 actual_end, type_name_);
194 const std::string type_name_;
196 Subscriber<Data> subscriber_;
203 template <
typename Data,
int scheme_
id>
216 subscriber_(subscriber)
221 std::string::const_iterator
post(std::string::const_iterator b, std::string::const_iterator
e,
224 return _post(b,
e, header);
227 #ifndef _LIBCPP_VERSION
228 std::vector<char>::const_iterator
229 post(std::vector<char>::const_iterator b, std::vector<char>::const_iterator
e,
232 return _post(b,
e, header);
236 const char*
post(
const char* b,
const char*
e,
239 return _post(b,
e, header);
250 const std::string&
type_name()
const override {
return type_name_; }
252 int scheme()
const override {
return scheme_id; }
255 template <
typename CharIterator>
256 CharIterator _post(CharIterator bytes_begin, CharIterator bytes_end,
259 CharIterator actual_end;
261 actual_end, type_name_);
263 subscriber_.set_link_data(*
msg, header);
273 const std::string type_name_;
275 Subscriber<Data> subscriber_;
279 template <
typename Data,
int scheme_
id,
typename Metadata>
296 std::string::const_iterator
post(std::string::const_iterator b, std::string::const_iterator
e,
297 const Metadata& md)
const override
299 return _post(b,
e, md);
302 #ifndef _LIBCPP_VERSION
303 std::vector<char>::const_iterator
post(std::vector<char>::const_iterator b,
304 std::vector<char>::const_iterator
e,
305 const Metadata& md)
const override
307 return _post(b,
e, md);
311 const char*
post(
const char* b,
const char*
e,
const Metadata& md)
const override
313 return _post(b,
e, md);
322 const std::string&
type_name()
const override {
return type_name_; }
324 int scheme()
const override {
return scheme_id; }
327 template <
typename CharIterator>
328 CharIterator _post(CharIterator bytes_begin, CharIterator bytes_end,
const Metadata& md)
const
330 CharIterator actual_end;
332 actual_end, type_name_);
341 const std::string type_name_;
349 template <
typename Data,
int scheme_
id>
358 std::string::const_iterator
post(std::string::const_iterator b,
359 std::string::const_iterator
e)
const override
364 #ifndef _LIBCPP_VERSION
365 std::vector<char>::const_iterator
post(std::vector<char>::const_iterator b,
366 std::vector<char>::const_iterator
e)
const override
372 const char*
post(
const char* b,
const char*
e)
const override
383 const std::string&
type_name()
const override {
return type_name_; }
385 int scheme()
const override {
return scheme_id; }
388 const std::string type_name_;
396 typedef std::function<
void(
const std::vector<unsigned char>&,
int scheme,
401 const std::string& type_regex =
".*",
402 const std::string& group_regex =
".*")
403 : handler_(handler), schemes_(schemes), type_regex_(type_regex), group_regex_(group_regex)
412 template <
typename CharIterator>
413 bool post(CharIterator bytes_begin, CharIterator bytes_end,
int scheme,
const std::string&
type,
414 const std::string&
group)
const
417 schemes_.count(
scheme)) &&
418 std::regex_match(
type, type_regex_) && std::regex_match(
group, group_regex_))
420 std::vector<unsigned char> data(bytes_begin, bytes_end);
430 std::thread::id
thread_id()
const {
return thread_id_; }
435 const std::set<int> schemes_;
436 std::regex type_regex_;
437 std::regex group_regex_;
438 const std::thread::id thread_id_{std::this_thread::get_id()};
446 std::thread::id
thread_id()
const {
return thread_id_; }
450 const std::thread::id thread_id_{std::this_thread::get_id()};
462 : handler_(handler), sub_cfg_(sub), group_(sub_cfg_.key().
group()), subscriber_id_(sub.id())
467 std::string::const_iterator
post(std::string::const_iterator b,
468 std::string::const_iterator
e)
const override
473 #ifndef _LIBCPP_VERSION
474 std::vector<char>::const_iterator
post(std::vector<char>::const_iterator b,
475 std::vector<char>::const_iterator
e)
const override
481 const char*
post(
const char* b,
const char*
e)
const override {
return _post(b,
e); }
485 switch (sub_cfg_.
action())
504 template <
typename CharIterator>
505 CharIterator _post(CharIterator bytes_begin, CharIterator bytes_end)
const
508 std::string* sbytes =
new std::string(bytes_begin, bytes_end);
509 *
msg.mutable_key() = sub_cfg_.
key();
510 msg.set_allocated_data(sbytes);
513 CharIterator actual_end = bytes_end;
519 intermodule::protobuf::Subscription sub_cfg_;
521 const std::thread::id thread_id_;
522 const std::string subscriber_id_;
Selector class for enabling SerializationHandlerBase::post() override signature based on whether the ...
const std::string & type_name() const override
const std::string & type_name() const override
static std::shared_ptr< DataType > parse(CharIterator bytes_begin, CharIterator bytes_end, CharIterator &actual_end, const std::string &type=type_name())
Given a beginning and end iterator to bytes, parse the data and return it.
const char * post(const char *b, const char *e) const override
const std::string & type_name() const override
virtual const Group & subscribed_group() const =0
SerializationInterModuleSubscription(HandlerType handler, const intermodule::protobuf::Subscription sub)
std::thread::id thread_id() const
static const Action UNSUBSCRIBE_ALL
std::string subscriber_id() const
The global namespace for the Goby project.
Class for parsing and serializing a given marshalling scheme. Must be specialized for a particular sc...
SerializationHandlerBase ::SubscriptionAction action() const override
std::vector< char >::const_iterator post(std::vector< char >::const_iterator b, std::vector< char >::const_iterator e, const intervehicle::protobuf::Header &header) const override
const char * post(const char *b, const char *e, const Metadata &md) const override
PublisherCallback(HandlerType handler)
Class that holds additional metadata and callback functions related to a subscription (and is optiona...
const ::goby::middleware::protobuf::SerializerTransporterKey & key() const
Represents a subscription to a serialized data type (interprocess layer).
const char * post(const char *b, const char *e) const override
std::function< void(const protobuf::SerializerTransporterMessage &d)> HandlerType
std::string::const_iterator post(std::string::const_iterator b, std::string::const_iterator e) const override
::goby::middleware::intermodule::protobuf::Subscription_Action action() const
const Group & subscribed_group() const override
const std::string & type_name() const override
const ::std::string & type() const
std::thread::id thread_id() const
goby::util::logger::GroupSetter group(std::string n)
std::function< void(std::shared_ptr< const Data > data)> HandlerType
std::string subscriber_id() const
const std::string & type_name() const override
std::string::const_iterator post(std::string::const_iterator b, std::string::const_iterator e, const intervehicle::protobuf::Header &header) const override
void update_type_regex(const std::string &type_regex)
int scheme() const override
Represents a subscription to a serialized data type (intervehicle layer).
std::thread::id thread_id() const
Represents a regex subscription to a serialized data type (interprocess and outer layers).
std::string::const_iterator post(std::string::const_iterator b, std::string::const_iterator e) const override
std::string thread_id(std::thread::id i=std::this_thread::get_id())
std::function< void(const std::vector< unsigned char > &, int scheme, const std::string &type, const Group &group)> HandlerType
virtual std::string subscriber_id() const
bool operator==(const Group &a, const Group &b)
bool post(CharIterator bytes_begin, CharIterator bytes_end, int scheme, const std::string &type, const std::string &group) const
const char * post(const char *b, const char *e) const override
std::vector< char >::const_iterator post(std::vector< char >::const_iterator b, std::vector< char >::const_iterator e, const Metadata &md) const override
virtual ~SerializationHandlerBase()=default
static const Action UNSUBSCRIBE
SerializationUnSubscription(const Group &group)
SerializationHandlerBase< intervehicle::protobuf::Header >::SubscriptionAction action() const override
Base class for handling posting callbacks for serialized data types (interprocess and outer)
SerializationSubscription(HandlerType handler, const Group &group=Group(Group::broadcast_group), const Subscriber< Data > &subscriber=Subscriber< Data >())
SerializationHandlerBase()=default
SerializationHandlerBase< Metadata >::SubscriptionAction action() const override
virtual int scheme() const =0
std::vector< char >::const_iterator post(std::vector< char >::const_iterator b, std::vector< char >::const_iterator e) const override
type
Generic JSON types used in JWTs.
const Group & subscribed_group() const override
extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, ::google::protobuf::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg
std::vector< char >::const_iterator post(std::vector< char >::const_iterator b, std::vector< char >::const_iterator e) const override
Represents a(n) (un)subscription from an InterModuleForwarder.
::google::protobuf::int32 marshalling_scheme() const
int scheme() const override
int scheme() const override
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
const Group & subscribed_group() const override
SerializationHandlerBase ::SubscriptionAction action() const override
std::function< void(std::shared_ptr< const Data > data)> HandlerType
const char * post(const char *b, const char *e, const intervehicle::protobuf::Header &header) const override
static const Action SUBSCRIBE
const Group & subscribed_group() const override
int scheme() const override
static constexpr std::uint32_t broadcast_group
Special group number representing the broadcast group (used when no grouping is required for a given ...
std::string::const_iterator post(std::string::const_iterator b, std::string::const_iterator e, const Metadata &md) const override
constexpr int scheme()
Placeholder to provide an interface for the scheme() function family.
Represents an unsubscription to a serialized data type (interprocess and outer layers).
PublisherCallback(HandlerType handler, const Data &data)
simple exception class for goby applications
SerializationSubscriptionRegex(HandlerType handler, const std::set< int > &schemes, const std::string &type_regex=".*", const std::string &group_regex=".*")
IntervehicleSerializationSubscription(HandlerType handler, const Group &group=Group(Group::broadcast_group), const Subscriber< Data > &subscriber=Subscriber< Data >())
virtual const std::string & type_name() const =0
std::function< void(const Data &data, const Metadata &md)> HandlerType
std::vector< char >::const_iterator post(std::vector< char >::const_iterator b, std::vector< char >::const_iterator e) const override
int scheme() const override
void update_group_regex(const std::string &group_regex)
const Group & subscribed_group() const override
std::string subscriber_id() const override
Implementation of Group for dynamic (run-time) instantiations. Use Group directly for static (compile...
std::string::const_iterator post(std::string::const_iterator b, std::string::const_iterator e) const override
SerializationHandlerBase ::SubscriptionAction action() const override
Represents an unsubscription to all subscribed data for a given thread.
Represents a callback for a published data type (e.g. acked_func or expired_func)
typename std::enable_if< B, T >::type enable_if_t
virtual SubscriptionAction action() const =0