00001 /*======================================================================= 00002 * Copyright 1991-1996, Silicon Graphics, Inc. 00003 * ALL RIGHTS RESERVED 00004 * 00005 * UNPUBLISHED -- Rights reserved under the copyright laws of the United 00006 * States. Use of a copyright notice is precautionary only and does not 00007 * imply publication or disclosure. 00008 * 00009 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: 00010 * Use, duplication or disclosure by the Government is subject to restrictions 00011 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights 00012 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or 00013 * in similar or successor clauses in the FAR, or the DOD or NASA FAR 00014 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., 00015 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. 00016 * 00017 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY 00018 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, 00019 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY 00020 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON 00021 * GRAPHICS, INC. 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Author : Nick Thompson (MMM yyyy) 00025 ** Modified by : Gavin Bell (MMM yyyy) 00026 **=======================================================================*/ 00027 /*======================================================================= 00028 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00029 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00030 *** *** 00031 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00032 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00033 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00034 *** *** 00035 *** RESTRICTED RIGHTS LEGEND *** 00036 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00037 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00038 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00039 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00040 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00041 *** *** 00042 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, *** 00043 *** BORDEAUX, FRANCE *** 00044 *** ALL RIGHTS RESERVED *** 00045 **=======================================================================*/ 00046 /*======================================================================= 00047 ** Modified by : VSG (MMM YYYY) 00048 **=======================================================================*/ 00049 00050 00051 #ifndef _SO_SENSOR_MANAGER_ 00052 #define _SO_SENSOR_MANAGER_ 00053 00054 #include <Inventor/misc/SoBasic.h> 00055 #include <Inventor/SbTime.h> 00056 00057 class SoSensor; 00058 class SoDelayQueueSensor; 00059 class SoTimerQueueSensor; 00060 class SoTimerSensor; 00061 class SoAlarmSensor; 00062 class SoSensorManagerThread; 00063 class SbDict; 00064 00065 { 00066 00067 public: 00068 // Constructor, destructor 00069 SoSensorManager(); 00070 ~SoSensorManager(); 00071 00072 // Set up a function to call when either queue has a sensor added 00073 // or removed 00074 void setChangedCallback(void (*func)(void *), void *data); 00075 00076 // Insert/remove an delay or timer event into/from the appropriate queue 00077 void insertDelaySensor(SoDelayQueueSensor *s); 00078 void insertTimerSensor(SoTimerQueueSensor *s); 00079 void removeDelaySensor(SoDelayQueueSensor *s); 00080 void removeTimerSensor(SoTimerQueueSensor *s); 00081 00082 // Timers are all rescheduled at the same time, after they have 00083 // been triggered. This avoids timer queue saturation. 00084 void rescheduleTimer(SoTimerSensor *s); 00085 void removeRescheduledTimer(SoTimerQueueSensor *s); 00086 00087 // Set/get delay queue sensors (OneShot, Node, Path, etc) 00088 // timeout value. Delay sensor go off whenever there is idle time 00089 // or when the timeout expires. 00090 void setDelaySensorTimeout(const SbTime &t); 00091 const SbTime &getDelaySensorTimeout(); 00092 00093 // Process all sensors in the delay queue. The isIdle flag should 00094 // be TRUE if the delay queue is being processed because there is 00095 // idle time; it should be false if it is being processed because 00096 // the delay sensor timeout has expired. 00097 void processDelayQueue(SbBool isIdle); 00098 00099 // Process all immediate (priority 0) sensors in the delay queue 00100 void processImmediateQueue(); 00101 00102 // Process appropriate sensors in the timer queue based on current time 00103 void processTimerQueue(); 00104 00105 // Returns TRUE if there is at least one sensor in the delay queue 00106 SbBool isDelaySensorPending(); 00107 00108 // Returns TRUE if there is at least one sensor in the timer 00109 // queue. If there is one, the time of the first sensor is placed 00110 // in tm. 00111 SbBool isTimerSensorPending(SbTime &tm); 00112 00113 // Just like UNIX select() call, but checks sensor queues while 00114 // waiting for events. 00115 int doSelect(int nfds, fd_set *readfds, fd_set *writefds, 00116 fd_set *exceptfds, 00117 struct timeval *userTimeOut); 00118 00119 // 00120 static void init(); 00121 static void finish(); 00122 00123 // return true if IV_DEBUG_SENSORS was set at startup 00124 static bool isIvDebugSensorsSet() 00125 {return s_ivDebugSensors;} 00126 00127 #ifdef _WIN32 00128 private: 00129 #else 00130 private: 00131 #endif 00132 SoSensor *delayQueue; // Head of delay sensor queue 00133 SoSensor *timerQueue; // Head of timer sensor queue 00134 SoSensor *rescheduleQueue;// Timers ready to be rescheduled 00135 00136 // These are used to process the delay queue every once in a 00137 // while: 00138 SbTime delayQTimeout; 00139 SoAlarmSensor *delayQTimeoutSensor; 00140 static void delayQTimeoutCB(void *, SoSensor *); 00141 00142 // Non-zero when processing a queue. The changedCallback will not 00143 // be called when we are in the middle of processing a queue, and 00144 // the immediate queue uses this to avoid recursion. Because a 00145 // timer sensor might decide to process the delay queue in its 00146 // trigger method, this is an integer instead of a simple Boolean. 00147 int processingQueue; 00148 00149 uint32_t delayQCount; // Avoids loops processing delay queue 00150 00151 // Insert/remove an entry into/from the queue with the given head 00152 void insert(SoSensor *s, SoSensor *&head); 00153 void remove(SoSensor *s, SoSensor *&head); 00154 00155 // Callback which is called whenever a sensor is inserted or removed 00156 void (*changedFunc)(void *); 00157 void *changedFuncData; 00158 00159 // Calls the changed callback, if there is one 00160 void notifyChanged(); 00161 00162 private: 00163 #ifdef _WIN32 00164 // IMPORTANT: see header doc of SoInventorBase::isMultiThreadApplication. 00165 // Note to implementer : to manage isMultiThreadApplication mode without breaking 00166 // standard multiThread mode we must alway use m_pThreadSensorMgr 00167 // constructor and destructor or init/finish will do the job to correctly init it. 00168 SoSensorManagerThread* m_pThreadSensorMgr; 00169 static SoSensorManagerThread* s_pThreadSensorMgr; 00170 00171 #endif 00172 static bool s_ivDebugSensors; 00173 00174 }; 00175 00176 #endif /* _SO_SENSOR_MANAGER_ */ 00177 00178