|
| template<class M > |
| Publisher | advertise (const std::string &topic, uint32_t queue_size=0) |
| | Create a Publisher. More...
|
| |
| template<class M > |
| void | publish (const std::string &topic, const M &message) |
| | publish a message without creating a publisher More...
|
| |
| Subscriber | subscribe (const std::string &topic, uint32_t queue_size, SvarFunction callback) |
| | subscribe a topic with callback function More...
|
| |
|
Subscriber | subscribe (const std::string &topic, SvarFunction callback, uint32_t queue_size=0) |
| | subscribe a topic with callback function
|
| |
|
template<class T , class M > |
| Subscriber | subscribe (const std::string &topic, uint32_t queue_size, void(T::*fp)(const std::shared_ptr< M > &), T *obj) |
| | subscribe a topic with callback member function
|
| |
|
template<class M > |
| Subscriber | subscribe (const std::string &topic, int queue_size, void(*fp)(const M &)) |
| | subscribe a topic with callback function
|
| |
|
template<class T , class M > |
| Subscriber | subscribe (const std::string &topic, uint32_t queue_size, void(T::*fp)(const M &), T *obj) |
| | subscribe a topic with callback member function
|
| |
|
std::vector< Publisher > | getPublishers () const |
| | get all publishers
|
| |
|
std::vector< Subscriber > | getSubscribers () const |
| | get all subscribers
|
| |
|
std::string | introduction (int width=80) const |
| | list all publishers and subscribers
|
| |
|
void | join (const Publisher &pub) |
| | Let the Publisher join this Messenger space.
|
| |
|
void | join (const Subscriber &sub) |
| | Let the Subscriber join this Messenger space.
|
| |
|
void | join (Messenger another) |
| | Let all publishers and subscribers left the old space.
|
| |
A tiny class implemented ROS like Pub/Sub messaging.
Messenger: A light-weight, efficient, thread-safe message publish and subscribe tool similar with ROS, a popular robot operating system.
The tool has the following features:
- Header only based on c++11, no extra dependency, makes it portable.
- Thread safe and support multi-thread condition notify mode by setting the queue size.
- Able to transfer any classes efficiently, including ROS defined messages, which means it can replace ROS messagging or work with it.
#include <GSLAM/core/Messenger.h>
int main(int argc,char** argv)
{
Subscriber sub=messenger.subscribe(
"topic_name",[](std::string msg){
std::cerr<<"Received string msg "<<msg<<std::endl;
});
messenger.publish("topic_name","hello world!");
Publisher pub=messenger.advertise<std::string>(
"topic_name");
return 0;
}
- Warning
- The Subscriber will auto shutdown, please hold the Subscriber instance until you want to unsubscribe.