コード例 #1
0
ファイル: touch.cpp プロジェクト: k-okada/naoqi_driver
void TouchEventRegister<T>::touchCallback(std::string &key, qi::AnyValue &value, qi::AnyValue &message)
{
  T msg = T();
  
  bool state =  value.toFloat() > 0.5f;

  //std::cerr << key << " " << state << std::endl;

  touchCallbackMessage(key, state, msg);

  std::vector<message_actions::MessageAction> actions;
  boost::mutex::scoped_lock callback_lock(mutex_);
  if (isStarted_) {
    // CHECK FOR PUBLISH
    if ( isPublishing_ && publisher_->isSubscribed() )
    {
      actions.push_back(message_actions::PUBLISH);
    }
    // CHECK FOR RECORD
    if ( isRecording_ )
    {
      //actions.push_back(message_actions::RECORD);
    }
    if ( !isDumping_ )
    {
      //actions.push_back(message_actions::LOG);
    }
    if (actions.size() >0)
    {
      converter_->callAll( actions, msg );
    }
  }
}
コード例 #2
0
ファイル: common.hpp プロジェクト: nickfajones/libapoa
    ~per_thread_index()
      {
      if (id_ >= 0)
        {
        std::lock_guard<std::mutex> callback_lock(callback_mutex_);

        thread_start_callbacks_.erase(id_);
        thread_finish_callbacks_.erase(id_);
        }

      std::lock_guard<std::mutex> index_lock(index_mutex_);

      for (ssize_t counter = index_size_ - 1;
           counter >= 0;
           --counter)
        {
        if (index_[counter] != NULL)
          {
          delete index_[counter];
          index_[counter] = NULL;
          }
        }

      delete [] index_;
      index_ = NULL;
      }
コード例 #3
0
ファイル: common.hpp プロジェクト: nickfajones/libapoa
    static void thread_finish()
      {
      std::lock_guard<std::mutex> callback_lock(callback_mutex_);

      for (per_thread_index_callback_map::iterator itr =
             thread_finish_callbacks_.begin();
           itr != thread_finish_callbacks_.end();
           ++itr)
        {
        (itr->second)();
        }

      thread_set_.erase(get_tenum());
      }
コード例 #4
0
ファイル: people.cpp プロジェクト: nlyubova/naoqi_driver
void PeopleEventRegister<T>::peopleCallback(std::string &key, qi::AnyValue &value, qi::AnyValue &message)
{
  T msg = T();
  
  tools::NaoqiFaceDetected faces;
  try {
    faces = tools::fromAnyValueToNaoqiFaceDetected(value);
  }
  catch(std::runtime_error& e)
  {
    std::cout << "Cannot retrieve facedetect" << std::endl;
    return;
  }

  if ( faces.face_info.size() > 0 ) { // sometimes value does not have face information..
    peopleCallbackMessage(key, faces, msg);
  }

  std::vector<message_actions::MessageAction> actions;
  boost::mutex::scoped_lock callback_lock(mutex_);

  if (isStarted_) {
    // CHECK FOR PUBLISH
    if ( isPublishing_ && publisher_->isSubscribed() )
    {
      actions.push_back(message_actions::PUBLISH);
    }
    // CHECK FOR RECORD
    if ( isRecording_ )
    {
      //actions.push_back(message_actions::RECORD);
    }
    if ( !isDumping_ )
    {
      //actions.push_back(message_actions::LOG);
    }
    if (actions.size() >0)
    {
      converter_->callAll( actions, msg );
    }
  }
}
コード例 #5
0
ファイル: audio.cpp プロジェクト: NearZhxiAo/naoqi_driver
void AudioEventRegister::processRemote(int nbOfChannels, int samplesByChannel, qi::AnyValue altimestamp, qi::AnyValue buffer)
{
  naoqi_bridge_msgs::AudioBuffer msg = naoqi_bridge_msgs::AudioBuffer();
  msg.header.stamp = ros::Time::now();
  msg.frequency = 48000;
  msg.channelMap = channelMap;

  std::pair<char*, size_t> buffer_pointer = buffer.asRaw();

  int16_t* remoteBuffer = (int16_t*)buffer_pointer.first;
  int bufferSize = nbOfChannels * samplesByChannel;
  msg.data = std::vector<int16_t>(remoteBuffer, remoteBuffer+bufferSize);

  std::vector<message_actions::MessageAction> actions;
  boost::mutex::scoped_lock callback_lock(processing_mutex_);
  if (isStarted_) {
    // CHECK FOR PUBLISH
    if ( isPublishing_ && publisher_->isSubscribed() )
    {
      actions.push_back(message_actions::PUBLISH);
    }
    // CHECK FOR RECORD
    if ( isRecording_ )
    {
      actions.push_back(message_actions::RECORD);
    }
    if ( !isDumping_ )
    {
      actions.push_back(message_actions::LOG);
    }
    if (actions.size() >0)
    {
      converter_->callAll( actions, msg );
    }
  }

}
コード例 #6
0
ファイル: common.hpp プロジェクト: nickfajones/libapoa
    per_thread_index() :
        id_(__sync_add_and_fetch(&index_id_, 1)),
        index_size_(default_index_size)
      {
      index_ = new T*[index_size_];
      memset(index_, 0, sizeof(T*) * index_size_);

      std::lock_guard<std::mutex> callback_lock(callback_mutex_);

      thread_start_callbacks_.insert(
        std::make_pair(
          id_, std::bind(&per_thread_index<T>::on_thread_start, this)));
      thread_finish_callbacks_.insert(
        std::make_pair(
          id_, std::bind(&per_thread_index<T>::on_thread_finish, this)));

      for (std::set<tenum_t>::iterator itr =
             thread_set_.begin();
           itr != thread_set_.end();
           ++itr)
        {
        do_on_thread_start(*itr, NULL);
        }
      }
コード例 #7
0
ファイル: common.hpp プロジェクト: nickfajones/libapoa
    static void init()
      {
      std::lock_guard<std::mutex> callback_lock(callback_mutex_);

      thread_set_.insert(0);
      }