qnode.cpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Includes
00011 *****************************************************************************/
00012 
00013 #include <ros/ros.h>
00014 #include <ros/network.h>
00015 #include <string>
00016 #include "qnode.hpp"
00017 #include <std_msgs/String.h>
00018 #include <sstream>
00019 
00020 /*****************************************************************************
00021 ** Implementation
00022 *****************************************************************************/
00023 
00024 QNode::QNode(int argc, char** argv, const std::string &name ) :
00025         init_argc(argc),
00026         init_argv(argv),
00027         node_name(name)
00028         {}
00029 
00030 QNode::~QNode() {
00031         shutdown();
00032 }
00037 void QNode::shutdown() {
00038     if(ros::isStarted()) {
00039       ros::shutdown(); // explicitly needed since we use ros::start();
00040       ros::waitForShutdown();
00041     }
00042         wait();
00043 }
00044 
00045 bool QNode::on_init() {
00046         ros::init(init_argc,init_argv,node_name);
00047         if ( ! ros::master::check() ) {
00048                 return false;
00049         }
00050         ros::start(); // our node handles go out of scope, so we want to control shutdown explicitly.
00051         ros_comms_init();
00052         start();
00053         return true;
00054 }
00055 
00056 bool QNode::on_init(const std::string &master_url, const std::string &host_url) {
00057         std::map<std::string,std::string> remappings;
00058         remappings["__master"] = master_url;
00059         remappings["__hostname"] = host_url;
00060         ros::init(remappings,node_name);
00061         if ( ! ros::master::check() ) {
00062                 return false;
00063         }
00064         ros::start(); // our node handles go out of scope, so we want to control shutdown explicitly.
00065         ros_comms_init();
00066         start();
00067         return true;
00068 }
00069 


qt_tutorials
Author(s): Daniel Stonier
autogenerated on Tue Jan 7 2014 11:33:48