// 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>

#pragma once

#ifdef Q_OS_WINPHONE
    #include <queue>
    #include <agile.h>

namespace CppUIThreadComponent
{
	public delegate void DequeueActivity(Platform::String^ sName);

	class UIDispatchActivity abstract
	{
	public:
		virtual void DoActivity() = 0;
		virtual Platform::String^ Name() = 0;
	};

	public ref class ComponentDispatcher sealed
	{
	public:
		ComponentDispatcher();
		void SetDequeueDelegate(DequeueActivity^ delegate) 
				{ m_delegate = delegate; };
		void DequeueUIDispatchActivity();

	internal:
		void EnqueueUIDispatchActivity(UIDispatchActivity* pActivity);

	private:
		std::queue<UIDispatchActivity*> m_qDispatch;
		Platform::Agile<DequeueActivity> m_delegate;
	};
}

CppUIThreadComponent::ComponentDispatcher^ GetNativeDispatcher();

#endif
