Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoMemoryError.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 : Paul S. Strauss (MMM yyyy)
25**=======================================================================*/
26/*=======================================================================
27 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
28 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
29 *** ***
30 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
31 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
32 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
33 *** ***
34 *** RESTRICTED RIGHTS LEGEND ***
35 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
36 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
37 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
38 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
39 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
40 *** ***
41 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49
50#ifndef _SO_MEMORY_ERROR
51#define _SO_MEMORY_ERROR
52
53#include <Inventor/errors/SoError.h>
54
55class SbThreadMutex;
56class SoMemoryError;
57
74typedef bool SoMemoryCleanupCB(const size_t requestedByteSize, void* data);
75
96class SoMemoryError : public SoError {
97
98 public:
99
103 static void setHandlerCallback(SoErrorCB *cb, void *data);
104
110
115 static void* getHandlerData();
116
121 static void setMemoryCleanupCallback(SoMemoryCleanupCB *cb, void * data);
122
127
131 virtual SoType getTypeId() const;
132
136 static void post(const SbString& whatWasAllocated);
137
141 static void post(const char* whatWasAllocated);
142
143 private:
144 // Initializes SoMemoryError class
145 static void initClass();
146 static void exitClass();
147 static SoErrorCB* getDefaultHandlerCB() { return defaultHandlerCB; }
148 static bool getMemorySpace(const size_t size);
149
150 private:
151 // Returns handler callback (and data) to use for a given instance
152 virtual SoErrorCB * getHandler(void *&data) const;
153 virtual bool isInit() const;
154
155 private:
156 // Type id of SoMemoryError class
157 static SoType classTypeId;
158 // Handler callback for class
159 static SoErrorCB *handlerCB;
160 // User data for callback
161 static void *cbData;
162 // TRUE if handler initialized
163 static SbBool wasInitted;
164
165 static SoMemoryError* s_memoryErrorObject;
166 static SbThreadMutex* s_threadMutex;
167 static SbString* s_memoryErrorString;
168
169 // This allow to avoid infinite loop in this code
170 // when user set an error callback that need allocation itself.
171 static bool s_memoryFreeSpaceLoop;
172 static SoMemoryCleanupCB* s_memoryCleanupCB;
173 static void* s_memoryCleanupData;
174
175};
176
177#endif /* _SO_MEMORY_ERROR */
178
Class for smart character strings.
Definition SbString.h:202
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
Error handling base class.
Definition SoError.h:109
void SoErrorCB(const SoError *error, void *data)
Error handling callbacks are of this type.
Definition SoError.h:69
Memory error handling.
virtual SoType getTypeId() const
Returns type identifier for an instance of this class.
bool SoMemoryCleanupCB(const size_t requestedByteSize, void *data)
Memory cleanup handling callback.
static void setHandlerCallback(SoErrorCB *cb, void *data)
Sets handler callback for SoMemoryError class.
static SoType getClassTypeId()
Returns type identifier for SoMemoryError class.
static void setMemoryCleanupCallback(SoMemoryCleanupCB *cb, void *data)
Sets memory cleanup handler callback for SoMemoryError class.
static void * getHandlerData()
Returns handler data for SoMemoryError class.
static void post(const char *whatWasAllocated)
Posts an error.
static void post(const SbString &whatWasAllocated)
Posts an error.
static SoErrorCB * getHandlerCallback()
Returns handler callback for SoMemoryError class.
Stores runtime type information.
Definition SoType.h:98
int SbBool
Boolean type.
Definition SbBase.h:87