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 : Paul Strauss (MMM yyyy) 00026 ** Modified by : Gavin Bell (MMM yyyy) 00027 **=======================================================================*/ 00028 /*======================================================================= 00029 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00030 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00031 *** *** 00032 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00033 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00034 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00035 *** *** 00036 *** RESTRICTED RIGHTS LEGEND *** 00037 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00038 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00039 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00040 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00041 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00042 *** *** 00043 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00044 *** BORDEAUX, FRANCE *** 00045 *** ALL RIGHTS RESERVED *** 00046 **=======================================================================*/ 00047 /*======================================================================= 00048 ** Modified by : VSG (MMM YYYY) 00049 **=======================================================================*/ 00050 00051 00052 #ifndef _SO_SENSOR_ 00053 #define _SO_SENSOR_ 00054 00055 #include <Inventor/SbBasic.h> 00056 #include <Inventor/threads/SbThreadSpinlock.h> 00057 00058 class SoField; 00059 class SoMField; 00060 class SoSensor; 00061 00065 typedef void SoSensorCB(void *data, SoSensor *sensor); 00066 00068 // 00069 // Class: SoSensor 00070 // 00071 // Abstract base class for all sensors. Defines basic callback 00072 // definition (explicit or in constructor) and scheduling and 00073 // triggering methods. 00074 // 00076 00098 class SoSensor { 00099 00100 public: 00101 00105 SoSensor() 00106 { 00107 func = NULL; 00108 funcData = NULL; 00109 #ifdef _WIN32 00110 dwThreadId=GetCurrentThreadId(); 00111 #endif 00112 m_schedule = FALSE; 00113 } 00118 SoSensor(SoSensorCB *f, void *d) 00119 { 00120 func = f; 00121 funcData = d; 00122 #ifdef _WIN32 00123 dwThreadId=GetCurrentThreadId(); 00124 #endif 00125 m_schedule = FALSE; 00126 } 00127 00128 // Virtual destructor so that subclasses are deleted properly 00129 #ifndef HIDDEN_FROM_DOC 00130 virtual ~SoSensor(); 00131 #endif // HIDDEN_FROM_DOC 00132 00136 inline void setFunction(SoSensorCB *f, void *userData); 00137 00145 void setFunction(SoSensorCB *f) 00146 { 00147 func = f; 00148 #ifdef _WIN32 00149 dwThreadId=GetCurrentThreadId(); 00150 #endif 00151 00152 } 00153 00158 void setData(void *d) { funcData = d; } 00159 00164 SoSensorCB * getFunction() const { return func; } 00165 00170 void * getData() const { return funcData; } 00171 00172 // Schedules the sensor for triggering at the appropriate time 00173 virtual void schedule() = 0; 00174 00175 // Unschedules sensor to keep it from being triggered 00176 virtual void unschedule() = 0; 00177 00183 virtual SbBool isScheduled() const 00184 { return m_schedule; } 00185 00186 private: 00187 00188 // take critical section ownership 00189 inline void lock() 00190 { m_mutex.lock(); } 00191 00192 // release critical section ownership 00193 inline void unlock() 00194 { m_mutex.unlock(); } 00195 00196 00197 // This must be called only by the SensorManager when it add/remove the sensor from its queues. 00198 // with the queue locked (in Multithread) to be ensure that this flag reflect the real state 00199 // of the sensor. 00200 inline void setScheduleFlag(SbBool flag) 00201 { m_schedule = flag; }; 00202 00203 #ifdef _WIN32 00204 DWORD getThreadId() { return dwThreadId;}; 00205 void setThreadId(DWORD id) { dwThreadId=id;}; 00206 #endif 00207 00208 // Initialize static members, etc. 00209 static void initClass(); 00210 00211 // Triggers the sensor, calling its callback function 00212 virtual void trigger(); 00213 00214 // This returns TRUE if this sensor should precede sensor s in 00215 // whichever queue this sensor would be in. 00216 virtual SbBool isBefore(const SoSensor *s) const = 0; 00217 00218 // Sets/returns the next sensor in whichever queue the sensor is in 00219 void setNextInQueue(SoSensor *next) { nextInQueue = next; } 00220 SoSensor * getNextInQueue() const { return nextInQueue; } 00221 00222 private: 00223 SoSensorCB * func; // Callback function 00224 void * funcData; // Data to pass to callback 00225 00226 #ifdef _WIN32 00227 DWORD dwThreadId; // thread to which this sensor belongs 00228 00229 private: 00230 #else 00231 private: 00232 #endif 00233 SoSensor *nextInQueue; // Next sensor in queue 00234 private: 00235 SbBool m_schedule; // Whether sensor is scheduled in a queue or not. 00236 SbThreadSpinlock m_mutex; 00237 }; 00238 00239 void SoSensor::setFunction(SoSensorCB *f, void *userData) 00240 { 00241 setFunction(f); 00242 setData(userData); 00243 } 00244 00245 #endif /* _SO_SENSOR_ */ 00246 00247 00248