Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoSensorManager.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 : Gavin Bell (MMM yyyy)
26**=======================================================================*/
27/*=======================================================================
28 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
29 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
30 *** ***
31 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
32 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
33 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
34 *** ***
35 *** RESTRICTED RIGHTS LEGEND ***
36 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
37 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
38 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
39 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
40 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
41 *** ***
42 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (MMM YYYY)
48**=======================================================================*/
49
50
51#ifndef _SO_SENSOR_MANAGER_
52#define _SO_SENSOR_MANAGER_
53
54#include <Inventor/misc/SoBasic.h>
55#include <Inventor/SbTime.h>
56
57class SoSensor;
60class SoTimerSensor;
61class SoAlarmSensor;
62class SoSensorManagerThread;
63class SbDict;
64
65{
66
67 public:
68 // Constructor, destructor
69 SoSensorManager();
70 ~SoSensorManager();
71
72 // Set up a function to call when either queue has a sensor added
73 // or removed
74 void setChangedCallback(void (*func)(void *), void *data);
75
76 // Insert/remove an delay or timer event into/from the appropriate queue
77 void insertDelaySensor(SoDelayQueueSensor *s);
78 void insertTimerSensor(SoTimerQueueSensor *s);
79 void removeDelaySensor(SoDelayQueueSensor *s);
80 void removeTimerSensor(SoTimerQueueSensor *s);
81
82 // Timers are all rescheduled at the same time, after they have
83 // been triggered. This avoids timer queue saturation.
84 void rescheduleTimer(SoTimerSensor *s);
85 void removeRescheduledTimer(SoTimerQueueSensor *s);
86
87 // Set/get delay queue sensors (OneShot, Node, Path, etc)
88 // timeout value. Delay sensor go off whenever there is idle time
89 // or when the timeout expires.
90 void setDelaySensorTimeout(const SbTime &t);
91 const SbTime &getDelaySensorTimeout();
92
93 // Process all sensors in the delay queue. The isIdle flag should
94 // be TRUE if the delay queue is being processed because there is
95 // idle time; it should be false if it is being processed because
96 // the delay sensor timeout has expired.
97 void processDelayQueue(SbBool isIdle);
98
99 // Process all immediate (priority 0) sensors in the delay queue
100 void processImmediateQueue();
101
102 // Process appropriate sensors in the timer queue based on current time
103 void processTimerQueue();
104
105 // Returns TRUE if there is at least one sensor in the delay queue
106 SbBool isDelaySensorPending();
107
108 // Returns TRUE if there is at least one sensor in the timer
109 // queue. If there is one, the time of the first sensor is placed
110 // in tm.
111 SbBool isTimerSensorPending(SbTime &tm);
112
113 // Just like UNIX select() call, but checks sensor queues while
114 // waiting for events.
115 int doSelect(int nfds, fd_set *readfds, fd_set *writefds,
116 fd_set *exceptfds,
117 struct timeval *userTimeOut);
118
119 //
120 static void init();
121 static void finish();
122
123 // return true if IV_DEBUG_SENSORS was set at startup
124 static bool isIvDebugSensorsSet()
125 {return s_ivDebugSensors;}
126
127#ifdef _WIN32
128 private:
129#else
130 private:
131#endif
132 SoSensor *delayQueue; // Head of delay sensor queue
133 SoSensor *timerQueue; // Head of timer sensor queue
134 SoSensor *rescheduleQueue;// Timers ready to be rescheduled
135
136 // These are used to process the delay queue every once in a
137 // while:
138 SbTime delayQTimeout;
139 SoAlarmSensor *delayQTimeoutSensor;
140 static void delayQTimeoutCB(void *, SoSensor *);
141
142 // Non-zero when processing a queue. The changedCallback will not
143 // be called when we are in the middle of processing a queue, and
144 // the immediate queue uses this to avoid recursion. Because a
145 // timer sensor might decide to process the delay queue in its
146 // trigger method, this is an integer instead of a simple Boolean.
147 int processingQueue;
148
149 uint32_t delayQCount; // Avoids loops processing delay queue
150
151 // Insert/remove an entry into/from the queue with the given head
152 void insert(SoSensor *s, SoSensor *&head);
153 void remove(SoSensor *s, SoSensor *&head);
154
155 // Callback which is called whenever a sensor is inserted or removed
156 void (*changedFunc)(void *);
157 void *changedFuncData;
158
159 // Calls the changed callback, if there is one
160 void notifyChanged();
161
162private:
163#ifdef _WIN32
164 // IMPORTANT: see header doc of SoInventorBase::isMultiThreadApplication.
165 // Note to implementer : to manage isMultiThreadApplication mode without breaking
166 // standard multiThread mode we must alway use m_pThreadSensorMgr
167 // constructor and destructor or init/finish will do the job to correctly init it.
168 SoSensorManagerThread* m_pThreadSensorMgr;
169 static SoSensorManagerThread* s_pThreadSensorMgr;
170
171#endif
172 static bool s_ivDebugSensors;
173
174};
175
176#endif /* _SO_SENSOR_MANAGER_ */
177
Class for representation of a time.
Definition SbTime.h:91
Triggers a delegate once sometime in the future.
Abstract base class for sensors not dependent on time.
Abstract base class for Open Inventor sensors.
Definition SoSensor.h:100
Abstract base class for sensors dependent on time.
Sensor that triggers repeatedly at regular intervals.
int SbBool
Boolean type.
Definition SbBase.h:87