node_handle.h
Go to the documentation of this file.
00001 #ifndef ROSRTT_NODE_HANDLE_H
00002 #define ROSRTT_NODE_HANDLE_H
00003 
00004 #include "ros/node_handle.h"
00005 #include "publisher.h"
00006 #include "subscriber.h"
00007 #include "topic_manager.h"
00008 
00009 namespace hpcl_rtt {
00010 
00011 class NodeHandle
00012 {
00013 public:
00014   NodeHandle(const std::string& ns = std::string(), const ros::M_string& remappings = ros::M_string());
00015 //  NodeHandle(const NodeHandle& rhs);
00016 //  NodeHandle(const NodeHandle& parent, const std::string& ns);
00017 //  NodeHandle(const NodeHandle& parent, const std::string& ns, const ros::M_string& remappings);
00018   ~NodeHandle();
00019 
00020   //NodeHandle& operator=(const NodeHandle& rhs);
00021 
00022   void setCallbackQueue(ros::CallbackQueueInterface* queue)
00023   {
00024     ros_nh.setCallbackQueue(queue);
00025   }
00026 
00027   ros::CallbackQueueInterface* getCallbackQueue() const
00028   {
00029     return ros_nh.getCallbackQueue();
00030   }
00031 
00032   const std::string& getNamespace() const 
00033   {
00034     return ros_nh.getNamespace();
00035   }
00036 
00037   const std::string& getUnresolvedNamespace()
00038   {
00039     return ros_nh.getUnresolvedNamespace();
00040   }
00041 
00042   std::string resolveName(const std::string& name, bool remap = true) const
00043   {
00044     return ros_nh.getUnresolvedNamespace();
00045   }
00046 
00047 
00048   template <class M>
00049   Publisher advertise(const std::string& topic, uint32_t queue_size, bool latch = false)
00050   {
00051     ros::Publisher ros_pub = ros_nh.advertise<M>(topic, queue_size, latch);
00052     ROS_INFO("advertise.");
00053     
00054     if (ros_pub) 
00055     {
00056       ConnectionBasePtr pub_connection = TopicManager::instance()->advertise<M>(topic);
00057       if (pub_connection)
00058       {
00059         ROS_INFO("publish successes.");
00060         Publisher pub(pub_connection, ros_pub);
00061         return pub;
00062       }
00063     }
00064 
00065     return Publisher();
00066   }
00067 
00068   template <class M>
00069   Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(*fp)(M),
00070              const ros::TransportHints& transport_hints = ros::TransportHints())
00071   {
00072     // this will lead local messages to be double received, not resolved.
00073     ros::Subscriber ros_sub = ros_nh.subscribe(topic, queue_size, fp, transport_hints);
00074     ROS_INFO("subscribe.");
00075     if (ros_sub) 
00076     {
00077       ROS_INFO("ros subscribe successful.");
00078       ConnectionBasePtr sub_connection = TopicManager::instance()->subscribe<M>(topic, fp);
00079       if (sub_connection)
00080       {
00081         ROS_INFO("subscribe successes.");
00082         Subscriber sub(sub_connection, ros_sub);
00083         return sub;
00084       }
00085     }
00086 
00087     return Subscriber();
00088   }
00089 
00090 private:
00091   ros::NodeHandle ros_nh;
00092 
00093 };
00094 
00095 }
00096 
00097 #endif


hpcl_rtt
Author(s): sukha
autogenerated on Thu Aug 27 2015 16:43:53