52 M_string::const_iterator it = remappings.find(
"__master");
53 if (it != remappings.end())
60 char *master_uri_env = NULL;
62 _dupenv_s(&master_uri_env, NULL,
"ROS_MASTER_URI");
64 master_uri_env = getenv(
"ROS_MASTER_URI");
68 ROS_FATAL(
"ROS_MASTER_URI is not defined in the environment. Either " \
69 "type the following or (preferrably) add this to your " \
70 "~/.bashrc file in order set up your " \
71 "local machine as a ROS master:\n\n" \
72 "export ROS_MASTER_URI=http://localhost:11311\n\n" \
73 "then, type 'roscore' in another shell to actually launch " \
74 "the master program.");
78 g_uri = master_uri_env;
89 ROS_FATAL(
"Couldn't parse the master URI [%s] into a host:port pair.", g_uri.c_str());
113 ROS_FATAL(
"retry timeout must not be negative.");
116 g_retry_timeout = timeout;
123 return execute(
"getPid", args, result, payload,
false);
132 if (!
execute(
"getPublishedTopics", args, result, payload,
true))
138 for (
int i = 0; i < payload.
size(); i++)
140 topics.push_back(
TopicInfo(std::string(payload[i][0]), std::string(payload[i][1])));
151 if (!
execute(
"getSystemState", args, result, payload,
true))
157 for (
int i = 0; i < payload.
size(); ++i)
159 for (
int j = 0; j < payload[i].
size(); ++j)
162 for (
int k = 0; k < val.
size(); ++k)
164 std::string name = payload[i][j][1][k];
165 node_set.insert(name);
170 nodes.insert(nodes.end(), node_set.begin(), node_set.end());
175 #if defined(__APPLE__) 176 boost::mutex g_xmlrpc_call_mutex;
183 std::string master_host =
getHost();
184 uint32_t master_port =
getPort();
186 bool printed =
false;
193 #if defined(__APPLE__) 194 boost::mutex::scoped_lock lock(g_xmlrpc_call_mutex);
197 b = c->
execute(method.c_str(), request, response);
204 if (!printed && wait_for_master)
206 ROS_ERROR(
"[%s] Failed to contact master at [%s:%d]. %s", method.c_str(), master_host.c_str(), master_port, wait_for_master ?
"Retrying..." :
"");
210 if (!wait_for_master)
218 ROS_ERROR(
"[%s] Timed out trying to connect to the master after [%f] seconds", method.c_str(), g_retry_timeout.
toSec());
243 ROS_INFO(
"Connected to master at [%s:%d]", master_host.c_str(), master_port);
ROSCPP_DECL uint32_t getPort()
Get the port where the master runs.
ROSCPP_DECL void setRetryTimeout(ros::WallDuration timeout)
Set the max time this node should spend looping trying to connect to the master.
ROSCPP_DECL const std::string & getURI()
Get the full URI to the master (eg. http://host:port/)
ROSCPP_DECL bool check()
Check whether the master is up.
std::set< std::string > S_string
void init(const M_string &remappings)
ROSCPP_DECL bool splitURI(const std::string &uri, std::string &host, uint32_t &port)
ROSCPP_DECL const std::string & getName()
Returns the name of the current node.
ROSCPP_DECL bool getTopics(V_TopicInfo &topics)
Get the list of topics that are being published by all nodes.
std::vector< TopicInfo > V_TopicInfo
std::map< std::string, std::string > M_string
std::vector< std::string > V_string
ROSCPP_DECL bool ok()
Check whether it's time to exit.
ROSCPP_DECL bool execute(const std::string &method, const XmlRpc::XmlRpcValue &request, XmlRpc::XmlRpcValue &response, XmlRpc::XmlRpcValue &payload, bool wait_for_master)
Execute an XMLRPC call on the master.
ROSCPP_DECL bool isShuttingDown()
Returns whether or not ros::shutdown() has been (or is being) called.
ROSCPP_DECL const std::string & getHost()
Get the hostname where the master runs.
ros::WallDuration g_retry_timeout
bool execute(const char *method, XmlRpcValue const ¶ms, XmlRpcValue &result)
static const XMLRPCManagerPtr & instance()
ROSCPP_DECL bool getNodes(V_string &nodes)
Retreives the currently-known list of nodes from the master.
Contains information retrieved from the master about a topic.