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


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas , Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:36