/usr/include/crystalspace-2.0/csutil/schedule.h is in libcrystalspace-dev 2.0+dfsg-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | /*
Copyright (C) 2000 by W.C.A. Wijngaards
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CS_SCHEDULE_H__
#define __CS_SCHEDULE_H__
/**\file
* Timer support
*/
#include "csextern.h"
class csSchedulePart;
/**
* The csSchedule class provides an easy way to get timers in applications.
* It can handle both repeating and single-shot callbacks. It is useful
* for handling time in 3D virtual worlds.
* <p>
* Use it like this:
* \code
* class myEntity
* {
* public:
* virtual void Update();
* };
* \endcode
* <p>
* Suppose you have an object of class myEntity, which looks like a button
* in your virtual world, and you want the button to blink. Calling Update
* every NextFrame would look bad, and handling the timing yourself is
* a hassle (and can be lots slower then mass-handling by csSchedule). So
* you can use the csSchedule to call the myEntity::Update method every
* second.
* <p>
* You can do it this way:
* \code
* void call_entity_update(void *arg)
* {
* myEntity *mp = (myEntity*)arg;
* mp->Update();
* }
* \endcode
* <p>
* You would then use the csSchedule method
* AddCallback(call_entity_update, (void*)my_entity, 1000);
* to have it call the function with the object pointer as argument after
* 1000 milliseconds (= 1 second) once.
* or you can use:
* AddRepeatCallback(call_entity_update, (void*)my_entity, 1000);
* to have the function called repeatedly, every 1000 msec (= second).
* <p>
* To notify the schedule that time has passed, each frame, for example
* in the NextFrame() method, you must call the TimePassed(elapsed_time)
* function.
* <p>
* This class is useful for callbacks in 3D virtual worlds, but the callbacks
* can have some jitter due to framerates. For mission-critical hardware IO
* calls (like controlling a floppy drive or controlling the UART) this jitter
* will be too big. In those cases use interrupt-driven callbacks, and place
* the controlling code in some platform-specific implementation file, since
* this type of use is typically platform-dependent. However, although this
* class cannot give callbacks inside a single frame, it will behave as best as
* possible using callbacks every frame.
*/
class CS_CRYSTALSPACE_EXPORT csSchedule
{
private:
/// first part of the scheduled callbacks
csSchedulePart *first;
/// internal, insert part given msec after now into list
void InsertCall(csSchedulePart *part, int afternow);
/// internal, unlink part from list given prev. (prev can be 0)
void RemoveCall(csSchedulePart *prev, csSchedulePart *part);
public:
/// create an empty schedule
csSchedule();
///
~csSchedule();
/**
* Notify the schedule that time has passed, elapsed_time is in msec.
* It will update the internal data and call any callbacks if necessary.
*/
void TimePassed(int elapsed_time);
/**
* Add a single-shot callback
* the function must be of type: void function(void *arg)
* arg is passed as argument to the function.
* delay: the function is called this many msec have passed.
*/
void AddCallback(void (*func)(void*), void *arg, int delay);
/**
* Add a repeating callback
* the function must be of type: void function(void *arg)
* arg is passed as argument to the function.
* period: the function is called every time this many msec pass.
*/
void AddRepeatCallback(void (*func)(void*), void *arg, int period);
/**
* Remove a repeating callback.
* (if multiple identical calls exist, the first is removed)
*/
void RemoveCallback(void (*func)(void*), void *arg, int period);
/**
* Remove a single-shot callback.
* (if multiple identical calls exist, the first is removed)
*/
void RemoveCallback(void (*func)(void*), void *arg);
/**
* Remove a single-shot or repeating callback.
* (if multiple identical calls exist, all are removed)
* removes all callbacks using given argument, whatever their function
* or period. Useful if the argument in question is an object that is
* destructed.
* So, in a class myEntity, in ~myEntity() you can call:
* schedule->RemoveCallback(this);
*/
void RemoveCallback(void *arg);
};
#endif // __CS_SCHEDULE_H__
|