2011-02-25 11:28:33 +00:00
|
|
|
/*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
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-01-07 19:13:47 +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.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2011-02-25 11:28:33 +00:00
|
|
|
|
|
|
|
/** \file ghost/intern/GHOST_TimerManager.h
|
|
|
|
* \ingroup GHOST
|
2003-01-01 19:57:02 +00:00
|
|
|
* Declaration of GHOST_TimerManager class.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#ifndef __GHOST_TIMERMANAGER_H__
|
|
|
|
#define __GHOST_TIMERMANAGER_H__
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "GHOST_Types.h"
|
|
|
|
|
|
|
|
class GHOST_TimerTask;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages a list of timer tasks.
|
|
|
|
* Timer tasks added are owned by the manager.
|
|
|
|
* Don't delete timer task objects.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \author Maarten Gribnau
|
|
|
|
* \date May 31, 2001
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
class GHOST_TimerManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
GHOST_TimerManager();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
2015-02-08 19:18:53 +00:00
|
|
|
~GHOST_TimerManager();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of timer tasks.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \return The number of events on the stack.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2015-02-08 19:18:53 +00:00
|
|
|
GHOST_TUns32 getNumTimers();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/**
|
2014-08-12 00:31:07 +00:00
|
|
|
* Returns whether this timer task ins in our list.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \return Indication of presence.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2015-02-08 19:18:53 +00:00
|
|
|
bool getTimerFound(GHOST_TimerTask *timer);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a timer task to the list.
|
|
|
|
* It is only added when it not already present in the list.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \param timer The timer task added to the list.
|
|
|
|
* \return Indication as to whether addition has succeeded.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2015-02-08 19:18:53 +00:00
|
|
|
GHOST_TSuccess addTimer(GHOST_TimerTask *timer);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a timer task from the list.
|
|
|
|
* It is only removed when it is found in the list.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \param timer The timer task to be removed from the list.
|
|
|
|
* \return Indication as to whether removal has succeeded.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2015-02-08 19:18:53 +00:00
|
|
|
GHOST_TSuccess removeTimer(GHOST_TimerTask *timer);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the soonest time the next timer would fire.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \return The soonest time the next timer would fire,
|
2002-10-12 11:37:38 +00:00
|
|
|
* or GHOST_kFireTimeNever if no timers exist.
|
|
|
|
*/
|
2015-02-08 19:18:53 +00:00
|
|
|
GHOST_TUns64 nextFireTime();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks all timer tasks to see if they are expired and fires them if needed.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \param time The current time.
|
|
|
|
* \return True if any timers were fired.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2015-02-08 19:18:53 +00:00
|
|
|
bool fireTimers(GHOST_TUns64 time);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks this timer task to see if they are expired and fires them if needed.
|
2012-09-06 02:10:09 +00:00
|
|
|
* \param time The current time.
|
|
|
|
* \param task The timer task to check and optionally fire.
|
|
|
|
* \return True if the timer fired.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2015-02-08 19:18:53 +00:00
|
|
|
bool fireTimer(GHOST_TUns64 time, GHOST_TimerTask *task);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Deletes all timers.
|
|
|
|
*/
|
|
|
|
void disposeTimers();
|
|
|
|
|
2012-05-19 09:23:08 +00:00
|
|
|
typedef std::vector<GHOST_TimerTask *> TTimerVector;
|
2002-10-12 11:37:38 +00:00
|
|
|
/** The list with event consumers. */
|
|
|
|
TTimerVector m_timers;
|
2012-06-25 10:35:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_TimerManager")
|
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#endif // __GHOST_TIMERMANAGER_H__
|
2002-10-30 02:07:20 +00:00
|
|
|
|