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.
Dependents: rosserial_mbed robot_S2
ros/subscriber.h@4:684f39d0c346, 2012-02-29 (annotated)
- Committer:
- nucho
- Date:
- Wed Feb 29 23:00:21 2012 +0000
- Revision:
- 4:684f39d0c346
- Parent:
- 3:1cf99502f396
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nucho | 1:ff0ec969dad1 | 1 | /* |
| nucho | 1:ff0ec969dad1 | 2 | * Software License Agreement (BSD License) |
| nucho | 1:ff0ec969dad1 | 3 | * |
| nucho | 1:ff0ec969dad1 | 4 | * Copyright (c) 2011, Willow Garage, Inc. |
| nucho | 1:ff0ec969dad1 | 5 | * All rights reserved. |
| nucho | 1:ff0ec969dad1 | 6 | * |
| nucho | 1:ff0ec969dad1 | 7 | * Redistribution and use in source and binary forms, with or without |
| nucho | 1:ff0ec969dad1 | 8 | * modification, are permitted provided that the following conditions |
| nucho | 1:ff0ec969dad1 | 9 | * are met: |
| nucho | 0:77afd7560544 | 10 | * |
| nucho | 1:ff0ec969dad1 | 11 | * * Redistributions of source code must retain the above copyright |
| nucho | 1:ff0ec969dad1 | 12 | * notice, this list of conditions and the following disclaimer. |
| nucho | 1:ff0ec969dad1 | 13 | * * Redistributions in binary form must reproduce the above |
| nucho | 1:ff0ec969dad1 | 14 | * copyright notice, this list of conditions and the following |
| nucho | 1:ff0ec969dad1 | 15 | * disclaimer in the documentation and/or other materials provided |
| nucho | 1:ff0ec969dad1 | 16 | * with the distribution. |
| nucho | 1:ff0ec969dad1 | 17 | * * Neither the name of Willow Garage, Inc. nor the names of its |
| nucho | 1:ff0ec969dad1 | 18 | * contributors may be used to endorse or promote prducts derived |
| nucho | 1:ff0ec969dad1 | 19 | * from this software without specific prior written permission. |
| nucho | 1:ff0ec969dad1 | 20 | * |
| nucho | 1:ff0ec969dad1 | 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| nucho | 1:ff0ec969dad1 | 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| nucho | 1:ff0ec969dad1 | 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| nucho | 1:ff0ec969dad1 | 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| nucho | 1:ff0ec969dad1 | 25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| nucho | 1:ff0ec969dad1 | 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| nucho | 1:ff0ec969dad1 | 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| nucho | 1:ff0ec969dad1 | 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| nucho | 1:ff0ec969dad1 | 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| nucho | 1:ff0ec969dad1 | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| nucho | 1:ff0ec969dad1 | 31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| nucho | 1:ff0ec969dad1 | 32 | * POSSIBILITY OF SUCH DAMAGE. |
| nucho | 0:77afd7560544 | 33 | */ |
| nucho | 0:77afd7560544 | 34 | |
| nucho | 1:ff0ec969dad1 | 35 | #ifndef ROS_SUBSCRIBER_H_ |
| nucho | 1:ff0ec969dad1 | 36 | #define ROS_SUBSCRIBER_H_ |
| nucho | 0:77afd7560544 | 37 | |
| nucho | 3:1cf99502f396 | 38 | #include "rosserial_msgs/TopicInfo.h" |
| nucho | 1:ff0ec969dad1 | 39 | |
| nucho | 1:ff0ec969dad1 | 40 | namespace ros { |
| nucho | 0:77afd7560544 | 41 | |
| nucho | 3:1cf99502f396 | 42 | /* Base class for objects subscribers. */ |
| nucho | 3:1cf99502f396 | 43 | class Subscriber_ |
| nucho | 3:1cf99502f396 | 44 | { |
| nucho | 3:1cf99502f396 | 45 | public: |
| nucho | 3:1cf99502f396 | 46 | virtual void callback(unsigned char *data)=0; |
| nucho | 3:1cf99502f396 | 47 | virtual int getEndpointType()=0; |
| nucho | 3:1cf99502f396 | 48 | |
| nucho | 3:1cf99502f396 | 49 | // id_ is set by NodeHandle when we advertise |
| nucho | 3:1cf99502f396 | 50 | int16_t id_; |
| nucho | 3:1cf99502f396 | 51 | |
| nucho | 3:1cf99502f396 | 52 | virtual const char * getMsgType()=0; |
| nucho | 3:1cf99502f396 | 53 | virtual const char * getMsgMD5()=0; |
| nucho | 3:1cf99502f396 | 54 | const char * topic_; |
| nucho | 3:1cf99502f396 | 55 | }; |
| nucho | 3:1cf99502f396 | 56 | |
| nucho | 3:1cf99502f396 | 57 | |
| nucho | 3:1cf99502f396 | 58 | /* Actual subscriber, templated on message type. */ |
| nucho | 1:ff0ec969dad1 | 59 | template<typename MsgT> |
| nucho | 3:1cf99502f396 | 60 | class Subscriber: public Subscriber_{ |
| nucho | 1:ff0ec969dad1 | 61 | public: |
| nucho | 0:77afd7560544 | 62 | typedef void(*CallbackT)(const MsgT&); |
| nucho | 1:ff0ec969dad1 | 63 | MsgT msg; |
| nucho | 0:77afd7560544 | 64 | |
| nucho | 3:1cf99502f396 | 65 | Subscriber(const char * topic_name, CallbackT cb, int endpoint=rosserial_msgs::TopicInfo::ID_SUBSCRIBER) : |
| nucho | 3:1cf99502f396 | 66 | cb_(cb), |
| nucho | 3:1cf99502f396 | 67 | endpoint_(endpoint) |
| nucho | 3:1cf99502f396 | 68 | { |
| nucho | 1:ff0ec969dad1 | 69 | topic_ = topic_name; |
| nucho | 3:1cf99502f396 | 70 | }; |
| nucho | 1:ff0ec969dad1 | 71 | |
| nucho | 3:1cf99502f396 | 72 | virtual void callback(unsigned char* data){ |
| nucho | 1:ff0ec969dad1 | 73 | msg.deserialize(data); |
| nucho | 1:ff0ec969dad1 | 74 | this->cb_(msg); |
| nucho | 0:77afd7560544 | 75 | } |
| nucho | 1:ff0ec969dad1 | 76 | |
| nucho | 3:1cf99502f396 | 77 | virtual const char * getMsgType(){ return this->msg.getType(); } |
| nucho | 3:1cf99502f396 | 78 | virtual const char * getMsgMD5(){ return this->msg.getMD5(); } |
| nucho | 3:1cf99502f396 | 79 | virtual int getEndpointType(){ return endpoint_; } |
| nucho | 1:ff0ec969dad1 | 80 | |
| nucho | 1:ff0ec969dad1 | 81 | private: |
| nucho | 1:ff0ec969dad1 | 82 | CallbackT cb_; |
| nucho | 3:1cf99502f396 | 83 | int endpoint_; |
| nucho | 1:ff0ec969dad1 | 84 | }; |
| nucho | 0:77afd7560544 | 85 | |
| nucho | 0:77afd7560544 | 86 | } |
| nucho | 1:ff0ec969dad1 | 87 | |
| nucho | 1:ff0ec969dad1 | 88 | #endif |