1 /**************************************************************************\
2  * Copyright (c) Kongsberg Oil & Gas Technologies AS
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32 
33 /*!
34   \class SoAlarmSensor SoAlarmSensor.h Inventor/sensors/SoAlarmSensor.h
35   \brief The SoAlarmSensor class is a sensor which will trigger once at a specified time.
36 
37   \ingroup sensors
38 
39   SoAlarmSensor provides a convenient way of setting up triggers for
40   jobs which should be executed only once when they are scheduled.
41  */
42 
43 #include <Inventor/sensors/SoAlarmSensor.h>
44 #include <cassert>
45 
46 #if COIN_DEBUG
47 #include <Inventor/errors/SoDebugError.h>
48 #endif // COIN_DEBUG
49 
50 /*!
51   Default constructor.
52  */
SoAlarmSensor(void)53 SoAlarmSensor::SoAlarmSensor(void)
54 {
55 }
56 
57 /*!
58   Constructor taking as parameters the sensor callback function and
59   the userdata which will be passed the callback.
60 
61   \sa setFunction(), setData()
62  */
SoAlarmSensor(SoSensorCB * func,void * data)63 SoAlarmSensor::SoAlarmSensor(SoSensorCB * func, void * data)
64   : inherited(func, data)
65 {
66 }
67 
68 /*!
69   Destructor.
70 */
~SoAlarmSensor(void)71 SoAlarmSensor::~SoAlarmSensor(void)
72 {
73 }
74 
75 /*!
76   Set the time at which the sensor will trigger.
77 
78   Note that you must manually schedule() the sensor after calling this
79   method.
80 
81   \sa setTimeFromNow(), getTime()
82  */
83 void
setTime(const SbTime & abstime)84 SoAlarmSensor::setTime(const SbTime & abstime)
85 {
86   this->alarm = abstime;
87 }
88 
89 /*!
90   Set the alarm to be at a specified offset from the current time.
91 
92   Note that you must manually schedule() the sensor after calling this
93   method.
94 
95   \sa setTime(), getTime()
96  */
97 void
setTimeFromNow(const SbTime & reltime)98 SoAlarmSensor::setTimeFromNow(const SbTime & reltime)
99 {
100   this->alarm.setToTimeOfDay();
101   this->alarm += reltime;
102 }
103 
104 /*!
105   Returns the trigger time for the alarm as an absolute value from
106   1970-01-01 00:00:00.
107 
108   \sa setTime(), setTimeFromNow()
109  */
110 const SbTime &
getTime(void) const111 SoAlarmSensor::getTime(void) const
112 {
113   return this->alarm;
114 }
115 
116 // Doc from superclass.
117 void
schedule(void)118 SoAlarmSensor::schedule(void)
119 {
120   this->setTriggerTime(this->alarm);
121   inherited::schedule();
122 }
123