Exemple #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?
	}
}