24#ifndef GOBY_MIDDLEWARE_TRANSPORT_INTERTHREAD_H
25#define GOBY_MIDDLEWARE_TRANSPORT_INTERTHREAD_H
58 public Poller<InterThreadTransporter>
80 static_assert((
group.c_str() !=
nullptr) && (
group.c_str()[0] !=
'\0'),
81 "goby::middleware::Group must have non-zero length string to publish on the "
88 if ((
group.c_str() ==
nullptr) || (
group.c_str()[0] ==
'\0'))
89 throw(
goby::Exception(
"Group must have a non-empty string for use on InterThread"));
99 template <typename Data, int scheme = scheme<Data>()>
104 std::shared_ptr<Data> data_ptr(
new Data(data));
105 publish_dynamic<Data>(data_ptr,
group, publisher);
115 template <typename Data, int scheme = scheme<Data>()>
130 template <typename Data, int scheme = scheme<Data>()>
134 publish_dynamic<Data, scheme>(std::shared_ptr<const Data>(data),
group, publisher);
140 publish_dynamic<EmptyMessage>(
141 std::shared_ptr<EmptyMessage>(std::make_shared<EmptyMessage>()),
group);
150 template <typename Data, int scheme = scheme<Data>()>
156 group, std::this_thread::get_id(), data_mutex_,
167 template <typename Data, int scheme = scheme<Data>()>
180 subscribe_dynamic<EmptyMessage>([=](
const std::shared_ptr<const EmptyMessage>&) { f(); },
189 template <typename Data, int scheme = scheme<Data>()>
205 int _poll(std::unique_ptr<std::unique_lock<std::timed_mutex>>& lock)
212 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::condition_variable_any > cv()
access the condition variable used for poll synchronization
std::shared_ptr< std::timed_mutex > poll_mutex()
access the mutex 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 int poll_all(std::thread::id thread_id, std::unique_ptr< std::unique_lock< std::timed_mutex > > &lock)
static void unsubscribe_all(std::thread::id thread_id)
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_any > cv, std::shared_ptr< std::timed_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.