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 : Paul S. Strauss (MMM yyyy) 00025 **=======================================================================*/ 00026 /*======================================================================= 00027 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00028 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00029 *** *** 00030 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00031 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00032 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00033 *** *** 00034 *** RESTRICTED RIGHTS LEGEND *** 00035 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00036 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00037 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00038 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00039 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00040 *** *** 00041 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00042 *** BORDEAUX, FRANCE *** 00043 *** ALL RIGHTS RESERVED *** 00044 **=======================================================================*/ 00045 /*======================================================================= 00046 ** Modified by : VSG (MMM YYYY) 00047 **=======================================================================*/ 00048 00049 00050 #ifndef _SO_MEMORY_ERROR 00051 #define _SO_MEMORY_ERROR 00052 00053 #include <Inventor/errors/SoError.h> 00054 00055 class SbThreadMutex; 00056 class SoMemoryError; 00057 00072 typedef bool SoMemoryCleanupCB(const size_t requestedByteSize, void* data); 00073 00094 class SoMemoryError : public SoError { 00095 00096 public: 00097 00101 static void setHandlerCallback(SoErrorCB *cb, void *data); 00102 00107 static SoErrorCB* getHandlerCallback(); 00108 00113 static void* getHandlerData(); 00114 00119 static void setMemoryCleanupCallback(SoMemoryCleanupCB *cb, void * data); 00120 00124 static SoType getClassTypeId(); 00125 00129 virtual SoType getTypeId() const; 00130 00134 static void post(const SbString& whatWasAllocated); 00135 00139 static void post(const char* whatWasAllocated); 00140 00141 private: 00142 // Initializes SoMemoryError class 00143 static void initClass(); 00144 static void exitClass(); 00145 static SoErrorCB* getDefaultHandlerCB() { return defaultHandlerCB; } 00146 static bool getMemorySpace(const size_t size); 00147 00148 private: 00149 // Returns handler callback (and data) to use for a given instance 00150 virtual SoErrorCB * getHandler(void *&data) const; 00151 virtual bool isInit() const; 00152 00153 private: 00154 // Type id of SoMemoryError class 00155 static SoType classTypeId; 00156 // Handler callback for class 00157 static SoErrorCB *handlerCB; 00158 // User data for callback 00159 static void *cbData; 00160 // TRUE if handler initialized 00161 static SbBool wasInitted; 00162 00163 static SoMemoryError* s_memoryErrorObject; 00164 static SbThreadMutex* s_threadMutex; 00165 static SbString* s_memoryErrorString; 00166 00167 // This allow to avoid infinite loop in this code 00168 // when user set an error callback that need allocation itself. 00169 static bool s_memoryFreeSpaceLoop; 00170 static SoMemoryCleanupCB* s_memoryCleanupCB; 00171 static void* s_memoryCleanupData; 00172 00173 }; 00174 00175 #endif /* _SO_MEMORY_ERROR */ 00176 00177