Go to the documentation of this file.
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_;
void subscribe_empty(const std::function< void()> &f)
Subscribe with no data (used to receive a signal from another thread)
Defines the common interface for publishing and subscribing data using static (constexpr) groups on G...
The global namespace for the Goby project.
Class that holds additional metadata and callback functions related to a subscription (and is optiona...
std::recursive_mutex mutex
Utility class for allowing the various Goby middleware transporters to poll the underlying transport ...
goby::util::logger::GroupSetter group(std::string n)
Class that holds additional metadata and callback functions related to a publication (and is optional...
A transporter for the interthread layer.
static void unsubscribe(const Group &group, std::thread::id thread_id)
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)....
virtual ~InterThreadTransporter()
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)
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)....
static void publish(std::shared_ptr< const Data > data, const Group &group, const Publisher< Data > &publisher)
void check_validity_runtime(const Group &group)
Check validity of the Group for interthread use (for DynamicGroup at run time)
static void unsubscribe_all(std::thread::id thread_id)
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)....
static int poll_all(std::thread::id thread_id, std::unique_ptr< std::unique_lock< std::timed_mutex >> &lock)
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
std::shared_ptr< std::timed_mutex > poll_mutex()
access the mutex used for poll synchronization
static constexpr int scheme()
Scheme for interthread is always MarshallingScheme::CXX_OBJECT as the data are not serialized,...
std::shared_ptr< std::condition_variable_any > cv()
access the condition variable used for poll synchronization
void check_validity()
Check validity of the Group for interthread use (at compile time)
void publish_empty()
Publish with no data (used to signal another thread)
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)....
simple exception class for goby applications
static void remove(std::thread::id thread_id)
void unsubscribe_all()
Unsubscribe from all current subscriptions.
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< 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)....