Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of rosserial_mbed_lib by
ros/subscriber.h@0:77afd7560544, 2011-08-19 (annotated)
- Committer:
- nucho
- Date:
- Fri Aug 19 09:06:30 2011 +0000
- Revision:
- 0:77afd7560544
- Child:
- 1:ff0ec969dad1
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nucho | 0:77afd7560544 | 1 | /* |
| nucho | 0:77afd7560544 | 2 | * subscriber.h |
| nucho | 0:77afd7560544 | 3 | * |
| nucho | 0:77afd7560544 | 4 | * Created on: Aug 5, 2011 |
| nucho | 0:77afd7560544 | 5 | * Author: astambler |
| nucho | 0:77afd7560544 | 6 | */ |
| nucho | 0:77afd7560544 | 7 | |
| nucho | 0:77afd7560544 | 8 | #ifndef SUBSCRIBER_H_ |
| nucho | 0:77afd7560544 | 9 | #define SUBSCRIBER_H_ |
| nucho | 0:77afd7560544 | 10 | |
| nucho | 0:77afd7560544 | 11 | #include "rosserial_ids.h" |
| nucho | 0:77afd7560544 | 12 | #include "msg_receiver.h" |
| nucho | 0:77afd7560544 | 13 | namespace ros{ |
| nucho | 0:77afd7560544 | 14 | |
| nucho | 0:77afd7560544 | 15 | /* ROS Subscriber |
| nucho | 0:77afd7560544 | 16 | * This class handles holding the msg so that |
| nucho | 0:77afd7560544 | 17 | * it is not continously reallocated. It is also used by the |
| nucho | 0:77afd7560544 | 18 | * node handle to keep track of callback functions and IDs. |
| nucho | 0:77afd7560544 | 19 | */ |
| nucho | 0:77afd7560544 | 20 | template<typename MsgT> |
| nucho | 0:77afd7560544 | 21 | class Subscriber: public MsgReceiver{ |
| nucho | 0:77afd7560544 | 22 | public: |
| nucho | 0:77afd7560544 | 23 | |
| nucho | 0:77afd7560544 | 24 | typedef void(*CallbackT)(const MsgT&); |
| nucho | 0:77afd7560544 | 25 | |
| nucho | 0:77afd7560544 | 26 | Subscriber(const char * topic_name, CallbackT msgCB){ |
| nucho | 0:77afd7560544 | 27 | topic_ = topic_name; |
| nucho | 0:77afd7560544 | 28 | cb_= msgCB; |
| nucho | 0:77afd7560544 | 29 | } |
| nucho | 0:77afd7560544 | 30 | MsgT msg; |
| nucho | 0:77afd7560544 | 31 | virtual void receive(unsigned char* data){ |
| nucho | 0:77afd7560544 | 32 | msg.deserialize(data); |
| nucho | 0:77afd7560544 | 33 | this->cb_(msg); |
| nucho | 0:77afd7560544 | 34 | } |
| nucho | 0:77afd7560544 | 35 | virtual const char * getMsgType(){return this->msg.getType();} |
| nucho | 0:77afd7560544 | 36 | virtual int _getType(){return TOPIC_SUBSCRIBERS;} |
| nucho | 0:77afd7560544 | 37 | private: |
| nucho | 0:77afd7560544 | 38 | CallbackT cb_; |
| nucho | 0:77afd7560544 | 39 | }; |
| nucho | 0:77afd7560544 | 40 | |
| nucho | 0:77afd7560544 | 41 | } |
| nucho | 0:77afd7560544 | 42 | #endif /* SUBSCRIBER_H_ */ |
