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.
Dependencies: rosserial_mbed_lib mbed Servo
Diff: ros/service_server.h
- Revision:
- 3:dff241b66f84
- Parent:
- 1:098e75fd5ad2
--- a/ros/service_server.h Sun Oct 16 09:33:53 2011 +0000
+++ b/ros/service_server.h Sat Nov 12 23:53:04 2011 +0000
@@ -32,46 +32,41 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef ROS_SERVICE_SERVER_H_
-#define ROS_SERVICE_SERVER_H_
+#ifndef _ROS_SERVICE_SERVER_H_
+#define _ROS_SERVICE_SERVER_H_
-#include "node_output.h"
+#include "rosserial_msgs/TopicInfo.h"
+
+#include "publisher.h"
+#include "subscriber.h"
namespace ros {
- template<typename SrvRequest , typename SrvResponse>
- class ServiceServer : MsgReceiver{
+ template<typename MReq , typename MRes>
+ class ServiceServer : public Subscriber_ {
public:
- typedef void(*CallbackT)(const SrvRequest&, SrvResponse&);
+ typedef void(*CallbackT)(const MReq&, MRes&);
- ServiceServer(const char* topic_name, CallbackT cb){
+ ServiceServer(const char* topic_name, CallbackT cb) :
+ pub(topic_name, &resp, rosserial_msgs::TopicInfo::ID_SERVICE_SERVER + rosserial_msgs::TopicInfo::ID_PUBLISHER)
+ {
this->topic_ = topic_name;
this->cb_ = cb;
}
- ServiceServer(ServiceServer& srv){
- this->topic_ = srv.topic_;
- this->cb_ = srv.cb_;
+ // these refer to the subscriber
+ virtual void callback(unsigned char *data){
+ req.deserialize(data);
+ cb_(req,resp);
+ pub.publish(&resp);
}
-
- virtual void receive(unsigned char * data){
- req.deserialize(data);
- this->cb_(req, resp);
- no_->publish(id_, &resp);
- }
+ virtual const char * getMsgType(){ return this->req.getType(); }
+ virtual const char * getMsgMD5(){ return this->req.getMD5(); }
+ virtual int getEndpointType(){ return rosserial_msgs::TopicInfo::ID_SERVICE_SERVER + rosserial_msgs::TopicInfo::ID_SUBSCRIBER; }
- virtual int _getType(){
- return 3;
- }
-
- virtual const char * getMsgType(){
- return req.getType();
- }
-
- SrvRequest req;
- SrvResponse resp;
- NodeOutput_ * no_;
-
+ MReq req;
+ MRes resp;
+ Publisher pub;
private:
CallbackT cb_;
};