
#include <Spectre/System/MessageQueue.h>

#ifdef SPECTRE_PLATFORM_WIN
#include <Platform/Win32/Win32EventQueue.h>
typedef sp::Win32EventQueue ImplType;
#elif SPECTRE_PLATFORM_UNIX
#include <Platform/Unix/X11EventQueue.h>
typedef sp::X11EventQueue ImplType;
#else
#error "No MessageQueue implementation exists"
#endif


namespace sp {

MessageQueue::MessageQueue()
{
	m_impl = new ImplType();
}

MessageQueue::~MessageQueue()
{
	delete m_impl;
}

void MessageQueue::postEvent(Event event)
{
	m_queue.push_back(event);
}

bool MessageQueue::pollEvent(Event& event)
{
	// Process platform events first.
	if (m_impl->poll(event)) {
		return true;
	}

	if (!isEmpty()) {
		event = m_queue.front();
		m_queue.pop_front();
		return true;
	}
	return false;
}

bool MessageQueue::isEmpty() const
{
	return m_queue.empty();
}

} // namespace sp
