2011-02-25 11:28:33 +00:00
|
|
|
/*
|
2002-10-12 11:37:38 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
* This program 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.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
2011-02-25 11:28:33 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup GHOST
|
2002-12-28 22:26:45 +00:00
|
|
|
* Declaration of GHOST_TimerTask class.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
#include "GHOST_ITimerTask.h"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implementation of a timer task.
|
|
|
|
|
*/
|
|
|
|
|
class GHOST_TimerTask : public GHOST_ITimerTask {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Constructor.
|
2020-11-06 14:18:55 +11:00
|
|
|
* \param start: The timer start time.
|
|
|
|
|
* \param interval: The interval between calls to the #timerProc.
|
|
|
|
|
* \param timerProc: The callback invoked when the interval expires.
|
2015-07-01 16:30:26 +10:00
|
|
|
* \param userData: The timer user data.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2021-07-05 10:10:20 -07:00
|
|
|
GHOST_TimerTask(uint64_t start,
|
|
|
|
|
uint64_t interval,
|
2011-12-24 02:32:08 +00:00
|
|
|
GHOST_TimerProcPtr timerProc,
|
2013-03-08 06:32:00 +00:00
|
|
|
GHOST_TUserDataPtr userData = NULL)
|
2011-12-24 02:32:08 +00:00
|
|
|
: m_start(start),
|
2012-05-19 09:23:08 +00:00
|
|
|
m_interval(interval),
|
|
|
|
|
m_next(start),
|
|
|
|
|
m_timerProc(timerProc),
|
|
|
|
|
m_userData(userData),
|
|
|
|
|
m_auxData(0)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the timer start time.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \return The timer start time.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2021-07-05 10:10:20 -07:00
|
|
|
inline uint64_t getStart() const
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
return m_start;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Changes the timer start time.
|
2020-11-06 14:18:55 +11:00
|
|
|
* \param start: The timer start time.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2021-07-05 10:10:20 -07:00
|
|
|
void setStart(uint64_t start)
|
2018-06-04 18:47:57 +02:00
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
m_start = start;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the timer interval.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \return The timer interval.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2021-07-05 10:10:20 -07:00
|
|
|
inline uint64_t getInterval() const
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
return m_interval;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Changes the timer interval.
|
2020-11-06 14:18:55 +11:00
|
|
|
* \param interval: The timer interval.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2021-07-05 10:10:20 -07:00
|
|
|
void setInterval(uint64_t interval)
|
2018-06-04 18:47:57 +02:00
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
m_interval = interval;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the time the timerProc will be called.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \return The time the timerProc will be called.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2021-07-05 10:10:20 -07:00
|
|
|
inline uint64_t getNext() const
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
return m_next;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Changes the time the timerProc will be called.
|
2020-11-06 14:18:55 +11:00
|
|
|
* \param next: The time the timerProc will be called.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2021-07-05 10:10:20 -07:00
|
|
|
void setNext(uint64_t next)
|
2018-06-04 18:47:57 +02:00
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
m_next = next;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the timer callback.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \return the timer callback.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2015-02-08 14:18:53 -05:00
|
|
|
inline GHOST_TimerProcPtr getTimerProc() const
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
return m_timerProc;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Changes the timer callback.
|
2015-07-01 16:30:26 +10:00
|
|
|
* \param timerProc: The timer callback.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2015-02-08 14:18:53 -05:00
|
|
|
inline void setTimerProc(const GHOST_TimerProcPtr timerProc)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
m_timerProc = timerProc;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the timer user data.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \return The timer user data.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2015-02-08 14:18:53 -05:00
|
|
|
inline GHOST_TUserDataPtr getUserData() const
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
return m_userData;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Changes the time user data.
|
2015-07-01 16:30:26 +10:00
|
|
|
* \param userData: The timer user data.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2015-02-08 14:18:53 -05:00
|
|
|
void setUserData(const GHOST_TUserDataPtr userData)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
m_userData = userData;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the auxiliary storage room.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \return The auxiliary storage room.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2021-07-05 10:10:20 -07:00
|
|
|
inline uint32_t getAuxData() const
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
return m_auxData;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Changes the auxiliary storage room.
|
2020-11-06 14:18:55 +11:00
|
|
|
* \param auxData: The auxiliary storage room.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2021-07-05 10:10:20 -07:00
|
|
|
void setAuxData(uint32_t auxData)
|
2018-06-04 18:47:57 +02:00
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
m_auxData = auxData;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
protected:
|
|
|
|
|
/** The time the timer task was started. */
|
2021-07-05 10:10:20 -07:00
|
|
|
uint64_t m_start;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/** The interval between calls. */
|
2021-07-05 10:10:20 -07:00
|
|
|
uint64_t m_interval;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/** The time the timerProc will be called. */
|
2021-07-05 10:10:20 -07:00
|
|
|
uint64_t m_next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/** The callback invoked when the timer expires. */
|
|
|
|
|
GHOST_TimerProcPtr m_timerProc;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/** The timer task user data. */
|
|
|
|
|
GHOST_TUserDataPtr m_userData;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/** Auxiliary storage room. */
|
2021-07-05 10:10:20 -07:00
|
|
|
uint32_t m_auxData;
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|