Ejemplo n.º 1
0
AudioEventRegister::AudioEventRegister( const std::string& name, const float& frequency, const qi::SessionPtr& session )
  : serviceId(0),
    p_audio_( session->service("ALAudioDevice")),
    p_robot_model_(session->service("ALRobotModel")),
    session_(session),
    isStarted_(false),
    isPublishing_(false),
    isRecording_(false),
    isDumping_(false)
{
  int micConfig = p_robot_model_.call<int>("_getMicrophoneConfig");
  if(micConfig){
    channelMap.push_back(3);
    channelMap.push_back(5);
    channelMap.push_back(0);
    channelMap.push_back(2);
  }
  else{
    channelMap.push_back(0);
    channelMap.push_back(2);
    channelMap.push_back(1);
    channelMap.push_back(4);
  }
  publisher_ = boost::make_shared<publisher::BasicPublisher<naoqi_bridge_msgs::AudioBuffer> >( name );
  recorder_ = boost::make_shared<recorder::BasicEventRecorder<naoqi_bridge_msgs::AudioBuffer> >( name );
  converter_ = boost::make_shared<converter::AudioEventConverter>( name, frequency, session );

  converter_->registerCallback( message_actions::PUBLISH, boost::bind(&publisher::BasicPublisher<naoqi_bridge_msgs::AudioBuffer>::publish, publisher_, _1) );
  converter_->registerCallback( message_actions::RECORD, boost::bind(&recorder::BasicEventRecorder<naoqi_bridge_msgs::AudioBuffer>::write, recorder_, _1) );
  converter_->registerCallback( message_actions::LOG, boost::bind(&recorder::BasicEventRecorder<naoqi_bridge_msgs::AudioBuffer>::bufferize, recorder_, _1) );

}
Ejemplo n.º 2
0
bool SessionInitializer::setUpNightmare(qi::SessionPtr session, const std::string &serviceDirectoryUrl)
{
  std::string serviceName;

  // #1 Connect session to service directory.
  if(session->connect(serviceDirectoryUrl).wait(1000) != qi::FutureState_FinishedWithValue)
    return false;

  // #1.1 If session is a client session, that's it.
  if (_listen == false)
    return true;

  // #1.2 Make session listen.
  session->listen("tcp://0.0.0.0:0");

  // #2 Allocate population and traffic tools.
  _populationGenerator = new PopulationGenerator();
  _trafficGenerator = new TrafficGenerator();

  // #3 Generate an unique name for hidder service
  if (DefaultService::generateUniqueServiceName(serviceName) == false)
    throw TestSessionError("[Internal] Cannot generate unique service name.");

  // #4 Register hidden service.
  session->registerService(serviceName, DefaultService::getDefaultService());

  // #5 Populate with client session and generate traffic.
  if (_populationGenerator->populateClients(serviceDirectoryUrl, 10000) == false)
    return false;

  if (_trafficGenerator->generateCommonTraffic(_populationGenerator->clientPopulation(), serviceName) == false)
    return false;

  return true;
}
Ejemplo n.º 3
0
bool SessionInitializer::setUpSD(qi::SessionPtr session, const std::string &serviceDirectoryUrl)
{
  session->connect(serviceDirectoryUrl);

  if (_listen == true)
    session->listen("tcp://0.0.0.0:0");

  return true;
}
Ejemplo n.º 4
0
bool SessionInitializer::setUpSSL(qi::SessionPtr session, const std::string &serviceDirectoryUrl)
{
  if(session->connect(serviceDirectoryUrl).wait(1000) != qi::FutureState_FinishedWithValue)
    return false;

  if (_listen == true)
  {
    session->setIdentity("../tests/server.key", "../tests/server.crt");
    session->listen("tcps://0.0.0.0:0");
  }

  return true;
}
Ejemplo n.º 5
0
bool SessionInitializer::tearDownSD(qi::SessionPtr session)
{
  if (session->close().wait(1000) != qi::FutureState_FinishedWithValue)
    return false;

  return true;
}
Ejemplo n.º 6
0
void alternateModule(qi::SessionPtr session) {
  while (!boost::this_thread::interruption_requested())
  {
    boost::this_thread::interruption_point();
    //a--;
    qi::AnyObject obj = newObject();
    qi::Future<unsigned int> fut = session->registerService("TestToto", obj);
    if (fut.hasError()) {
      std::cout << "Error registering service: " << fut.error() << std::endl;
      continue;
    }
    std::cout << "Service TestToto registered" << std::endl;
    qi::os::msleep(50);
    qi::Future<void> futun = session->unregisterService(fut.value());
    if (futun.hasError()) {
      std::cout << "Error unregistering service: " << futun.error() << std::endl;
      continue;
    }
    std::cout << "Service TestToto unregistered" << std::endl;
  }
}
Ejemplo n.º 7
0
bool SessionInitializer::tearDownNightmare(qi::SessionPtr session)
{
  if (_trafficGenerator)
    _trafficGenerator->stopTraffic();

  delete _populationGenerator;
  delete _trafficGenerator;

  if (session->close().wait(1000) != qi::FutureState_FinishedWithValue)
    return false;

  return true;
}
Ejemplo n.º 8
0
PeopleEventRegister<T>::PeopleEventRegister( const std::string& name, const std::vector<std::string> keys, const float& frequency, const qi::SessionPtr& session )
  : serviceId(0),
    p_memory_( session->service("ALMemory")),
    session_(session),
    isStarted_(false),
    isPublishing_(false),
    isRecording_(false),
    isDumping_(false)
{
  publisher_ = boost::make_shared<publisher::BasicPublisher<T> >( name );
  //recorder_ = boost::make_shared<recorder::BasicEventRecorder<T> >( name );
  converter_ = boost::make_shared<converter::PeopleEventConverter<T> >( name, frequency, session );

  converter_->registerCallback( message_actions::PUBLISH, boost::bind(&publisher::BasicPublisher<T>::publish, publisher_, _1) );
  //converter_->registerCallback( message_actions::RECORD, boost::bind(&recorder::BasicEventRecorder<T>::write, recorder_, _1) );
  //converter_->registerCallback( message_actions::LOG, boost::bind(&recorder::BasicEventRecorder<T>::bufferize, recorder_, _1) );

  keys_.resize(keys.size());
  size_t i = 0;
  for(std::vector<std::string>::const_iterator it = keys.begin(); it != keys.end(); ++it, ++i)
    keys_[i] = *it;

  name_ = name;
}
Ejemplo n.º 9
0
MovetoSubscriber::MovetoSubscriber( const std::string& name, const std::string& topic, const qi::SessionPtr& session,
                                    const boost::shared_ptr<tf2_ros::Buffer>& tf2_buffer):
  BaseSubscriber( name, topic, session ),
  p_motion_( session->service("ALMotion") ),
  tf2_buffer_( tf2_buffer )
{}
Ejemplo n.º 10
0
static void session_close(qi::SessionPtr s, qi::Atomic<int>* counter)
{
  s->close();
  ++(*counter);
}
Ejemplo n.º 11
0
LifeStatusSubscriber::LifeStatusSubscriber(const std::string& name, const std::string& life_status, const qi::SessionPtr& session):
	life_status_(life_status),
	BaseSubscriber(name, life_status, session),
	p_life_status_(session->service("ALAutonomousLife"))
{}