| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/* |
| 38 |
* Copyright (C) 1990,91,92 Silicon Graphics, Inc. |
| 39 |
* |
| 40 |
_______________________________________________________________________ |
| 41 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 42 |
| |
| 43 |
| $Revision: 1.1.1.1 $ |
| 44 |
| |
| 45 |
| Classes: |
| 46 |
| SoTimerQueueSensor |
| 47 |
| |
| 48 |
| Author(s) : Paul Strauss, Gavin Bell |
| 49 |
| |
| 50 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 51 |
_______________________________________________________________________ |
| 52 |
*/ |
| 53 |
////////////////////////////////////////////////////////////////////////////// |
| 54 |
|
| 55 |
#include <Inventor/SoDB.h> |
| 56 |
#include <Inventor/sensors/SoTimerQueueSensor.h> |
| 57 |
|
| 58 |
//////////////////////////////////////////////////////////////////////// |
| 59 |
// |
| 60 |
// Description: |
| 61 |
// Constructor |
| 62 |
// |
| 63 |
// Use: protected |
| 64 |
|
| 65 |
SoTimerQueueSensor::SoTimerQueueSensor() : SoSensor() |
| 66 |
// |
| 67 |
//////////////////////////////////////////////////////////////////////// |
| 68 |
{ |
| 69 |
scheduled = FALSE; |
| 70 |
} |
| 71 |
|
| 72 |
//////////////////////////////////////////////////////////////////////// |
| 73 |
// |
| 74 |
// Description: |
| 75 |
// Constructor with function and data. |
| 76 |
// |
| 77 |
// Use: protected |
| 78 |
|
| 79 |
SoTimerQueueSensor::SoTimerQueueSensor(SoSensorCB *func, void *data) : |
| 80 |
SoSensor(func, data) |
| 81 |
// |
| 82 |
//////////////////////////////////////////////////////////////////////// |
| 83 |
{ |
| 84 |
scheduled = FALSE; |
| 85 |
} |
| 86 |
|
| 87 |
//////////////////////////////////////////////////////////////////////// |
| 88 |
// |
| 89 |
// Description: |
| 90 |
// Destructor |
| 91 |
// |
| 92 |
// Use: protected |
| 93 |
|
| 94 |
SoTimerQueueSensor::~SoTimerQueueSensor() |
| 95 |
// |
| 96 |
//////////////////////////////////////////////////////////////////////// |
| 97 |
{ |
| 98 |
// Make sure sensor isn't still scheduled to be triggered |
| 99 |
unschedule(); |
| 100 |
} |
| 101 |
|
| 102 |
//////////////////////////////////////////////////////////////////////// |
| 103 |
// |
| 104 |
// Description: |
| 105 |
// Schedules the sensor to be triggered by inserting it into timer queue. |
| 106 |
// |
| 107 |
// Use: public, virtual |
| 108 |
|
| 109 |
void |
| 110 |
SoTimerQueueSensor::schedule() |
| 111 |
// |
| 112 |
//////////////////////////////////////////////////////////////////////// |
| 113 |
{ |
| 114 |
// Don't do anything if there's no callback function or it is |
| 115 |
// already scheduled: |
| 116 |
if (func == NULL || scheduled == TRUE) |
| 117 |
return; |
| 118 |
|
| 119 |
// Insert into queue |
| 120 |
SoDB::getSensorManager()->insertTimerSensor(this); |
| 121 |
|
| 122 |
scheduled = TRUE; |
| 123 |
} |
| 124 |
|
| 125 |
//////////////////////////////////////////////////////////////////////// |
| 126 |
// |
| 127 |
// Description: |
| 128 |
// Unschedules the sensor. |
| 129 |
// |
| 130 |
// Use: public, virtual |
| 131 |
|
| 132 |
void |
| 133 |
SoTimerQueueSensor::unschedule() |
| 134 |
// |
| 135 |
//////////////////////////////////////////////////////////////////////// |
| 136 |
{ |
| 137 |
if (scheduled) { |
| 138 |
// Remove from queue |
| 139 |
SoDB::getSensorManager()->removeTimerSensor(this); |
| 140 |
|
| 141 |
scheduled = FALSE; |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
//////////////////////////////////////////////////////////////////////// |
| 146 |
// |
| 147 |
// Description: |
| 148 |
// Returns TRUE if sensor is scheduled. |
| 149 |
// |
| 150 |
// Use: public, virtual |
| 151 |
|
| 152 |
SbBool |
| 153 |
SoTimerQueueSensor::isScheduled() const |
| 154 |
// |
| 155 |
//////////////////////////////////////////////////////////////////////// |
| 156 |
{ |
| 157 |
return scheduled; |
| 158 |
} |
| 159 |
|
| 160 |
//////////////////////////////////////////////////////////////////////// |
| 161 |
// |
| 162 |
// Description: |
| 163 |
// Set the trigger time. If the sensor is scheduled, this |
| 164 |
// unschedules and reschedules it. |
| 165 |
// |
| 166 |
// Use: protected |
| 167 |
|
| 168 |
void |
| 169 |
SoTimerQueueSensor::setTriggerTime(const SbTime &time) |
| 170 |
// |
| 171 |
//////////////////////////////////////////////////////////////////////// |
| 172 |
{ |
| 173 |
trigTime = time; |
| 174 |
if (isScheduled()) { |
| 175 |
SoDB::getSensorManager()->removeTimerSensor(this); |
| 176 |
SoDB::getSensorManager()->insertTimerSensor(this); |
| 177 |
} |
| 178 |
} |
| 179 |
//////////////////////////////////////////////////////////////////////// |
| 180 |
// |
| 181 |
// Description: |
| 182 |
// Triggers the sensor, calling its callback function. This |
| 183 |
// overrides the method in SoSensor because it has to reset the |
| 184 |
// schedule flag before triggering. |
| 185 |
// |
| 186 |
// Use: protected |
| 187 |
|
| 188 |
void |
| 189 |
SoTimerQueueSensor::trigger() |
| 190 |
// |
| 191 |
//////////////////////////////////////////////////////////////////////// |
| 192 |
{ |
| 193 |
// Mark the sensor as unscheduled |
| 194 |
scheduled = FALSE; |
| 195 |
|
| 196 |
// Do the normal triggering stuff |
| 197 |
SoSensor::trigger(); |
| 198 |
} |
| 199 |
|
| 200 |
//////////////////////////////////////////////////////////////////////// |
| 201 |
// |
| 202 |
// Description: |
| 203 |
// Returns TRUE if this sensor should precede sensor s in the timer |
| 204 |
// queue: it must have an earlier trigger time. |
| 205 |
// |
| 206 |
// Use: private, virtual |
| 207 |
|
| 208 |
SbBool |
| 209 |
SoTimerQueueSensor::isBefore(const SoSensor *s) const |
| 210 |
// |
| 211 |
//////////////////////////////////////////////////////////////////////// |
| 212 |
{ |
| 213 |
// We must assume that s is also an SoTimerQueueSensor |
| 214 |
return (getTriggerTime() <= |
| 215 |
((const SoTimerQueueSensor *) s)->getTriggerTime()); |
| 216 |
} |
| 217 |
|