CTimer *CTimer::Instance()
{
if (g_singleinstance == 0)
g_singleinstance = new CTimer;
return g_singleinstance;
}
void CTimer::SetInterval(long second)
{
m_second = second * 2;
}
void CTimer::StartTimer()
{
if (!(m_rtcfd > 0))
{
cout<<"TimerWarning: rtcfd < 0...Start failed..."<<endl;
return;
}
if(ioctl(m_rtcfd, RTC_PIE_ON, 0) < 0)
{
cout<<"TimerWarning: ioctl(RTC_PIE_ON) failed..."<<endl;
close(m_rtcfd);
return;
}
m_counter = 0;
}
void CTimer::StopTimer()
{
if (!(m_rtcfd > 0))
{
cout<<"TimerWarning: rtcfd < 0...Stop failed..."<<endl;
return;
}
if(ioctl(m_rtcfd, RTC_PIE_OFF, 0) < 0)
{
cout<<"TimerWarning: ioctl(RTC_PIE_ON) failed..."<<endl;
close(m_rtcfd);
return;
}
}