void callbackThreadFunction(SharedMemoryTransport<T>* smt, boost::function<void(T&)> callback)
    {
      T msg;
      std::string serialized_data;

      ros::Rate loop_rate(10.0);
      while(ros::ok()) //wait for the field to at least have something
      {
        if(!smt->initialized())
        {
          ROS_WARN("%s: Shared memory transport was shut down while we were waiting for connections. Stopping callback thread!", m_nh->getNamespace().c_str());
          return;
        }
        if(!smt->connected())
        {
          smt->connect();
        }
        else if(smt->hasData())
        {
          break;
        }
        ROS_WARN_STREAM_THROTTLE(1.0, m_nh->getNamespace() << ": Trying to connect to field " << smt->getFieldName() << "...");
        loop_rate.sleep();
        //boost::this_thread::interruption_point();
      }

      if(getCurrentMessage(msg))
      {
        callback(msg);
      }

      while(ros::ok())
      {
        try
        {
          if(m_use_polling)
          {
            smt->awaitNewDataPolled(msg);
          }
          else
          {
            smt->awaitNewData(msg);
          }
          callback(msg);
        }
        catch(ros::serialization::StreamOverrunException& ex)
        {
          ROS_ERROR("%s: Deserialization failed for topic %s! The string was:\n%s", m_nh->getNamespace().c_str(), m_full_topic_path.c_str(), serialized_data.c_str());
        }
        //boost::this_thread::interruption_point();
      }
    }
Пример #2
0
bool VoiceboxDialog::enqueueCurMessage() {
  if (((in_saved_msgs) && (cur_msg == saved_msgs.end()))
      ||((!in_saved_msgs) && (cur_msg == new_msgs.end()))) {
      ERROR("check implementation!\n");
      return false;
  }

  FILE*  fp=getCurrentMessage();
  if (NULL == fp)
    return false;

  if (!in_saved_msgs) {
    if (cur_msg == new_msgs.begin()) 
      enqueueBack("first_new_msg");
    else
      enqueueBack("next_new_msg");    
  } else {
    if (cur_msg == saved_msgs.begin()) 
      enqueueBack("first_saved_msg");
    else 
      enqueueBack("next_saved_msg");
  }
  // notifies the dialog that playback of message starts
  enqueueSeparator(PLAYLIST_SEPARATOR_MSG_BEGIN);
  // enqueue msg
  message.fpopen(cur_msg->name, AmAudioFile::Read, fp);
  play_list.addToPlaylist(new AmPlaylistItem(&message, NULL));
  if (!isAtLastMsg())
    enqueueBack("msg_menu");
  else 
    enqueueBack("msg_end_menu");
  //can do save action on cur message?
  do_save_cur_msg = !in_saved_msgs;

  return true;
}