Esempio n. 1
0
int ChatServer::handle_data(ACE_SOCK_Stream *client)
{
	if (DLOG)
	{
		printf("\n");
		Util::log("[ChatServer::handle_data] START\n");
	}

	// Place the connection into blocking mode since this
	// thread isn't doing anything except handling this client.
	client->disable(ACE_NONBLOCK);

	PacketHandler handler = PacketHandler(*client);
	ServerPacketListener spl = ServerPacketListener(handler);
		
	// Keep handling chat messages until client closes connection
	// or this thread is asked to cancel itself.
	ACE_Thread_Manager *mgr = ACE_Thread_Manager::instance();
	ACE_thread_t me = ACE_Thread::self();
	while (!mgr->testcancel(me) &&
		handler.processPacket(spl) != 0)
		continue;
	handler.close();

	if (DLOG) Util::log("[ChatServer::handle_data] END\n");
	return 0;
}
Esempio n. 2
0
  int
  FrameStoreUpdaterSvc::svc()
  {
    // set up RAPID frame-updaters
    rapid::FsConfigUpdater fsConfigUpdater(*m_frameStore);

    typedef kn::shared_ptr<rapid::FsPositionUpdater> FsPositionUpdaterPtr;
    typedef kn::shared_ptr<rapid::FsJointUpdater> FsJointUpdaterPtr;

    std::vector<FsPositionUpdaterPtr>  fsPositionUpdaters;
    std::vector<FsJointUpdaterPtr> fsJointUpdaters;
    
    kn::DdsEventLoop eventLoop(svcName);
    
    
    // connect RAPID frame-updaters for local-robot updates
    if (m_params->frameStoreConfig.enabled) {      
      eventLoop.connect<rapid::FrameStoreConfig>(&fsConfigUpdater, rapid::FRAMESTORE_CONFIG_TOPIC +
                                                 m_params->frameStoreConfig.topicSuffix,
                                                 m_params->frameStoreConfig.parentNode,
                                                 m_params->frameStoreConfig.profile,
                                                 m_params->frameStoreConfig.library);
    }
    
    for (unsigned int i = 0; i < m_params->positionUpdaters.size(); ++i) {
      fsPositionUpdaters.push_back(FsPositionUpdaterPtr(new rapid::FsPositionUpdater(*m_frameStore, 
                                                                                     m_params->positionUpdaters[i])));
      fsPositionUpdaters.back()->connect(eventLoop);
    }
    
    for (unsigned int i = 0; i < m_params->jointUpdaters.size(); ++i) {
      fsJointUpdaters.push_back(FsJointUpdaterPtr(new rapid::FsJointUpdater(*m_frameStore,
                                                                            m_params->jointUpdaters[i])));
      fsJointUpdaters.back()->connect(eventLoop);
    }

    // enter processing loop
    MIRO_LOG(LL_NOTICE, "Entering (detached) rapid framestore update loop.");
    ACE_Thread_Manager * mgr = this->thr_mgr();
    while (!mgr->testcancel(mgr->thr_self())) {

      // 10Hz processing
      eventLoop.processEvents(kn::microseconds(100000));
    }

    MIRO_LOG(LL_NOTICE, "Exiting (detached) rapid framestore updater loop.");

    return 0;
  }
int Thread_Per_Connection_Logging_Server::handle_data(ACE_SOCK_Stream *client)
{
    ACE_FILE_IO log_file;
    make_log_file(log_file, client);

    client->disable(ACE_NONBLOCK);

    Logging_Handler logging_handler(log_file, *client);
    ACE_Thread_Manager *tm = ACE_Thread_Manager::instance();
    ACE_thread_t me = ACE_OS::thr_self();

    while (!tm->testcancel(me) && logging_handler.log_record() != -1)
        continue;

    log_file.close();
    return 0;
}
  //
  // Now the svc() method where everything interesting happens.
  //
  int
  ReactorTask::svc()
  {
    MIRO_DBG_OSTR(MIRO, LL_DEBUG,
                  "[Miro::ReactorTask] 0x" << (void*)this <<
                  " starts in thread " << ACE_Thread::self());

    ACE_Time_Value timeout(0, 100000); // wait for 100 msec
    ACE_Time_Value delta;              // uninitialized time value

    // set the given thread scheduling policy

    if (ACE_OS::sched_params(schedp_) == -1) {
      MIRO_LOG_OSTR(LL_ERROR, "[Miro::ReactorTask] Could not set sched parameters." << std::endl
                    << "[Miro::ReactorTask] Maybe suid root is missing." << std::endl
                    << "[Miro::ReactorTask] Will work on default scheduling policy." << std::endl);
    }

    // set the thread to be the owner of the reactor,
    //otherwise we will get errors
    reactor_.owner(ACE_OS::thr_self());

    ACE_Thread_Manager * mgr = this->thr_mgr();

    try {
      while (!mgr->testcancel(mgr->thr_self())) {
        // set delta to timeout
        // handle_events decrements the timeout
        delta = timeout;
        // trigger message handling
        reactor_.handle_events(delta);
      }
    }
    catch (const Miro::Exception& e) {
      MIRO_LOG_OSTR(LL_ERROR, "ReactorTask.handleMessage() - Uncaught Miro exception: " << e << std::endl);
      conditionalShutdown();
    }
    catch (...) {
      MIRO_LOG(LL_ERROR, "[Miro::HwReactor] task terminated due to unknown exception.");
      conditionalShutdown();
    }

    return 0;
  }
int
Thread_Per_Connection_Logging_Server::handle_data (ACE_SOCK_Stream *client)
{
  ACE_FILE_IO log_file;
  // Client's hostname is logfile name.
  make_log_file (log_file, client);

  // Place the connection into blocking mode since this
  // thread isn't doing anything except handling this client.
  client->disable (ACE_NONBLOCK);

  Logging_Handler logging_handler (log_file, *client);

  // Keep handling log records until client closes connection
  // or this thread is asked to cancel itself.
  ACE_Thread_Manager *mgr = ACE_Thread_Manager::instance ();
  ACE_thread_t me = ACE_Thread::self ();
  while (!mgr->testcancel (me) &&
         logging_handler.log_record () != -1)
    continue;

  log_file.close ();
  return 0;
}