service_server_link.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2008, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Willow Garage, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef ROSCPP_SERVICE_SERVER_LINK_H
37 #define ROSCPP_SERVICE_SERVER_LINK_H
38 
39 #include "ros/common.h"
40 
41 #include <mutex>
42 //#include <boost/shared_array.hpp>
43 #include <memory>
44 #include <thread>
45 
46 #include <queue>
47 
48 namespace roswrap
49 {
50 class Header;
51 class Message;
52 class Connection;
53 typedef std::shared_ptr<Connection> ConnectionPtr;
54 
59 class ROSCPP_DECL ServiceServerLink : public std::enable_shared_from_this<ServiceServerLink>
60 {
61 private:
62  struct CallInfo
63  {
66 
67  bool finished_;
68  std::condition_variable finished_condition_;
69  std::mutex finished_mutex_;
70  std::thread::id caller_thread_id_;
71 
72  bool success_;
74 
75  std::string exception_string_;
76  };
77  typedef std::shared_ptr<CallInfo> CallInfoPtr;
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 
140  std::string service_name_;
142  std::string request_md5sum_;
143  std::string response_md5sum_;
144 
148 
150  std::mutex call_queue_mutex_;
151 
153 
154  bool dropped_;
155 };
156 typedef std::shared_ptr<ServiceServerLink> ServiceServerLinkPtr;
157 
158 } // namespace roswrap
159 
160 #endif // ROSCPP_SERVICE_SERVER_LINK_H
161 
162 
163 
roswrap::ConnectionPtr
std::shared_ptr< Connection > ConnectionPtr
Definition: connection.h:58
Header
roswrap::console::initialize
ROSCONSOLE_DECL void initialize()
Don't call this directly. Performs any required initialization/configuration. Happens automatically w...
Definition: rossimu.cpp:235
roswrap::SerializedMessage
Definition: serialized_message.h:40
boost::shared_array< uint8_t >
roswrap
Definition: param_modi.cpp:41
roswrap::ServiceServerLinkPtr
std::shared_ptr< ServiceServerLink > ServiceServerLinkPtr
Definition: forwards.h:87
roswrap::Header
Provides functionality to parse a connection header and retrieve values from it.
Definition: header.h:53
sick_scan_base.h
roswrap::message_traits::header
std_msgs::Header * header(M &m)
returns Header<M>::pointer(m);
Definition: message_traits.h:281
ROSCPP_DECL
#define ROSCPP_DECL
Definition: roswrap/src/cfgsimu/sick_scan/ros/common.h:63
roswrap::service::call
bool call(const std::string &service_name, MReq &req, MRes &res)
Invoke an RPC service.
Definition: service.h:66


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:10