// This code was taken from https://github.com/robwirving/CppUIThreadApp
// http://www.robwirving.com/2013/07/17/guide-to-getting-to-the-ui-thread-for-any-type-of-windows-phone-8-app/
// http://www.robwirving.com/2014/06/02/getting-to-the-ui-thread-from-a-windows-phone-winrt-component/

#include <QObject>

#ifdef Q_OS_WINPHONE

#include "pch.h"
#include "UIDispatchActivity.h"

CppUIThreadComponent::ComponentDispatcher^ g_NativeDispatcher;

CppUIThreadComponent::ComponentDispatcher^ GetNativeDispatcher()
{
	return g_NativeDispatcher;
}

namespace CppUIThreadComponent 
{
	ComponentDispatcher::ComponentDispatcher()
	{
		g_NativeDispatcher = this;
	}

	void ComponentDispatcher::DequeueUIDispatchActivity()
	{
		// This method is called from the C# dispatcher on the UI Thread!
		m_qDispatch.front()->DoActivity();
		m_qDispatch.pop();
	}

	void ComponentDispatcher::EnqueueUIDispatchActivity(UIDispatchActivity* pActivity)
	{
		m_qDispatch.push(pActivity);
		m_delegate->Invoke(pActivity->Name());
	}
}

#endif
