xmlrpc_manager.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  * Copyright (C) 2009, Willow Garage, Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the names of Willow Garage, Inc. nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef ROSCPP_XMLRPC_MANAGER_H
30 #define ROSCPP_XMLRPC_MANAGER_H
31 
32 #include <string>
33 #include <set>
34 //#include <boost/function.hpp>
35 #include <mutex>
36 //#include <boost/thread/thread.hpp>
37 #include <memory>
38 
39 #include "common.h"
40 #include "xmlrpcpp/XmlRpc.h"
41 
42 #include <ros/time.h>
43 
44 
45 namespace roswrap
46 {
47 
51 namespace xmlrpc
52 {
53 XmlRpc::XmlRpcValue responseStr(int code, const std::string& msg, const std::string& response);
54 XmlRpc::XmlRpcValue responseInt(int code, const std::string& msg, int response);
55 XmlRpc::XmlRpcValue responseBool(int code, const std::string& msg, bool response);
56 }
57 
59 typedef std::shared_ptr<XMLRPCCallWrapper> XMLRPCCallWrapperPtr;
60 
61 class ROSCPP_DECL ASyncXMLRPCConnection : public std::enable_shared_from_this<ASyncXMLRPCConnection>
62 {
63 public:
65 
66  virtual void addToDispatch(XmlRpc::XmlRpcDispatch* disp) = 0;
67  virtual void removeFromDispatch(XmlRpc::XmlRpcDispatch* disp) = 0;
68 
69  virtual bool check() = 0;
70 };
71 typedef std::shared_ptr<ASyncXMLRPCConnection> ASyncXMLRPCConnectionPtr;
72 typedef std::set<ASyncXMLRPCConnectionPtr> S_ASyncXMLRPCConnection;
73 
75 {
76 public:
78  : in_use_(false)
79  , client_(c)
80  {
81  }
82 
83  bool in_use_;
84  ros::WallTime last_use_time_; // for reaping
86 
87  static const ros::WallDuration s_zombie_time_; // how long before it is toasted
88 };
89 
90 class XMLRPCManager;
91 typedef std::shared_ptr<XMLRPCManager> XMLRPCManagerPtr;
92 
93 typedef std::function<void(XmlRpc::XmlRpcValue&, XmlRpc::XmlRpcValue&)> XMLRPCFunc;
94 
96 {
97 public:
98  static const XMLRPCManagerPtr& instance();
99 
100  XMLRPCManager();
101  ~XMLRPCManager();
102 
113  bool validateXmlrpcResponse(const std::string& method,
115 
119  inline const std::string& getServerURI() const { return uri_; }
120  inline uint32_t getServerPort() const { return port_; }
121 
122  XmlRpc::XmlRpcClient* getXMLRPCClient(const std::string& host, const int port, const std::string& uri);
123  void releaseXMLRPCClient(XmlRpc::XmlRpcClient* c);
124 
125  void addASyncConnection(const ASyncXMLRPCConnectionPtr& conn);
126  void removeASyncConnection(const ASyncXMLRPCConnectionPtr& conn);
127 
128  bool bind(const std::string& function_name, const XMLRPCFunc& cb);
129  void unbind(const std::string& function_name);
130 
131  void start();
132  void shutdown();
133 
134  bool isShuttingDown() { return shutting_down_; }
135 
136 private:
137  void serverThreadFunc();
138 
139  std::string uri_;
140  int port_;
141  std::thread server_thread_;
142 
143 #if defined(__APPLE__)
144  // OSX has problems with lots of concurrent xmlrpc calls
145  std::mutex xmlrpc_call_mutex_;
146 #endif
148  typedef std::vector<CachedXmlRpcClient> V_CachedXmlRpcClient;
150  std::mutex clients_mutex_;
151 
153 
155 
160 
162 
163 
165  {
166  std::string name;
167  XMLRPCFunc function;
169  };
170  typedef std::map<std::string, FunctionInfo> M_StringToFuncInfo;
171  std::mutex functions_mutex_;
173 
174  volatile bool unbind_requested_;
175 };
176 
177 }
178 
179 #endif
response
const std::string response
roswrap::XMLRPCManager::M_StringToFuncInfo
std::map< std::string, FunctionInfo > M_StringToFuncInfo
Definition: xmlrpc_manager.h:170
roswrap::XMLRPCManagerPtr
std::shared_ptr< XMLRPCManager > XMLRPCManagerPtr
Definition: forwards.h:172
roswrap::XMLRPCCallWrapperPtr
std::shared_ptr< XMLRPCCallWrapper > XMLRPCCallWrapperPtr
Definition: xmlrpc_manager.h:58
roswrap::xmlrpc::responseStr
XmlRpc::XmlRpcValue responseStr(int code, const std::string &msg, const std::string &response)
Definition: xmlrpc_manager.cpp:43
roswrap::XMLRPCManager::uri_
std::string uri_
Definition: xmlrpc_manager.h:139
roswrap::xmlrpc::responseInt
XmlRpc::XmlRpcValue responseInt(int code, const std::string &msg, int response)
Definition: xmlrpc_manager.cpp:52
roswrap::CachedXmlRpcClient::client_
XmlRpc::XmlRpcClient * client_
Definition: xmlrpc_manager.h:85
roswrap::XMLRPCManager::master_retry_timeout_
ros::WallDuration master_retry_timeout_
Definition: xmlrpc_manager.h:154
msg
msg
XmlRpc::XmlRpcServer
A class to handle XML RPC requests.
Definition: XmlRpcServer.h:38
roswrap::master::check
ROSCPP_DECL bool check()
Check whether the master is up.
roswrap::XMLRPCManager::added_connections_mutex_
std::mutex added_connections_mutex_
Definition: xmlrpc_manager.h:157
roswrap::xmlrpc::responseBool
XmlRpc::XmlRpcValue responseBool(int code, const std::string &msg, bool response)
Definition: xmlrpc_manager.cpp:61
roswrap::XMLRPCManager::FunctionInfo::wrapper
XMLRPCCallWrapperPtr wrapper
Definition: xmlrpc_manager.h:168
roswrap::XMLRPCManager::clients_mutex_
std::mutex clients_mutex_
Definition: xmlrpc_manager.h:150
roswrap::XMLRPCManager::V_CachedXmlRpcClient
std::vector< CachedXmlRpcClient > V_CachedXmlRpcClient
Definition: xmlrpc_manager.h:148
roswrap::CachedXmlRpcClient::in_use_
bool in_use_
Definition: xmlrpc_manager.h:83
roswrap::shutdown
ROSCPP_DECL void shutdown()
Disconnects everything and unregisters from the master. It is generally not necessary to call this fu...
Definition: rossimu.cpp:269
roswrap::ASyncXMLRPCConnectionPtr
std::shared_ptr< ASyncXMLRPCConnection > ASyncXMLRPCConnectionPtr
Definition: xmlrpc_manager.h:71
roswrap::XMLRPCManager::getServerURI
const std::string & getServerURI() const
Get the xmlrpc server URI of this node.
Definition: xmlrpc_manager.h:119
roswrap::XMLRPCManager::added_connections_
S_ASyncXMLRPCConnection added_connections_
Definition: xmlrpc_manager.h:156
XmlRpc::XmlRpcClient
A class to send XML RPC requests to a server and return the results.
Definition: XmlRpcClient.h:27
roswrap::CachedXmlRpcClient::last_use_time_
ros::WallTime last_use_time_
Definition: xmlrpc_manager.h:84
roswrap::XMLRPCManager::functions_
M_StringToFuncInfo functions_
Definition: xmlrpc_manager.h:172
pcap_json_converter.payload
string payload
Definition: pcap_json_converter.py:130
roswrap::XMLRPCManager::clients_
V_CachedXmlRpcClient clients_
Definition: xmlrpc_manager.h:149
roswrap::CachedXmlRpcClient::CachedXmlRpcClient
CachedXmlRpcClient(XmlRpc::XmlRpcClient *c)
Definition: xmlrpc_manager.h:77
roswrap::XMLRPCManager::isShuttingDown
bool isShuttingDown()
Definition: xmlrpc_manager.h:134
roswrap::XMLRPCManager::port_
int port_
Definition: xmlrpc_manager.h:140
roswrap::XMLRPCManager::server_thread_
std::thread server_thread_
Definition: xmlrpc_manager.h:141
roswrap::XMLRPCManager::removed_connections_
S_ASyncXMLRPCConnection removed_connections_
Definition: xmlrpc_manager.h:158
roswrap::XMLRPCManager::removed_connections_mutex_
std::mutex removed_connections_mutex_
Definition: xmlrpc_manager.h:159
roswrap
Definition: param_modi.cpp:41
roswrap::ASyncXMLRPCConnection::~ASyncXMLRPCConnection
virtual ~ASyncXMLRPCConnection()
Definition: xmlrpc_manager.h:64
ros::WallTime
roswrap::XMLRPCManager::getServerPort
uint32_t getServerPort() const
Definition: xmlrpc_manager.h:120
common.h
roswrap::XMLRPCManager::shutting_down_
bool shutting_down_
Definition: xmlrpc_manager.h:152
roswrap::XMLRPCManager::FunctionInfo
Definition: xmlrpc_manager.h:164
roswrap::XMLRPCManager::server_
XmlRpc::XmlRpcServer server_
Definition: xmlrpc_manager.h:147
sick_scan_xd_api_test.c
c
Definition: sick_scan_xd_api_test.py:445
roswrap::CachedXmlRpcClient::s_zombie_time_
static const ros::WallDuration s_zombie_time_
Definition: xmlrpc_manager.h:87
sick_scan_base.h
XmlRpc::XmlRpcDispatch
roswrap::ASyncXMLRPCConnection
Definition: xmlrpc_manager.h:61
roswrap::XMLRPCManager::unbind_requested_
volatile bool unbind_requested_
Definition: xmlrpc_manager.h:174
roswrap::XMLRPCManager::connections_
S_ASyncXMLRPCConnection connections_
Definition: xmlrpc_manager.h:161
roswrap::XMLRPCManager::FunctionInfo::name
std::string name
Definition: xmlrpc_manager.h:166
roswrap::XMLRPCCallWrapper
Definition: xmlrpc_manager.cpp:71
ros::WallDuration
ROSCPP_DECL
#define ROSCPP_DECL
Definition: roswrap/src/cfgsimu/sick_scan/ros/common.h:63
roswrap::CachedXmlRpcClient
Definition: xmlrpc_manager.h:74
roswrap::XMLRPCManager
Definition: xmlrpc_manager.h:95
roswrap::start
ROSCPP_DECL void start()
Actually starts the internals of the node (spins up threads, starts the network polling and xmlrpc lo...
roswrap::S_ASyncXMLRPCConnection
std::set< ASyncXMLRPCConnectionPtr > S_ASyncXMLRPCConnection
Definition: xmlrpc_manager.h:72
XmlRpc::XmlRpcValue
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:25
roswrap::XMLRPCManager::functions_mutex_
std::mutex functions_mutex_
Definition: xmlrpc_manager.h:171
roswrap::XMLRPCFunc
std::function< void(XmlRpc::XmlRpcValue &, XmlRpc::XmlRpcValue &)> XMLRPCFunc
Definition: xmlrpc_manager.h:93


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