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/condition_variable.hpp>
41 #include <boost/thread/mutex.hpp>
42 #include <boost/shared_array.hpp>
43 #include <boost/enable_shared_from_this.hpp>
44 #include <boost/thread.hpp>
45 
46 #include <queue>
47 
48 namespace ros
49 {
50 class Header;
51 class Message;
52 class Connection;
54 
59 class ROSCPP_DECL ServiceServerLink : public boost::enable_shared_from_this<ServiceServerLink>
60 {
61 private:
62  struct CallInfo
63  {
66 
67  bool finished_;
68  boost::condition_variable finished_condition_;
69  boost::mutex finished_mutex_;
70  boost::thread::id caller_thread_id_;
71 
72  bool success_;
74 
75  std::string exception_string_;
76  };
78  typedef std::queue<CallInfoPtr> Q_CallInfo;
79 
80 public:
81  typedef std::map<std::string, std::string> M_string;
82  ServiceServerLink(const std::string& service_name, bool persistent, const std::string& request_md5sum, const std::string& response_md5sum, const M_string& header_values);
83  virtual ~ServiceServerLink();
84 
85  //
86  bool initialize(const ConnectionPtr& connection);
87 
91  bool isValid() const;
95  bool isPersistent() const { return persistent_; }
96 
97  const ConnectionPtr& getConnection() const { return connection_; }
98 
99  const std::string& getServiceName() const { return service_name_; }
100  const std::string& getRequestMD5Sum() const { return request_md5sum_; }
101  const std::string& getResponseMD5Sum() const { return response_md5sum_; }
102 
109  bool call(const SerializedMessage& req, SerializedMessage& resp);
110 
111 private:
112  void onConnectionDropped(const ConnectionPtr& conn);
113  bool onHeaderReceived(const ConnectionPtr& conn, const Header& header);
114 
119  void callFinished();
124  void processNextCall();
128  void clearCalls();
132  void cancelCall(const CallInfoPtr& info);
133 
134  void onHeaderWritten(const ConnectionPtr& conn);
135  void onRequestWritten(const ConnectionPtr& conn);
136  void onResponseOkAndLength(const ConnectionPtr& conn, const boost::shared_array<uint8_t>& buffer, uint32_t size, bool success);
137  void onResponse(const ConnectionPtr& conn, const boost::shared_array<uint8_t>& buffer, uint32_t size, bool success);
138 
139  ConnectionPtr connection_;
140  std::string service_name_;
142  std::string request_md5sum_;
143  std::string response_md5sum_;
144 
148 
149  Q_CallInfo call_queue_;
150  boost::mutex call_queue_mutex_;
151 
152  CallInfoPtr current_call_;
153 
154  bool dropped_;
155 };
157 
158 } // namespace ros
159 
160 #endif // ROSCPP_SERVICE_SERVER_LINK_H
161 
162 
163 
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 Mar 22 2020 03:20:34