Personal fork
Fork of rosserial_mbed_lib by
ros/service_server.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 | * service_server.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 | |
nucho | 0:77afd7560544 | 9 | #ifndef SERVICE_SERVER_H_ |
nucho | 0:77afd7560544 | 10 | #define SERVICE_SERVER_H_ |
nucho | 0:77afd7560544 | 11 | |
nucho | 0:77afd7560544 | 12 | |
nucho | 0:77afd7560544 | 13 | #include "node_output.h" |
nucho | 0:77afd7560544 | 14 | |
nucho | 0:77afd7560544 | 15 | namespace ros{ |
nucho | 0:77afd7560544 | 16 | template<typename SrvRequest , typename SrvResponse> |
nucho | 0:77afd7560544 | 17 | class ServiceServer : MsgReceiver{ |
nucho | 0:77afd7560544 | 18 | public: |
nucho | 0:77afd7560544 | 19 | typedef void(*CallbackT)(const SrvRequest&, SrvResponse&); |
nucho | 0:77afd7560544 | 20 | |
nucho | 0:77afd7560544 | 21 | private: |
nucho | 0:77afd7560544 | 22 | CallbackT cb_; |
nucho | 0:77afd7560544 | 23 | |
nucho | 0:77afd7560544 | 24 | public: |
nucho | 0:77afd7560544 | 25 | ServiceServer(const char* topic_name, CallbackT cb){ |
nucho | 0:77afd7560544 | 26 | this->topic_ = topic_name; |
nucho | 0:77afd7560544 | 27 | this->cb_ = cb; |
nucho | 0:77afd7560544 | 28 | } |
nucho | 0:77afd7560544 | 29 | |
nucho | 0:77afd7560544 | 30 | ServiceServer(ServiceServer& srv){ |
nucho | 0:77afd7560544 | 31 | this->topic_ = srv.topic_; |
nucho | 0:77afd7560544 | 32 | this->cb_ = srv.cb_; |
nucho | 0:77afd7560544 | 33 | } |
nucho | 0:77afd7560544 | 34 | virtual void receive(unsigned char * data){ |
nucho | 0:77afd7560544 | 35 | req.deserialize(data); |
nucho | 0:77afd7560544 | 36 | this->cb_(req, resp); |
nucho | 0:77afd7560544 | 37 | no_->publish(id_, &resp); |
nucho | 0:77afd7560544 | 38 | } |
nucho | 0:77afd7560544 | 39 | |
nucho | 0:77afd7560544 | 40 | virtual int _getType(){ |
nucho | 0:77afd7560544 | 41 | return 3; |
nucho | 0:77afd7560544 | 42 | } |
nucho | 0:77afd7560544 | 43 | virtual const char * getMsgType(){ |
nucho | 0:77afd7560544 | 44 | return req.getType(); |
nucho | 0:77afd7560544 | 45 | } |
nucho | 0:77afd7560544 | 46 | |
nucho | 0:77afd7560544 | 47 | SrvRequest req; |
nucho | 0:77afd7560544 | 48 | SrvResponse resp; |
nucho | 0:77afd7560544 | 49 | NodeOutput_ * no_; |
nucho | 0:77afd7560544 | 50 | |
nucho | 0:77afd7560544 | 51 | }; |
nucho | 0:77afd7560544 | 52 | } |
nucho | 0:77afd7560544 | 53 | |
nucho | 0:77afd7560544 | 54 | #endif /* SERVICE_SERVER_H_ */ |