53 #include "roscpp/GetLoggers.h" 54 #include "roscpp/SetLoggerLevel.h" 55 #include "roscpp/Empty.h" 59 #include <rosgraph_msgs/Clock.h> 77 void init(
const std::string& names,
const M_string& remappings, uint32_t options);
122 if (g_shutdown_requested)
126 boost::recursive_mutex::scoped_try_lock lock(g_shutting_down_mutex, boost::defer_lock);
132 if (!g_shutting_down)
137 g_shutdown_requested =
false;
143 g_shutdown_requested =
true;
150 ROSCPP_LOG_DEBUG(
"shutting down due to exit() or end of main() without cleanup of all NodeHandles");
160 num_params = params.
size();
163 std::string reason = params[1];
164 ROS_WARN(
"Shutdown request received.");
165 ROS_WARN(
"Reason given for shutdown: [%s]", reason.c_str());
172 bool getLoggers(roscpp::GetLoggers::Request&, roscpp::GetLoggers::Response& resp)
174 std::map<std::string, ros::console::levels::Level> loggers;
175 bool success = ::ros::console::get_loggers(loggers);
178 for (std::map<std::string, ros::console::levels::Level>::const_iterator it = loggers.begin(); it != loggers.end(); it++)
180 roscpp::Logger logger;
181 logger.name = it->first;
185 logger.level =
"debug";
189 logger.level =
"info";
193 logger.level =
"warn";
197 logger.level =
"error";
201 logger.level =
"fatal";
203 resp.loggers.push_back(logger);
209 bool setLoggerLevel(roscpp::SetLoggerLevel::Request& req, roscpp::SetLoggerLevel::Response&)
211 std::transform(req.level.begin(), req.level.end(), req.level.begin(), (int(*)(int))std::toupper);
214 if (req.level ==
"DEBUG")
218 else if (req.level ==
"INFO")
222 else if (req.level ==
"WARN")
226 else if (req.level ==
"ERROR")
230 else if (req.level ==
"FATAL")
239 bool success = ::ros::console::set_logger_level(req.logger, level);
250 ROSCPP_LOG_DEBUG(
"close_all_connections service called, closing connections");
262 if (!g_internal_callback_queue)
278 disableAllSignalsInThisThread();
282 while (!g_shutting_down)
295 boost::mutex::scoped_lock lock(g_start_mutex);
301 g_shutdown_requested =
false;
302 g_shutting_down =
false;
306 bool enable_debug =
false;
307 std::string enable_debug_env;
312 enable_debug = boost::lexical_cast<
bool>(enable_debug_env.c_str());
314 catch (boost::bad_lexical_cast&)
339 bool no_rosout =
false;
340 std::string no_rosout_env;
345 no_rosout = boost::lexical_cast<
bool>(no_rosout_env.c_str());
347 catch (boost::bad_lexical_cast&)
358 if (g_shutting_down)
goto end;
367 if (g_shutting_down)
goto end;
376 if (g_shutting_down)
goto end;
386 if (g_shutting_down)
goto end;
389 bool use_sim_time =
false;
390 param::param(
"/use_sim_time", use_sim_time, use_sim_time);
397 if (g_shutting_down)
goto end;
408 if (g_shutting_down)
goto end;
413 ROSCPP_LOG_DEBUG(
"Started node [%s], pid [%d], bound on [%s], xmlrpc port [%d], tcpros port [%d], using [%s] time",
424 boost::recursive_mutex::scoped_lock lock(g_shutting_down_mutex);
429 char* env_ipv6 = NULL;
431 _dupenv_s(&env_ipv6, NULL,
"ROS_IPV6");
433 env_ipv6 = getenv(
"ROS_IPV6");
436 bool use_ipv6 = (env_ipv6 && strcmp(env_ipv6,
"on") == 0);
448 void init(
const M_string& remappings,
const std::string& name, uint32_t options)
450 if (!g_atexit_registered)
452 g_atexit_registered =
true;
463 g_init_options = options;
469 signal(SIGPIPE, SIG_IGN);
472 WSAStartup(MAKEWORD(2, 0), &wsaData);
482 g_initialized =
true;
486 void init(
int& argc,
char** argv,
const std::string& name, uint32_t options)
490 int full_argc = argc;
492 for (
int i = 0; i < argc; )
494 std::string arg = argv[i];
495 size_t pos = arg.find(
":=");
496 if (pos != std::string::npos)
498 std::string local_name = arg.substr(0, pos);
499 std::string external_name = arg.substr(pos + 2);
501 ROSCPP_LOG_DEBUG(
"remap: %s => %s", local_name.c_str(), external_name.c_str());
502 remappings[local_name] = external_name;
506 for (
int j = i; j < full_argc - 1; j++)
517 init(remappings, name, options);
520 void init(
const VP_string& remappings,
const std::string& name, uint32_t options)
523 VP_string::const_iterator it = remappings.begin();
524 VP_string::const_iterator end = remappings.end();
525 for (; it != end; ++it)
527 remappings_map[it->first] = it->second;
530 init(remappings_map, name, options);
533 std::string
getROSArg(
int argc,
const char*
const* argv,
const std::string& arg)
535 for (
int i = 0; i < argc; ++i)
537 std::string str_arg = argv[i];
538 size_t pos = str_arg.find(
":=");
539 if (str_arg.substr(0,pos) == arg)
541 return str_arg.substr(pos+2);
549 for (
int i = 0; i < argc; ++i)
551 std::string arg = argv[i];
552 size_t pos = arg.find(
":=");
553 if (pos == std::string::npos)
555 args_out.push_back(arg);
586 return g_global_queue.get();
596 boost::recursive_mutex::scoped_lock lock(g_shutting_down_mutex);
600 g_shutting_down =
true;
604 g_global_queue->disable();
605 g_global_queue->clear();
607 if (g_internal_queue_thread.get_id() != boost::this_thread::get_id())
609 g_internal_queue_thread.join();
613 g_rosout_appender = 0;
630 static const std::string uri =
"http://localhost:11311";
CallbackQueueInterface * callback_queue
Queue to add callbacks to. If NULL, the global callback queue will be used.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
Assign value from parameter server, with default.
void init(const std::string &_service, const boost::function< bool(MReq &, MRes &)> &_callback)
Templated convenience method for filling out md5sum/etc. based on the service request/response types...
This is the default implementation of the ros::CallbackQueueInterface.
virtual void spin(CallbackQueue *queue=0)=0
Spin on a callback queue (defaults to the global one). Blocks until roscpp has been shutdown...
ROSCPP_DECL void start()
Actually starts the internals of the node (spins up threads, starts the network polling and xmlrpc lo...
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
bool closeAllConnections(roscpp::Empty::Request &, roscpp::Empty::Response &)
void enable()
Enable the queue (queue is enabled by default)
static boost::recursive_mutex g_shutting_down_mutex
std::vector< std::pair< std::string, std::string > > VP_string
ROSCPP_DECL XmlRpc::XmlRpcValue responseInt(int code, const std::string &msg, int response)
void init(const M_string &remappings)
ROSCPP_DECL bool isInitialized()
Returns whether or not ros::init() has been called.
void init(const M_string &remappings)
ROSCPP_DECL const std::string & getName()
Returns the name of the current node.
static bool useSystemTime()
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
Resolve a graph resource name into a fully qualified graph resource name.
#define ROSCONSOLE_AUTOINIT
static void setNow(const Time &new_now)
void internalCallbackQueueThreadFunc()
bool getLoggers(roscpp::GetLoggers::Request &, roscpp::GetLoggers::Response &resp)
static const ServiceManagerPtr & instance()
void init(const std::string &names, const M_string &remappings, uint32_t options)
Encapsulates all options available for creating a ServiceServer.
void check_ipv6_environment()
ROSCPP_DECL CallbackQueue * getGlobalCallbackQueue()
Returns a pointer to the global default callback queue.
std::map< std::string, std::string > M_string
#define ROSCPP_LOG_DEBUG(...)
Abstract interface for classes which spin on a callback queue.
void basicSigintHandler(int sig)
Type const & getType() const
std::vector< std::string > V_string
void init(const M_string &remappings)
ROSCPP_DECL const std::string & getHost()
void shutdownCallback(XmlRpc::XmlRpcValue ¶ms, XmlRpc::XmlRpcValue &result)
static const ConnectionManagerPtr & instance()
Encapsulates all options available for creating a Subscriber.
ROSCPP_DECL void initInternalTimerManager()
ROSCPP_DECL bool ok()
Check whether it's time to exit.
ROSCPP_DECL bool isShuttingDown()
Returns whether or not ros::shutdown() has been (or is being) called.
bool get_environment_variable(std::string &str, const char *environment_variable)
CallbackQueuePtr getInternalCallbackQueue()
static bool g_atexit_registered
ROSCPP_DECL void spin()
Enter simple event loop.
Spinner which runs in a single thread.
Don't broadcast rosconsole output to the /rosout topic.
static volatile bool g_shutting_down
static bool g_shutdown_requested
ROSCPP_DECL std::string getROSArg(int argc, const char *const *argv, const std::string &arg)
searches the command line arguments for the given arg parameter. In case this argument is not found a...
void clockCallback(const rosgraph_msgs::Clock::ConstPtr &msg)
CallbackQueuePtr g_global_queue
ROSCPP_DECL const std::string & getDefaultMasterURI()
returns the default master uri that is used if no other is specified, e.g. by defining ROS_MASTER_URI...
static bool s_use_keepalive_
static const PollManagerPtr & instance()
static CallbackQueuePtr g_internal_callback_queue
ROSCPP_DECL void requestShutdown()
Request that the node shut itself down from within a ROS thread.
void init(const std::string &_topic, uint32_t _queue_size, const boost::function< void(const boost::shared_ptr< M const > &)> &_callback, const boost::function< boost::shared_ptr< M >(void)> &factory_fn=DefaultMessageCreator< M >())
Templated initialization, templated on message type. Only supports "const boost::shared_ptr<M const>&...
ROSCPP_DECL bool isStarted()
Returns whether or not the node has been started through ros::start()
ROSCONSOLE_DECL void shutdown()
static boost::mutex g_start_mutex
ROSOutAppender * g_rosout_appender
static const XMLRPCManagerPtr & instance()
ROSCPP_DECL void shutdown()
Disconnects everything and unregisters from the master. It is generally not necessary to call this fu...
ROSCPP_DECL void removeROSArgs(int argc, const char *const *argv, V_string &args_out)
returns a vector of program arguments that do not include any ROS remapping arguments. Useful if you need to parse your arguments to determine your node name
static bool g_initialized
bool setLoggerLevel(roscpp::SetLoggerLevel::Request &req, roscpp::SetLoggerLevel::Response &)
ROSCPP_DECL void spinOnce()
Process a single round of callbacks.
ROSCONSOLE_DECL void register_appender(LogAppender *appender)
static uint32_t g_init_options
CallbackQueueInterface * callback_queue
Queue to add callbacks to. If NULL, the global callback queue will be used.
static boost::thread g_internal_queue_thread
void init(const M_string &remappings)
ROSCPP_DECL void waitForShutdown()
Wait for this node to be shutdown, whether through Ctrl-C, ros::shutdown(), or similar.
static const TopicManagerPtr & instance()