Ejemplo n.º 1
0
void InputService::processQueue(EventQueue& queue)
{
	// Send events which are piled on queue so far
	size_t numEvents = queue.size(); // TODO: Do we have to limit by numEvents?

	while (!queue.empty())
	{
		EventEntry& e = queue.front();

		EventId id = e.eventID;
		Ref<InputEvent> evt = e.event;
		queue.pop_front();

		if (evt && evt->isConsumed())
			continue;

		EventChannel* channel = e.channel;
		if (channel)
		{
			// If channel specified on post : Send to that channel
			channel->send(id, evt);
			continue;
		}

		// When channel not specified: broadcast upward from source channel

		if (evt == NULL)
			continue; // Can't handle event with no channel specified.

		// 1. Broadcast to source channel
		Ref<InputSource> source = evt->getSource();
		if (source && source->hasChannel())
		{
			source->channel()->send(id, evt);
			if (evt->isConsumed() || !evt->isUplinking())
				continue;
		}

		// 2. Broadcast to device channel
		Weak<InputDevice> device = evt->getDevice();
		if (device && device->hasChannel())
		{
			device->channel()->send(id, evt);
			if (evt->isConsumed() || !evt->isUplinking())
				continue;
		}

		// 3. Broadcast to user channel
		Ref<InputUser> user = evt->getUser();

		if (user && user->hasChannel())
		{
			user->channel()->send(id, evt);
			if (evt->isConsumed() || !evt->isUplinking())
				continue;
		}

		// TODO: 4. Broadcast to service channel?
	}
}
Ejemplo n.º 2
0
	/**
	 * Processes all of the scheduled delegates until there are no more to execute.
	 * Sleeps when waiting for a scheduled delegate to be ready to invoke to reduce processor usage.
	 */
	static void Run() { StackTrace trace(__METHOD__, __FILE__, __LINE__);
		while (FutureEvents.empty() == false) {
			FutureEventHandler event = FutureEvents.top();
			FutureEvents.pop();
			Sleep(event.Time() - DateTime::Utc());
			event();
		}
	}
	bool ___updateEventQueue(TimeType t, TimeType & currTime, EventQueue & eventQueue)
	{
		currTime += t;
		if(eventQueue.empty())
			return false;

		
		if(currTime >= eventQueue.front().first)
		{
			eventQueue.front().second();
			eventQueue.pop();
			currTime = 0.0f;
		}
		
		return true;
	
	}
Ejemplo n.º 4
0
  void AbstractDevice::eventThread() {
    ADR_GUARD("AbstractDevice::eventThread");
    m_thread_exists = true;
    while (!m_thread_should_die) {
      m_event_mutex.lock();
      while (m_events.empty()) {
        m_events_available.wait(m_event_mutex, 1);
        if (m_thread_should_die) {
          break;
        }
      }
      if (m_thread_should_die) {
        m_event_mutex.unlock();
        break;
      }

      // Make a local copy of the events so they can be processed without
      // leaving the mutex locked.
      EventQueue events = m_events;

      // Queues don't support clear().  o_o
      while (!m_events.empty()) {
        m_events.pop();
      }

      m_event_mutex.unlock();

      // Process the events.
      while (!events.empty()) {
        EventPtr event = events.front();
        events.pop();
        processEvent(event.get());
      }
    }
    m_thread_exists = false;
  }
Ejemplo n.º 5
0
Archivo: txn.cpp Proyecto: maoy/mosaic
void
demux(Event e)
{
  if (e.t) 
    std::cout << "in demux " << e.type << " "<< *e.t << std::endl;
  else
    std::cout << "in demux (null tuple) " << e.type <<  std::endl;
  assert(e.type==Event::RECV || e.type == Event::NONE);
  mainloop(e);
  while (!taskQ.empty()){
    e = taskQ.dequeue();
    std::cout << "in demux loop" << e.type << " "<< *e.t << std::endl;
    assert(e.type==Event::RECV || e.type == Event::NONE);
    mainloop(e);
  }
  
  /*
  TxnContext ctx = g_txnManager->create();
  demux_handler(e, ctx);
  taskQ.commitTables();
  view_maintenance( taskQ, ctx );
  g_txnManager->commit(ctx);
  */
}