Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoSensor.h
Go to the documentation of this file.
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Nick Thompson (MMM yyyy)
25** Modified by : Paul Strauss (MMM yyyy)
26** Modified by : Gavin Bell (MMM yyyy)
27**=======================================================================*/
28/*=======================================================================
29 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
30 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
31 *** ***
32 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
33 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
34 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
35 *** ***
36 *** RESTRICTED RIGHTS LEGEND ***
37 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
38 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
39 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
40 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
41 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
42 *** ***
43 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, ***
44 *** BORDEAUX, FRANCE ***
45 *** ALL RIGHTS RESERVED ***
46**=======================================================================*/
47/*=======================================================================
48** Modified by : VSG (MMM YYYY)
49**=======================================================================*/
50
51
52#ifndef _SO_SENSOR_
53#define _SO_SENSOR_
54
55#include <Inventor/SbBasic.h>
57
58class SoField;
59class SoMField;
60class SoSensor;
61
65typedef void SoSensorCB(void *data, SoSensor *sensor);
66
68//
69// Class: SoSensor
70//
71// Abstract base class for all sensors. Defines basic callback
72// definition (explicit or in constructor) and scheduling and
73// triggering methods.
74//
76
97class SoSensor {
98
99 public:
100
105 {
106 func = NULL;
107 funcData = NULL;
108#ifdef _WIN32
109 dwThreadId=GetCurrentThreadId();
110#endif
111 m_schedule = FALSE;
112 }
117 SoSensor(SoSensorCB *f, void *d)
118 {
119 func = f;
120 funcData = d;
121#ifdef _WIN32
122 dwThreadId=GetCurrentThreadId();
123#endif
124 m_schedule = FALSE;
125 }
126
127 // Virtual destructor so that subclasses are deleted properly
128#ifndef HIDDEN_FROM_DOC
129 virtual ~SoSensor();
130#endif // HIDDEN_FROM_DOC
131
135 inline void setFunction(SoSensorCB *f, void *userData);
136
145 {
146 func = f;
147#ifdef _WIN32
148 dwThreadId=GetCurrentThreadId();
149#endif
150
151 }
152
157 void setData(void *d) { funcData = d; }
158
163 SoSensorCB * getFunction() const { return func; }
164
169 void * getData() const { return funcData; }
170
171 // Schedules the sensor for triggering at the appropriate time
172 virtual void schedule() = 0;
173
174 // Unschedules sensor to keep it from being triggered
175 virtual void unschedule() = 0;
176
182 virtual SbBool isScheduled() const
183 { return m_schedule; }
184
185 private:
186
187 // take critical section ownership
188 inline void lock()
189 { m_mutex.lock(); }
190
191 // release critical section ownership
192 inline void unlock()
193 { m_mutex.unlock(); }
194
195
196 // This must be called only by the SensorManager when it add/remove the sensor from its queues.
197 // with the queue locked (in Multithread) to be ensure that this flag reflect the real state
198 // of the sensor.
199 inline void setScheduleFlag(SbBool flag)
200 { m_schedule = flag; };
201
202#ifdef _WIN32
203 DWORD getThreadId() { return dwThreadId;};
204 void setThreadId(DWORD id) { dwThreadId=id;};
205#endif
206
207 // Initialize static members, etc.
208 static void initClass();
209
210 // Triggers the sensor, calling its callback function
211 virtual void trigger();
212
213 // This returns TRUE if this sensor should precede sensor s in
214 // whichever queue this sensor would be in.
215 virtual SbBool isBefore(const SoSensor *s) const = 0;
216
217 // Sets/returns the next sensor in whichever queue the sensor is in
218 void setNextInQueue(SoSensor *next) { nextInQueue = next; }
219 SoSensor * getNextInQueue() const { return nextInQueue; }
220
221 private:
222 SoSensorCB * func; // Callback function
223 void * funcData; // Data to pass to callback
224
225#ifdef _WIN32
226 DWORD dwThreadId; // thread to which this sensor belongs
227
228 private:
229#else
230 private:
231#endif
232 SoSensor *nextInQueue; // Next sensor in queue
233 private:
234 SbBool m_schedule; // Whether sensor is scheduled in a queue or not.
235 SbThreadSpinlock m_mutex;
236};
237
238void SoSensor::setFunction(SoSensorCB *f, void *userData)
239{
240 setFunction(f);
241 setData(userData);
242}
243
244#endif /* _SO_SENSOR_ */
245
246
#define FALSE
Possible value of SbBool.
Definition SbBase.h:75
void SoSensorCB(void *data, SoSensor *sensor)
This typedef defines the calling sequence for all callbacks from sensors.
Definition SoSensor.h:65
uint32_t DWORD
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable spinloc...
void lock()
Request exclusive access for this spinlock.
void unlock()
Release exclusive access.
Base class for all fields.
Definition SoField.h:234
Base class for all multiple-valued fields.
Definition SoMField.h:134
Abstract base class for Open Inventor sensors.
Definition SoSensor.h:97
SoSensor(SoSensorCB *f, void *d)
Constructor that takes standard callback function and data.
Definition SoSensor.h:117
virtual void unschedule()=0
virtual void schedule()=0
void setFunction(SoSensorCB *f)
Sets the callback function that is called when the sensor is triggered.
Definition SoSensor.h:144
virtual SbBool isScheduled() const
Returns TRUE if this sensor has been scheduled and is waiting in a sensor queue to be triggered.
Definition SoSensor.h:182
void * getData() const
Returns the user-supplied pointer that will be passed to the callback function.
Definition SoSensor.h:169
void setFunction(SoSensorCB *f, void *userData)
Definition SoSensor.h:238
SoSensorCB * getFunction() const
Returns the callback that will be called when the sensor is triggered.
Definition SoSensor.h:163
SoSensor()
Constructor.
Definition SoSensor.h:104
void setData(void *d)
Sets the callback data passed to the callback function.
Definition SoSensor.h:157
int SbBool
Boolean type.
Definition SbBase.h:87