service_server.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef _ROS_SERVICE_SERVER_H_
19 #define _ROS_SERVICE_SERVER_H_
20 
22 
23 #include "publisher.h"
24 #include "subscriber.h"
25 
26 namespace ros {
27 
28  template<typename MReq , typename MRes>
29  class ServiceServer : public Subscriber_ {
30  public:
31  typedef void(*CallbackT)(const MReq&, MRes&);
32 
33  ServiceServer(const char* topic_name, CallbackT cb) :
34  pub(topic_name, &resp, rosserial_msgs::TopicInfo::ID_SERVICE_SERVER + rosserial_msgs::TopicInfo::ID_PUBLISHER)
35  {
36  this->topic_ = topic_name;
37  this->cb_ = cb;
38  }
39 
40  // these refer to the subscriber
41  virtual void callback(unsigned char *data){
42  req.deserialize(data);
43  cb_(req,resp);
44  pub.publish(&resp);
45  }
46  virtual const char * getMsgType(){ return this->req.getType(); }
47  virtual const char * getMsgMD5(){ return this->req.getMD5(); }
49 
50  MReq req;
51  MRes resp;
52  Publisher pub;
53  private:
54  CallbackT cb_;
55  };
56 
57 }
58 
59 #endif
void publish(const boost::shared_ptr< M > &message) const
const char * topic_
Definition: subscriber.h:37


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Tue Oct 20 2020 03:35:57