service_server_link.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef ROSCPP_SERVICE_SERVER_LINK_H
36 #define ROSCPP_SERVICE_SERVER_LINK_H
37 
38 #include "ros/common.h"
39 
40 #include <boost/thread/mutex.hpp>
41 #include <boost/shared_array.hpp>
42 #include <boost/enable_shared_from_this.hpp>
43 #include <boost/thread.hpp>
44 
45 #include <queue>
46 
47 namespace ros
48 {
49 class Header;
50 class Message;
51 class Connection;
53 
58 class ROSCPP_DECL ServiceServerLink : public boost::enable_shared_from_this<ServiceServerLink>
59 {
60 private:
61  struct CallInfo
62  {
65 
66  bool finished_;
68  boost::mutex finished_mutex_;
69  boost::thread::id caller_thread_id_;
70 
71  bool success_;
73 
74  std::string exception_string_;
75  };
77  typedef std::queue<CallInfoPtr> Q_CallInfo;
78 
79 public:
80  typedef std::map<std::string, std::string> M_string;
81  ServiceServerLink(const std::string& service_name, bool persistent, const std::string& request_md5sum, const std::string& response_md5sum, const M_string& header_values);
82  virtual ~ServiceServerLink();
83 
84  //
85  bool initialize(const ConnectionPtr& connection);
86 
90  bool isValid() const;
94  bool isPersistent() const { return persistent_; }
95 
96  const ConnectionPtr& getConnection() const { return connection_; }
97 
98  const std::string& getServiceName() const { return service_name_; }
99  const std::string& getRequestMD5Sum() const { return request_md5sum_; }
100  const std::string& getResponseMD5Sum() const { return response_md5sum_; }
101 
108  bool call(const SerializedMessage& req, SerializedMessage& resp);
109 
110 private:
111  void onConnectionDropped(const ConnectionPtr& conn);
112  bool onHeaderReceived(const ConnectionPtr& conn, const Header& header);
113 
118  void callFinished();
123  void processNextCall();
127  void clearCalls();
131  void cancelCall(const CallInfoPtr& info);
132 
133  void onHeaderWritten(const ConnectionPtr& conn);
134  void onRequestWritten(const ConnectionPtr& conn);
135  void onResponseOkAndLength(const ConnectionPtr& conn, const boost::shared_array<uint8_t>& buffer, uint32_t size, bool success);
136  void onResponse(const ConnectionPtr& conn, const boost::shared_array<uint8_t>& buffer, uint32_t size, bool success);
137 
138  ConnectionPtr connection_;
139  std::string service_name_;
141  std::string request_md5sum_;
142  std::string response_md5sum_;
143 
147 
148  Q_CallInfo call_queue_;
149  boost::mutex call_queue_mutex_;
150 
151  CallInfoPtr current_call_;
152 
153  bool dropped_;
154 };
156 
157 } // namespace ros
158 
159 #endif // ROSCPP_SERVICE_SERVER_LINK_H
160 
161 
162 
ROSCONSOLE_DECL void initialize()
bool call(const std::string &service_name, MReq &req, MRes &res)
Invoke an RPC service.
Definition: service.h:65
boost::shared_ptr< Connection > ConnectionPtr
Definition: connection.h:57
boost::shared_ptr< ServiceServerLink > ServiceServerLinkPtr
Definition: forwards.h:85
const std::string header


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Sun Feb 3 2019 03:29:54