1 /**************************************************************************\
2  * Copyright (c) Kongsberg Oil & Gas Technologies AS
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32 
33 #ifndef COIN_TIDBITSP_H
34 #define COIN_TIDBITSP_H
35 
36 #ifndef COIN_INTERNAL
37 #error this is a private header file
38 #endif
39 
40 #include <stdio.h>
41 #include <Inventor/C/tidbits.h>
42 #include <Inventor/C/basic.h>
43 #include <Inventor/C/base/string.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif /* __cplusplus */
48 
49 #if 0 /* to get proper auto-indentation in emacs */
50 }
51 #endif /* emacs indentation */
52 
53 /* ********************************************************************** */
54 
55 void coin_init_tidbits(void);
56 
57 /* ********************************************************************** */
58 
59 FILE * coin_get_stdin(void);
60 FILE * coin_get_stdout(void);
61 FILE * coin_get_stderr(void);
62 
63 /* ********************************************************************** */
64 
65 #define coin_atexit(func, priority) \
66         coin_atexit_func(SO__QUOTE(func), func, priority)
67 
68 void coin_atexit_cleanup(void);
69 
70 SbBool coin_is_exiting(void);
71 
72 /* this enum contains all values that are available for use for the
73    third argument to coin_atexit_func() -- no other values than these
74    should be used! */
75 enum coin_atexit_priorities {
76   /* Absolute priorities goes first */
77 
78   /* clean-ups of client code should be done before any clean-up code
79      within Coin happens, so this is (2^31 - 1): */
80   CC_ATEXIT_EXTERNAL = 2147483647,
81 
82   /* clean-up code with no particular dependencies should use this
83      code: */
84   CC_ATEXIT_NORMAL = 0,
85 
86   /* dynamically loaded libraries should be the last to go, as other
87      code in Coin will be dependent on functionality in these in its
88      own clean-up code: */
89   CC_ATEXIT_DYNLIBS = -2147483647,
90 
91   /* Relative priorities */
92 
93   /* The realTime field should be cleaned up before normal cleanups
94      are called, since the global field list will be cleaned up there.
95   */
96   CC_ATEXIT_REALTIME_FIELD = CC_ATEXIT_NORMAL + 10,
97 
98   /*
99     We need to clean up default parts for draggers before tracking SoBase instances
100    */
101   CC_ATEXIT_DRAGGERDEFAULTS = CC_ATEXIT_NORMAL + 2,
102 
103   /*
104     SoBase instance tracking should happen before normal cleanups
105   */
106   CC_ATEXIT_TRACK_SOBASE_INSTANCES = CC_ATEXIT_NORMAL + 1,
107 
108   /* Just after NORMAL */
109   CC_ATEXIT_NORMAL_LOWPRIORITY = CC_ATEXIT_NORMAL - 1,
110 
111   /*
112      Used to clean up static data for nodes/elements/nodekits ++
113      Must be done before the typesystem cleanup
114   */
115   CC_ATEXIT_STATIC_DATA = CC_ATEXIT_NORMAL - 10,
116 
117   /*
118      Cleanups for static SoDB data (sensor manager, converters++)
119    */
120   CC_ATEXIT_SODB = CC_ATEXIT_NORMAL - 20,
121   /*
122     SoBase (the base class) cleanup.
123    */
124   CC_ATEXIT_SOBASE = CC_ATEXIT_NORMAL - 30,
125 
126   /*
127     Typesystem cleanup.
128   */
129   CC_ATEXIT_SOTYPE  = CC_ATEXIT_NORMAL - 40,
130 
131   /* later, in case e.g. some nodes' clean-up depends on the font
132      subsystem still being up'n'running: */
133   CC_ATEXIT_FONT_SUBSYSTEM = CC_ATEXIT_NORMAL - 100,
134 
135   /* Just before FONT_SUBSYSTEM */
136   CC_ATEXIT_FONT_SUBSYSTEM_HIGHPRIORITY = CC_ATEXIT_FONT_SUBSYSTEM + 1,
137 
138   /* Just later than FONT_SUBSYSTEM */
139   CC_ATEXIT_FONT_SUBSYSTEM_LOWPRIORITY = CC_ATEXIT_FONT_SUBSYSTEM - 1,
140 
141   /* still later, so clean-up code can use e.g. SoDebugError to report
142      problems, output debugging info, etc: */
143   CC_ATEXIT_MSG_SUBSYSTEM = CC_ATEXIT_NORMAL - 200,
144   /*
145     Clean up the SbName dictionary. Should be done as late as
146     possible, since SbName is used a lot in other modules.
147   */
148   CC_ATEXIT_SBNAME = CC_ATEXIT_NORMAL - 500,
149 
150   /* needs to happen late, since CC_ATEXIT_NORMAL clean-up routines
151      will for instance often want to dealloc mutexes: */
152   CC_ATEXIT_THREADING_SUBSYSTEM = CC_ATEXIT_NORMAL - 1000,
153 
154   /* FIXME: Not sure if this is needed, refer comment by mortene where
155      enum is used in mutex.cpp - 20080711 BFG */
156   CC_ATEXIT_THREADING_SUBSYSTEM_LOWPRIORITY = CC_ATEXIT_THREADING_SUBSYSTEM - 1,
157 
158   /* FIXME: Not sure if this is needed, refer comment by mortene where
159      enum is used in thread.cpp - 20080711 BFG */
160   CC_ATEXIT_THREADING_SUBSYSTEM_VERYLOWPRIORITY = CC_ATEXIT_THREADING_SUBSYSTEM - 2,
161 
162   /* Needs to happen late, but before we cleanup our dynamic
163      libraries */
164   CC_ATEXIT_ENVIRONMENT = CC_ATEXIT_DYNLIBS + 10
165 
166 
167 };
168 
169 void coin_atexit_func(const char * name, coin_atexit_f * fp, coin_atexit_priorities priority);
170 
171 /* ********************************************************************** */
172 
173 /*
174   We're using these to ensure portable import and export even when the
175   application sets a locale with different thousands separator and
176   decimal point than the default "C" locale.
177 
178   Use these functions to wrap locale-aware functions where
179   necessary:
180 
181   \code
182   cc_string storedlocale;
183   SbBool changed = coin_locale_set_portable(&storedlocale);
184 
185   // [code with locale-aware functions]
186 
187   if (changed) { coin_locale_reset(&storedlocale); }
188   \endcode
189 
190   Possibly locale-aware functions includes at least atof(), atoi(),
191   atol(), strtol(), strtoul(), strtod(), strtof(), strtold(), and all
192   the *printf() functions.
193 */
194 
195 SbBool coin_locale_set_portable(cc_string * storeold);
196 void coin_locale_reset(cc_string * storedold);
197 
198 /*
199   Portable atof() function, which will not cause any trouble due to
200   underlying locale's decimal point setting.
201 */
202 double coin_atof(const char * ptr);
203 
204 /* ********************************************************************** */
205 
206 /*
207   Functions to output ascii85 encoded data. Used for instance for Postscript
208   image rendering.
209 */
210 void coin_output_ascii85(FILE * fp,
211                          const unsigned char val,
212                          unsigned char * tuple,
213                          unsigned char * linebuf,
214                          int * tuplecnt, int * linecnt,
215                          const int rowlen,
216                          const SbBool flush);
217 
218 void coin_flush_ascii85(FILE * fp,
219                         unsigned char * tuple,
220                         unsigned char * linebuf,
221                         int * tuplecnt, int * linecnt,
222                         const int rowlen);
223 
224 /* ********************************************************************** */
225 
226 /*
227   Parse version string of type <major>.<minor>.<patch>. <minor> or
228   <patch> might not be in the string. It's possible to supply NULL for
229   minor and/or patch if you're not interested in minor and/or patch.
230 */
231 SbBool coin_parse_versionstring(const char * versionstr,
232                                 int * major,
233                                 int * minor,
234                                 int * patch);
235 
236 /* ********************************************************************** */
237 
238 SbBool coin_getcwd(cc_string * str);
239 
240 /* ********************************************************************** */
241 
242 int coin_isinf(double value);
243 int coin_isnan(double value);
244 int coin_finite(double value);
245 
246 /* ********************************************************************** */
247 
248 unsigned long coin_geq_prime_number(unsigned long num);
249 
250 /* ********************************************************************** */
251 
252 enum CoinOSType {
253   COIN_UNIX,
254   COIN_OS_X,
255   COIN_MSWINDOWS
256 };
257 
258 int coin_runtime_os(void);
259 
260 #define COIN_MAC_FRAMEWORK_IDENTIFIER_CSTRING ("org.coin3d.Coin.framework")
261 
262 /* ********************************************************************** */
263 
264 int coin_debug_extra(void);
265 int coin_debug_normalize(void);
266 int coin_debug_caching_level(void);
267 
268 /* ********************************************************************** */
269 
270 #ifdef __cplusplus
271 } /* extern "C" */
272 #endif /* __cplusplus */
273 
274 /* ********************************************************************** */
275 
276 #endif /* !COIN_TIDBITS_H */
277