00001 template<typename Msg> 00002 void TypedPublisher<Msg>::start(const std::string& _topic, int queue_size) 00003 { 00004 unique_lock lock (mutex); 00005 if (running && (topic==_topic)) return; 00006 if (running) stop(); 00007 topic=_topic; 00008 pub= node.advertise<MessageType>(topic,queue_size,true); 00009 running=true; 00010 } 00011 00012 template<typename Msg> 00013 void TypedPublisher<Msg>::stop(){ 00014 unique_lock lock (mutex); 00015 running=false; 00016 pub.shutdown(); 00017 } 00018 00019 template<typename Msg> 00020 void TypedPublisher<Msg>::publish(MessageType& m) 00021 { 00022 unique_lock lock(mutex); 00023 if (!running) return; 00024 pub.publish(m); 00025 }