25#ifndef GOBY_MIDDLEWARE_TRANSPORT_INTERTHREAD_H
26#define GOBY_MIDDLEWARE_TRANSPORT_INTERTHREAD_H
59 public Poller<InterThreadTransporter>
83 static_assert((
group.c_str() !=
nullptr) && (
group.c_str()[0] !=
'\0'),
84 "goby::middleware::Group must have non-zero length string to publish on the "
91 if ((
group.c_str() ==
nullptr) || (
group.c_str()[0] ==
'\0'))
92 throw(
goby::Exception(
"Group must have a non-empty string for use on InterThread"));
102 template <typename Data, int scheme = scheme<Data>()>
107 std::shared_ptr<Data> data_ptr(
new Data(data));
118 template <typename Data, int scheme = scheme<Data>()>
133 template <typename Data, int scheme = scheme<Data>()>
144 std::shared_ptr<EmptyMessage>(std::make_shared<EmptyMessage>()),
group);
153 template <typename Data, int scheme = scheme<Data>()>
159 group, std::this_thread::get_id(), data_mutex_,
170 template <typename Data, int scheme = scheme<Data>()>
192 template <typename Data, int scheme = scheme<Data>()>
208 int _poll(std::unique_ptr<std::unique_lock<std::mutex>>& lock)
215 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,...
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 ...
Poller(PollerInterface *inner_poller=nullptr)
Class that holds additional metadata and callback functions related to a publication (and is optional...
StaticTransporterInterface(NullTransporter &inner)
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)
Objects implementing the Goby nested middleware.
The global namespace for the Goby project.