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&)
352 if (g_shutting_down)
goto end;
361 if (g_shutting_down)
goto end;
370 if (g_shutting_down)
goto end;
380 if (g_shutting_down)
goto end;
383 bool use_sim_time =
false;
384 param::param(
"/use_sim_time", use_sim_time, use_sim_time);
391 if (g_shutting_down)
goto end;
402 if (g_shutting_down)
goto end;
407 ROSCPP_LOG_DEBUG(
"Started node [%s], pid [%d], bound on [%s], xmlrpc port [%d], tcpros port [%d], using [%s] time",
418 boost::recursive_mutex::scoped_lock lock(g_shutting_down_mutex);
423 char* env_ipv6 = NULL;
425 _dupenv_s(&env_ipv6, NULL,
"ROS_IPV6");
427 env_ipv6 = getenv(
"ROS_IPV6");
430 bool use_ipv6 = (env_ipv6 && strcmp(env_ipv6,
"on") == 0);
435 void init(
const M_string& remappings,
const std::string& name, uint32_t options)
437 if (!g_atexit_registered)
439 g_atexit_registered =
true;
450 g_init_options = options;
456 signal(SIGPIPE, SIG_IGN);
466 g_initialized =
true;
470 void init(
int& argc,
char** argv,
const std::string& name, uint32_t options)
474 int full_argc = argc;
476 for (
int i = 0; i < argc; )
478 std::string arg = argv[i];
479 size_t pos = arg.find(
":=");
480 if (pos != std::string::npos)
482 std::string local_name = arg.substr(0, pos);
483 std::string external_name = arg.substr(pos + 2);
485 ROSCPP_LOG_DEBUG(
"remap: %s => %s", local_name.c_str(), external_name.c_str());
486 remappings[local_name] = external_name;
490 for (
int j = i; j < full_argc - 1; j++)
501 init(remappings, name, options);
504 void init(
const VP_string& remappings,
const std::string& name, uint32_t options)
507 VP_string::const_iterator it = remappings.begin();
508 VP_string::const_iterator end = remappings.end();
509 for (; it != end; ++it)
511 remappings_map[it->first] = it->second;
514 init(remappings_map, name, options);
517 std::string
getROSArg(
int argc,
const char*
const* argv,
const std::string& arg)
519 for (
int i = 0; i < argc; ++i)
521 std::string str_arg = argv[i];
522 size_t pos = str_arg.find(
":=");
523 if (str_arg.substr(0,pos) == arg)
525 return str_arg.substr(pos+2);
533 for (
int i = 0; i < argc; ++i)
535 std::string arg = argv[i];
536 size_t pos = arg.find(
":=");
537 if (pos == std::string::npos)
539 args_out.push_back(arg);
570 return g_global_queue.get();
580 boost::recursive_mutex::scoped_lock lock(g_shutting_down_mutex);
584 g_shutting_down =
true;
588 g_global_queue->disable();
589 g_global_queue->clear();
591 if (g_internal_queue_thread.get_id() != boost::this_thread::get_id())
593 g_internal_queue_thread.join();
596 g_rosout_appender = 0;
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
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
Type const & getType() const
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)
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
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.
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
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>&...
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()