Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoSensor.h
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-2024 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>
56#include <Inventor/threads/SbThreadSpinlock.h>
57
58class SoField;
59class SoMField;
60class SoSensor;
61
68typedef void SoSensorCB(void *data, SoSensor *sensor);
69
71//
72// Class: SoSensor
73//
74// Abstract base class for all sensors. Defines basic callback
75// definition (explicit or in constructor) and scheduling and
76// triggering methods.
77//
79
100class SoSensor {
101
102 public:
103
108 {
109 func = NULL;
110 funcData = NULL;
111#ifdef _WIN32
112 dwThreadId=GetCurrentThreadId();
113#endif
114 m_schedule = FALSE;
115 }
120 SoSensor(SoSensorCB *f, void *d)
121 {
122 func = f;
123 funcData = d;
124#ifdef _WIN32
125 dwThreadId=GetCurrentThreadId();
126#endif
127 m_schedule = FALSE;
128 }
129
130 // Virtual destructor so that subclasses are deleted properly
131#ifndef HIDDEN_FROM_DOC
132 virtual ~SoSensor();
133#endif // HIDDEN_FROM_DOC
134
138 inline void setFunction(SoSensorCB *f, void *userData);
139
148 {
149 func = f;
150#ifdef _WIN32
151 dwThreadId=GetCurrentThreadId();
152#endif
153
154 }
155
160 void setData(void *d) { funcData = d; }
161
166 SoSensorCB * getFunction() const { return func; }
167
172 void * getData() const { return funcData; }
173
174 // Schedules the sensor for triggering at the appropriate time
175 virtual void schedule() = 0;
176
177 // Unschedules sensor to keep it from being triggered
178 virtual void unschedule() = 0;
179
185 virtual SbBool isScheduled() const
186 { return m_schedule; }
187
188 private:
189
190 // take critical section ownership
191 inline void lock()
192 { m_mutex.lock(); }
193
194 // release critical section ownership
195 inline void unlock()
196 { m_mutex.unlock(); }
197
198
199 // This must be called only by the SensorManager when it add/remove the sensor from its queues.
200 // with the queue locked (in Multithread) to be ensure that this flag reflect the real state
201 // of the sensor.
202 inline void setScheduleFlag(SbBool flag)
203 { m_schedule = flag; };
204
205#ifdef _WIN32
206 DWORD getThreadId() { return dwThreadId;};
207 void setThreadId(DWORD id) { dwThreadId=id;};
208#endif
209
210 // Initialize static members, etc.
211 static void initClass();
212
213 // Triggers the sensor, calling its callback function
214 virtual void trigger();
215
216 // This returns TRUE if this sensor should precede sensor s in
217 // whichever queue this sensor would be in.
218 virtual SbBool isBefore(const SoSensor *s) const = 0;
219
220 // Sets/returns the next sensor in whichever queue the sensor is in
221 void setNextInQueue(SoSensor *next) { nextInQueue = next; }
222 SoSensor * getNextInQueue() const { return nextInQueue; }
223
224 private:
225 SoSensorCB * func; // Callback function
226 void * funcData; // Data to pass to callback
227
228#ifdef _WIN32
229 DWORD dwThreadId; // thread to which this sensor belongs
230
231 private:
232#else
233 private:
234#endif
235 SoSensor *nextInQueue; // Next sensor in queue
236 private:
237 SbBool m_schedule; // Whether sensor is scheduled in a queue or not.
238 SbThreadSpinlock m_mutex;
239};
240
241void SoSensor::setFunction(SoSensorCB *f, void *userData)
242{
243 setFunction(f);
244 setData(userData);
245}
246
247#endif /* _SO_SENSOR_ */
248
249
<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:100
SoSensor(SoSensorCB *f, void *d)
Constructor that takes standard callback function and data.
Definition SoSensor.h:120
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:147
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:185
void * getData() const
Returns the user-supplied pointer that will be passed to the callback function.
Definition SoSensor.h:172
void setFunction(SoSensorCB *f, void *userData)
Definition SoSensor.h:241
SoSensorCB * getFunction() const
Returns the callback that will be called when the sensor is triggered.
Definition SoSensor.h:166
SoSensor()
Constructor.
Definition SoSensor.h:107
void setData(void *d)
Sets the callback data passed to the callback function.
Definition SoSensor.h:160
void SoSensorCB(void *data, SoSensor *sensor)
This typedef defines the calling sequence for all callbacks from sensors.
Definition SoSensor.h:68
int SbBool
Boolean type.
Definition SbBase.h:87