24#ifndef GOBY_MIDDLEWARE_TRANSPORT_INTERTHREAD_H
25#define GOBY_MIDDLEWARE_TRANSPORT_INTERTHREAD_H
58 public Poller<InterThreadTransporter>
82 static_assert((
group.c_str() !=
nullptr) && (
group.c_str()[0] !=
'\0'),
83 "goby::middleware::Group must have non-zero length string to publish on the "
90 if ((
group.c_str() ==
nullptr) || (
group.c_str()[0] ==
'\0'))
91 throw(
goby::Exception(
"Group must have a non-empty string for use on InterThread"));
101 template <typename Data, int scheme = scheme<Data>()>
106 std::shared_ptr<Data> data_ptr(
new Data(data));
107 publish_dynamic<Data>(data_ptr,
group, publisher);
117 template <typename Data, int scheme = scheme<Data>()>
132 template <typename Data, int scheme = scheme<Data>()>
136 publish_dynamic<Data, scheme>(std::shared_ptr<const Data>(data),
group, publisher);
142 publish_dynamic<EmptyMessage>(
143 std::shared_ptr<EmptyMessage>(std::make_shared<EmptyMessage>()),
group);
152 template <typename Data, int scheme = scheme<Data>()>
158 group, std::this_thread::get_id(), data_mutex_,
169 template <typename Data, int scheme = scheme<Data>()>
182 subscribe_dynamic<EmptyMessage>([=](
const std::shared_ptr<const EmptyMessage>&) { f(); },
191 template <typename Data, int scheme = scheme<Data>()>
207 int _poll(std::unique_ptr<std::unique_lock<std::mutex>>& lock)
214 std::shared_ptr<std::mutex> data_mutex_;
simple exception class for goby applications
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
A transporter for the interthread layer.
void subscribe_dynamic(std::function< void(const Data &)> f, const Group &group, const Subscriber< Data > &=Subscriber< Data >())
Subscribe to a specific run-time defined group and data type (const reference variant)....
void check_validity()
Check validity of the Group for interthread use (at compile time)
void unsubscribe_dynamic(const Group &group, const Subscriber< Data > &=Subscriber< Data >())
Unsubscribe to a specific run-time defined group and data type. Where possible, prefer the static var...
void publish_dynamic(std::shared_ptr< Data > data, const Group &group, const Publisher< Data > &publisher=Publisher< Data >())
Publish a message using a run-time defined DynamicGroup (shared pointer to mutable data variant)....
void check_validity_runtime(const Group &group)
Check validity of the Group for interthread use (for DynamicGroup at run time)
void publish_dynamic(std::shared_ptr< const Data > data, const Group &group, const Publisher< Data > &publisher=Publisher< Data >())
Publish a message using a run-time defined DynamicGroup (shared pointer to const data variant)....
void subscribe_empty(const std::function< void()> &f)
Subscribe with no data (used to receive a signal from another thread)
void unsubscribe_all()
Unsubscribe from all current subscriptions.
void publish_dynamic(const Data &data, const Group &group, const Publisher< Data > &publisher=Publisher< Data >())
Publish a message using a run-time defined DynamicGroup (const reference variant)....
void subscribe_dynamic(std::function< void(std::shared_ptr< const Data >)> f, const Group &group, const Subscriber< Data > &=Subscriber< Data >())
Subscribe to a specific run-time defined group and data type (shared pointer variant)....
void publish_empty()
Publish with no data (used to signal another thread)
static constexpr int scheme()
Scheme for interthread is always MarshallingScheme::CXX_OBJECT as the data are not serialized,...
virtual ~InterThreadTransporter()
std::shared_ptr< std::mutex > poll_mutex()
access the mutex used for poll synchronization
std::shared_ptr< std::condition_variable > cv()
access the condition variable used for poll synchronization
Utility class for allowing the various Goby middleware transporters to poll the underlying transport ...
Class that holds additional metadata and callback functions related to a publication (and is optional...
Defines the common interface for publishing and subscribing data using static (constexpr) groups on G...
Class that holds additional metadata and callback functions related to a subscription (and is optiona...
static void remove(std::thread::id thread_id)
static void unsubscribe_all(std::thread::id thread_id)
static int poll_all(std::thread::id thread_id, std::unique_ptr< std::unique_lock< std::mutex > > &lock)
static void subscribe(std::function< void(std::shared_ptr< const Data >)> func, const Group &group, std::thread::id thread_id, std::shared_ptr< std::mutex > data_mutex, std::shared_ptr< std::condition_variable > cv, std::shared_ptr< std::mutex > poller_mutex)
static void unsubscribe(const Group &group, std::thread::id thread_id)
static void publish(std::shared_ptr< const Data > data, const Group &group, const Publisher< Data > &publisher)
goby::util::logger::GroupSetter group(std::string n)
The global namespace for the Goby project.