2002-08-02 19:57:46 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
#include "CTimerThread.h"
|
|
|
|
#include "CThread.h"
|
|
|
|
#include "TMethodJob.h"
|
2001-10-14 18:29:43 +00:00
|
|
|
#include "CLog.h"
|
2003-01-04 22:01:32 +00:00
|
|
|
#include "CArch.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// CTimerThread
|
|
|
|
//
|
|
|
|
|
|
|
|
CTimerThread::CTimerThread(double timeout) : m_timeout(timeout)
|
|
|
|
{
|
2002-06-09 22:20:01 +00:00
|
|
|
if (m_timeout >= 0.0) {
|
|
|
|
m_callingThread = new CThread(CThread::getCurrentThread());
|
|
|
|
m_timingThread = new CThread(new TMethodJob<CTimerThread>(
|
2001-10-06 14:13:28 +00:00
|
|
|
this, &CTimerThread::timer));
|
2002-06-09 22:20:01 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_callingThread = NULL;
|
|
|
|
m_timingThread = NULL;
|
|
|
|
}
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CTimerThread::~CTimerThread()
|
|
|
|
{
|
2002-06-09 22:20:01 +00:00
|
|
|
if (m_timingThread != NULL) {
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "cancelling timeout"));
|
2002-06-09 22:20:01 +00:00
|
|
|
m_timingThread->cancel();
|
|
|
|
m_timingThread->wait();
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "cancelled timeout"));
|
2002-06-09 22:20:01 +00:00
|
|
|
delete m_timingThread;
|
|
|
|
delete m_callingThread;
|
|
|
|
}
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CTimerThread::timer(void*)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "timeout in %f seconds", m_timeout));
|
2003-01-04 22:01:32 +00:00
|
|
|
ARCH->sleep(m_timeout);
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "timeout"));
|
2001-10-06 14:13:28 +00:00
|
|
|
m_callingThread->cancel();
|
|
|
|
}
|