#include "mysingalthreadtimer.h"



MySingalThreadTimer* MySingalThreadTimer::m_pMySingalThreadTimer = nullptr;

MySingalThreadTimer::MySingalThreadTimer(QObject *parent)
	: QThread(parent)
{
	m_pTimer = nullptr;
}

MySingalThreadTimer::~MySingalThreadTimer()
{
	
}

MySingalThreadTimer* MySingalThreadTimer::GetInstance()
{
	if (m_pMySingalThreadTimer == nullptr)
	{
		m_pMySingalThreadTimer = new MySingalThreadTimer(nullptr);
	}
	return m_pMySingalThreadTimer;
}

void MySingalThreadTimer::FreeInstance()
{
	if (m_pMySingalThreadTimer)
	{
		delete m_pMySingalThreadTimer;
		m_pMySingalThreadTimer = nullptr;
	}
}


void MySingalThreadTimer::InitTimerObjects()
{
	if (m_pTimer == nullptr)
	{
		m_pTimer = new MyTimer();			
		//m_pTimer->CreateRunableFactory();
		m_pTimer->setInterval(1000/*2 * 60 * 60 *1000*/ );
		m_pTimer->start();
		connect(m_pTimer, SIGNAL(timeout()), m_pTimer, SLOT(timout_Slot()),Qt::DirectConnection);
	}	
}

void MySingalThreadTimer::StartTimer()
{
	if (m_pTimer)
	{
		m_pTimer->m_bRuning  = true;
	}
}

void MySingalThreadTimer::StopTimer()
{
	if (m_pTimer)
	{
		m_pTimer->m_bRuning  = false;
	}	
}

void MySingalThreadTimer::run()
{
	DeleteAllTimer();
	InitTimerObjects();
	exec();
}

void MySingalThreadTimer::timout_Slot()
{
	
}

void MySingalThreadTimer::DeleteAllTimer()
{
	if (m_pTimer)
	{
		m_pTimer->m_bRuning  = false;
		m_pTimer->stop();
		delete m_pTimer;
		m_pTimer = nullptr;
	}
}
