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? } }
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; }
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; }