Commit | Line | Data |
---|---|---|
b311480e | 1 | -- Copyright (c) 1992-1999 Matra Datavision |
2 | -- Copyright (c) 1999-2012 OPEN CASCADE SAS | |
3 | -- | |
4 | -- The content of this file is subject to the Open CASCADE Technology Public | |
5 | -- License Version 6.5 (the "License"). You may not use the content of this file | |
6 | -- except in compliance with the License. Please obtain a copy of the License | |
7 | -- at http://www.opencascade.org and read it completely before using this file. | |
8 | -- | |
9 | -- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
10 | -- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
11 | -- | |
12 | -- The Original Code and all software distributed under the License is | |
13 | -- distributed on an "AS IS" basis, without warranty of any kind, and the | |
14 | -- Initial Developer hereby disclaims all such warranties, including without | |
15 | -- limitation, any warranties of merchantability, fitness for a particular | |
16 | -- purpose or non-infringement. Please see the License for the specific terms | |
17 | -- and conditions governing the rights and limitations under the License. | |
18 | ||
7fd59977 | 19 | -- Update: |
20 | -- 20-01-2009 : ABD Integration support of system fonts (using FTGL and FreeType) | |
21 | ||
22 | package OSD | |
23 | ||
24 | ---History: | |
25 | -- Version Date Purpose | |
26 | -- 1.1 24/06/92 Operating System Dependent tools | |
27 | -- 1.2 | |
28 | -- 2.0 | |
29 | -- 3.0 | |
30 | -- Windows NT 30/09/96 ( EUG ) | |
0ac0c8b4 | 31 | ---Purpose: Set of Operating Sytem Dependent Tools |
7fd59977 | 32 | -- (O)perating (S)ystem (D)ependent |
33 | ||
0ac0c8b4 | 34 | uses |
7fd59977 | 35 | |
0ac0c8b4 RL |
36 | Standard , |
37 | Quantity , | |
7fd59977 | 38 | TCollection |
39 | ||
40 | is | |
0ac0c8b4 | 41 | |
7fd59977 | 42 | exception OSDError inherits Failure from Standard ; |
43 | ||
44 | imported Function; | |
45 | ---Purpose: This is in fact a pointer to a function. | |
46 | -- This is not an "enumeration" but a trick to solve an omission | |
47 | -- from CDL. | |
48 | --- C++: alias "typedef int (* OSD_Function)(...);" | |
49 | ||
50 | enumeration OEMType is Unavailable,SUN,DEC,SGI,NEC,MAC,PC,HP,IBM,VAX,LIN,AIX; | |
51 | ---Purpose: This is set of possible machine types | |
52 | -- used in OSD_Host::MachineType | |
53 | ||
0ac0c8b4 | 54 | enumeration SysType is Unknown,Default,UnixBSD, UnixSystemV, VMS, OS2, |
7fd59977 | 55 | OSF, MacOs, Taligent, WindowsNT, LinuxREDHAT,Aix; |
56 | ---Purpose: Thisd is a set of possible system types. | |
57 | -- 'Default' means SysType of machine operating this process. | |
58 | -- This can be used with the Path class. | |
59 | -- All UNIX-like are grouped under "UnixBSD" or "UnixSystemV". | |
60 | -- Such systems are Solaris, NexTOS ... | |
61 | -- A category of systems accept MSDOS-like path such as | |
0ac0c8b4 | 62 | -- WindowsNT and OS2. |
7fd59977 | 63 | |
64 | enumeration FromWhere is FromBeginning, FromHere, FromEnd; | |
65 | ---Purpose: Used by OSD_File in the method Seek. | |
66 | ||
67 | enumeration LockType is NoLock, ReadLock, WriteLock, ExclusiveLock; | |
68 | ---Purpose: locks for files. | |
69 | -- NoLock is the default value when opening a file. | |
70 | -- | |
71 | -- ReadLock allows only one reading of the file at a time. | |
72 | -- | |
0ac0c8b4 | 73 | -- WriteLock prevents others writing into a file(excepted the user |
7fd59977 | 74 | -- who puts the lock)but allows everybody to read. |
75 | -- | |
76 | -- ExclusiveLock prevents reading and writing except for the | |
77 | -- current user of the file. | |
78 | -- So ExclusiveLock means only one user on the file and this | |
79 | -- user is the one who puts the lock. | |
80 | ||
81 | enumeration SingleProtection is None,R,W,RW,X,RX,WX,RWX,D,RD,WD,RWD,XD,RXD,WXD,RWXD; | |
82 | ---Purpose: Access rights for files. | |
83 | -- R means Read, W means Write, X means eXecute and D means Delete. | |
84 | -- On UNIX, the right to Delete is combined with Write access. | |
85 | -- So if "W"rite is not set and "D"elete is, "W"rite will be set | |
86 | -- and if "W" is set, "D" will be too. | |
87 | ||
88 | enumeration OpenMode is ReadOnly, WriteOnly, ReadWrite; | |
89 | ---Purpose: Specifies the file open mode. | |
90 | ||
91 | enumeration LoadMode is RTLD_LAZY, RTLD_NOW; | |
92 | ---Purpose: This enumeration is used to load shareable libraries. | |
93 | ||
94 | enumeration KindFile is FILE, DIRECTORY, LINK, SOCKET, UNKNOWN; | |
95 | ---Purpose: Specifies the type of files. | |
7fd59977 | 96 | |
0ac0c8b4 RL |
97 | private enumeration WhoAmI is WDirectory, WDirectoryIterator, |
98 | WEnvironment, WFile, WFileNode, WFileIterator, WMailBox, | |
7fd59977 | 99 | WPath, WProcess, WProtection, WSemaphore, WHost, WDisk, |
100 | WChronometer, WSharedMemory, WTimer, WPackage, WPrinter, | |
101 | WEnvironmentIterator; | |
102 | ---Purpose: Allows great accuracy for error management. | |
103 | -- This is private. | |
104 | ||
105 | ||
106 | class Error; | |
107 | ---Purpose: Accurate management of OSD specific errors. | |
108 | ||
109 | class Protection; | |
110 | ---Purpose: Gets and sets protection attributes of 'system , user , | |
111 | -- group, and world'. | |
0ac0c8b4 | 112 | |
7fd59977 | 113 | class Path; |
114 | ---Purpose: Manages independent system path translation. | |
115 | ||
116 | deferred class FileNode; | |
117 | ---Purpose: A set of file/directory manipulation tools. | |
118 | ||
119 | class Disk; | |
120 | ---Purpose: A set of disk oriented tools. | |
121 | ||
122 | class File; | |
123 | ---Purpose: A set of file oriented tools. | |
124 | ||
125 | class FileIterator; | |
126 | ---Purpose: Searches for child files in current directory. | |
127 | ||
128 | class Directory; | |
129 | ---Purpose: A set of directory oriented tools | |
130 | ||
131 | class DirectoryIterator; | |
132 | ---Purpose: Searches sub-directories in current directory. | |
133 | ||
134 | class Chronometer; | |
0ac0c8b4 | 135 | ---Purpose: Measures time elapsed for performance program tests. |
7fd59977 | 136 | -- Measures CPU time consumed by a method call. |
137 | ||
138 | class Timer; | |
139 | ---Purpose: Measures the effective time elapsed for a method call. | |
140 | ||
141 | class Printer; | |
142 | ---Purpose: Selects a printer (used by File). | |
143 | ||
144 | class Host; | |
145 | ---Purpose: Carries information about a host. | |
146 | -- System version ,host name, nodename ... | |
147 | ||
148 | class Environment; | |
149 | ---Purpose: Manages environment variables. | |
150 | ||
151 | class EnvironmentIterator; | |
152 | ---Purpose: Get all environment variables. | |
153 | ||
154 | class Process; | |
155 | ---Purpose: Process specific oriented tools | |
156 | ||
157 | class SharedMemory; | |
0ac0c8b4 | 158 | ---Purpose: Manages shared memory. |
7fd59977 | 159 | |
160 | class Semaphore; | |
161 | ---Purpose: Manages semaphores. | |
0ac0c8b4 | 162 | |
7fd59977 | 163 | -- class Mutex is alias Mutex from Standard; |
164 | ---Purpose: Mutex object to synchronize threads within one process | |
0ac0c8b4 | 165 | |
7fd59977 | 166 | class MailBox; |
167 | ---Purpose: Manages asynchronous mail boxes. | |
0ac0c8b4 | 168 | |
7fd59977 | 169 | class SharedLibrary; |
170 | ---Purpose: Provides tools to load a shared library | |
171 | -- and retrieve the address of an entry point. | |
172 | ||
f0430952 | 173 | imported MemInfo; |
7fd59977 | 174 | imported PThread; |
175 | imported ThreadFunction; | |
176 | class Thread; | |
177 | ---Purpose: A tool to manage threads | |
7fd59977 | 178 | |
7fd59977 | 179 | ----------------------------------------------- |
180 | -- UNIX specific exceptions and enumeration -- | |
181 | ----------------------------------------------- | |
182 | ||
183 | exception Signal inherits Failure from Standard; | |
184 | exception SIGHUP inherits Signal; | |
185 | exception SIGINT inherits Signal; | |
186 | exception SIGQUIT inherits Signal; | |
187 | exception SIGILL inherits Signal; | |
188 | exception SIGKILL inherits Signal; | |
189 | exception SIGBUS inherits Signal; | |
190 | exception SIGSEGV inherits Signal; | |
191 | exception SIGSYS inherits Signal; | |
0ac0c8b4 | 192 | |
7fd59977 | 193 | |
194 | enumeration Signals is | |
195 | ---purpose: | |
196 | -- The "posix" signals. | |
0ac0c8b4 | 197 | -- |
7fd59977 | 198 | S_SIGHUP, -- "hangup." |
199 | S_SIGINT, -- "interrupt." | |
200 | S_SIGQUIT, -- "quit." | |
201 | S_SIGILL, -- "illegal instruction." | |
202 | S_SIGKILL, -- "kill." | |
203 | S_SIGBUS, -- "bus error." | |
204 | S_SIGSEGV, -- "segmentation violation." | |
205 | S_SIGSYS, -- "bad argument to system call." | |
206 | S_SIGFPE, -- "floating point exception." | |
207 | S_FPE_FLTDIV_TRAP, -- "floating/decimal divide by zero." | |
208 | S_FPE_INTDIV_TRAP, -- "integer divide by zero." | |
209 | S_FPE_FLTOVF_TRAP, -- "floating overflow." | |
210 | S_FPE_INTOVF_TRAP, -- "integer overflow." | |
211 | S_FPE_FLTUND_TRAP, -- "floating underflow." | |
212 | S_FPE_FLTINEX_TRAP -- "floating inexact result." | |
213 | end Signals; | |
0ac0c8b4 | 214 | |
7fd59977 | 215 | ---------------------------------------- |
216 | -- Exceptions ( Windows NT specific ) -- | |
217 | ---------------------------------------- | |
218 | ||
219 | exception Exception inherits Failure from Standard; | |
0ac0c8b4 | 220 | |
7fd59977 | 221 | exception Exception_ACCESS_VIOLATION inherits Exception; |
222 | exception Exception_ARRAY_BOUNDS_EXCEEDED inherits Exception; | |
223 | exception Exception_FLT_DENORMAL_OPERAND inherits Exception; | |
224 | exception Exception_FLT_DIVIDE_BY_ZERO inherits Exception; | |
225 | exception Exception_FLT_INEXACT_RESULT inherits Exception; | |
226 | exception Exception_FLT_INVALID_OPERATION inherits Exception; | |
227 | exception Exception_FLT_OVERFLOW inherits Exception; | |
228 | exception Exception_FLT_STACK_CHECK inherits Exception; | |
229 | exception Exception_FLT_UNDERFLOW inherits Exception; | |
230 | exception Exception_ILLEGAL_INSTRUCTION inherits Exception; | |
231 | exception Exception_IN_PAGE_ERROR inherits Exception; | |
232 | exception Exception_INT_DIVIDE_BY_ZERO inherits Exception; | |
233 | exception Exception_INT_OVERFLOW inherits Exception; | |
234 | exception Exception_INVALID_DISPOSITION inherits Exception; | |
235 | exception Exception_NONCONTINUABLE_EXCEPTION inherits Exception; | |
236 | exception Exception_PRIV_INSTRUCTION inherits Exception; | |
237 | exception Exception_STACK_OVERFLOW inherits Exception; | |
238 | exception Exception_STATUS_NO_MEMORY inherits Exception; -- generating by 'HeapAlloc' | |
239 | exception Exception_CTRL_BREAK inherits Exception; -- generating by 'Ctrl-C' keystroke | |
240 | ||
241 | ---------------------------------------------- | |
242 | -- Handler and SegvHandler (UNIX specific ) -- | |
243 | ---------------------------------------------- | |
244 | ||
0ac0c8b4 RL |
245 | -- |
246 | -- Handler(aSignal: Signals; aCode: Signals) | |
247 | -- | |
248 | ||
249 | Handler(aSignal: Signals; aSigInfo: Address; aContext: Address) | |
7fd59977 | 250 | ---Purpose: |
251 | -- 1) Raise a exception when aSignal is a floating point signal. | |
252 | -- aSignal is SIGFPE. | |
0ac0c8b4 | 253 | -- aCode is |
7fd59977 | 254 | -- (FPE: Floating Point Exception) |
255 | -- (FLT: FLoaTing operation.) | |
256 | -- (INT: INTeger operation.) | |
257 | -- (DIV: DIVided by zero.) | |
258 | -- (OVF: OVerFlow.) | |
259 | -- (INEX: INEXact operation.) | |
0ac0c8b4 | 260 | -- |
7fd59977 | 261 | -- FPE_FLTDIV_TRAP (the exception "DivideByZero" is raised.) |
262 | -- FPE_INTDIV_TRAP (the exception "DivideByZero" is raised.) | |
0ac0c8b4 | 263 | -- |
7fd59977 | 264 | -- FPE_FLTOVF_TRAP (the exception "Overflow" is raised.) |
265 | -- FPE_INTOVF_TRAP (the exception "Overflow" is raised.) | |
0ac0c8b4 | 266 | -- |
7fd59977 | 267 | -- FPE_FLTINEX_TRAP (the exception "NumericError" is raised.) |
0ac0c8b4 | 268 | -- |
7fd59977 | 269 | -- 2) Display the signal name, and call "exit" with signal number for |
270 | -- a "Hardware" signal. | |
0ac0c8b4 | 271 | -- |
7fd59977 | 272 | raises |
0ac0c8b4 | 273 | DivideByZero, |
7fd59977 | 274 | Overflow, |
275 | Underflow, | |
276 | SIGHUP, | |
277 | SIGINT, | |
278 | SIGQUIT, | |
279 | SIGILL, | |
280 | SIGKILL, | |
281 | SIGBUS, | |
282 | SIGSEGV, | |
283 | SIGSYS | |
284 | is private; | |
285 | ||
286 | SegvHandler(aSignal: Signals; aSigInfo: Address; aContext: Address) | |
287 | ---Purpose: | |
288 | -- Handle access to null object and segmentation violation | |
289 | -- | |
290 | raises | |
291 | NullObject, | |
292 | SIGSEGV | |
293 | is private; | |
294 | ||
295 | --------------------------------------- | |
296 | -- WntHandler (Windows NT specific ) -- | |
297 | --------------------------------------- | |
298 | ||
299 | WntHandler ( exceptionInfo : Address from Standard ) | |
300 | returns Integer from Standard | |
301 | raises DivideByZero, | |
302 | Overflow, | |
303 | Underflow, | |
304 | Exception_ACCESS_VIOLATION, | |
305 | Exception_ARRAY_BOUNDS_EXCEEDED, | |
306 | Exception_FLT_DENORMAL_OPERAND, | |
307 | Exception_FLT_DIVIDE_BY_ZERO, | |
308 | Exception_FLT_INEXACT_RESULT, | |
309 | Exception_FLT_INVALID_OPERATION, | |
310 | Exception_FLT_OVERFLOW, | |
311 | Exception_FLT_STACK_CHECK, | |
312 | Exception_FLT_UNDERFLOW, | |
313 | Exception_ILLEGAL_INSTRUCTION, | |
314 | Exception_IN_PAGE_ERROR, | |
315 | Exception_INVALID_DISPOSITION, | |
316 | Exception_NONCONTINUABLE_EXCEPTION, | |
317 | Exception_PRIV_INSTRUCTION, | |
318 | Exception_STACK_OVERFLOW, | |
319 | Exception_STATUS_NO_MEMORY | |
320 | is private; | |
321 | ---Purpose: | |
322 | -- 1) Raises an exception if the exception due to floating point errors. | |
323 | -- Flosting point errors: | |
324 | -- EXCEPTION_FLT_DENORMAL_OPERAND | |
325 | -- EXCEPTION_FLT_DIVIDE_BY_ZERO | |
326 | -- EXCEPTION_FLT_INEXACT_RESULT | |
327 | -- EXCEPTION_FLT_INVALID_OPERATION | |
328 | -- EXCEPTOPN_FLT_OVERFLOW | |
329 | -- EXCEPTION_FLT_STACK_CHECK | |
330 | -- EXCEPTION_FLT_UNDERFLOW | |
331 | -- 2) Displays a message box 'Continue' - 'Debugger' - 'Stop' if the environment | |
332 | -- variable 'CSF_EXCEPTION_PROMPT' is set and takes appropriate action. | |
333 | -- Raises an exception otherwise. | |
0ac0c8b4 RL |
334 | |
335 | SetSignal(theFloatingSignal: Boolean = Standard_True); | |
7fd59977 | 336 | ---Purpose: |
0ac0c8b4 RL |
337 | -- Sets signal and exception handlers. |
338 | -- <b>Windows-specific notes<\b> | |
339 | -- Compiled with MS VC++ sets 3 main handlers: | |
340 | -- @li Signal handlers (via ::signal() functions) that translate system signals | |
341 | -- (SIGSEGV, SIGFPE, SIGILL) into C++ exceptions (classes inheriting | |
342 | -- Standard_Failure). They only be called if user calls ::raise() function | |
343 | -- with one of supported signal type set. | |
344 | -- @li Exception handler OSD::WntHandler() (via ::SetUnhandledExceptionFilter()) | |
345 | -- that will be used when user's code is compiled with /EHs option. | |
346 | -- @li Structured exception (SE) translator (via _set_se_translator()) that | |
347 | -- translates SE exceptions (aka asynchronous exceptions) into the | |
348 | -- C++ exceptions inheriting Standard_Failure. This translator will be | |
349 | -- used when user's code is compiled with /EHa option. | |
350 | -- . | |
351 | -- This approach ensures that regardless of the option the user chooses to | |
352 | -- compile his code with (/EHs or /EHa), signals (or SE exceptions) will be | |
353 | -- translated into Open CASCADE C++ exceptions. | |
354 | -- . | |
355 | -- If @a theFloatingSignal is TRUE then floating point exceptions will be | |
356 | -- generated in accordance with the mask | |
357 | -- <tt>_EM_INVALID | _EM_DENORMAL | _EM_ZERODIVIDE | _EM_OVERFLOW<\tt> that is | |
358 | -- used to call ::_controlfp() system function. If @a theFloatingSignal is FALSE | |
359 | -- corresponding operations (e.g. division by zero) will gracefully complete | |
360 | -- without an exception. | |
361 | -- . | |
362 | -- <b>Unix-specific notes<\b> | |
363 | -- OSD::SetSignal() sets handlers (via ::sigaction()) for multiple signals | |
364 | -- (SIGFPE, SIGSEGV, etc). Currently the number of handled signals is much | |
365 | -- greater than for Windows, in the future this may change to provide better | |
366 | -- consistency with Windows. | |
367 | -- . | |
368 | -- @a theFloatingSignal is recognized on Sun Solaris, Linux, and SGI Irix to | |
369 | -- generate floating-point exception according to the mask | |
370 | -- <tt>FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW</tt> (in Linux conventions).<br> | |
371 | -- When compiled with OBJS macro defined, already set signal handlers (e.g. | |
372 | -- by Data Base Managers) are not redefined. | |
373 | -- . | |
374 | -- <b>Common notes<\b> | |
375 | -- If OSD::SetSignal() method is used in at least one thread, it must also be | |
376 | -- called in any other thread where Open CASCADE will be used, to ensure | |
377 | -- consistency of behavior. Its @a aFloatingSignal argument must be consistent | |
378 | -- across threads. | |
379 | -- . | |
380 | -- Keep in mind that whether the C++ exception will really be thrown (i.e. | |
381 | -- ::throw() will be called) is regulated by the NO_CXX_EXCEPTIONS and | |
382 | -- OCC_CONVERT_SIGNALS macros used during compilation of Open CASCADE and | |
383 | -- user's code. Refer to Foundation Classes User's Guide for further details. | |
7fd59977 | 384 | -- |
7fd59977 | 385 | |
386 | AvailableMemory returns Integer from Standard; | |
387 | ---Purpose: Returns available memory in Kilobytes. | |
388 | ---Level: Advanced | |
0ac0c8b4 | 389 | |
7fd59977 | 390 | SecSleep(aDelay: Integer from Standard); |
391 | ---Purpose: Commands the process to sleep for a number of seconds. | |
0ac0c8b4 | 392 | ---Level: Public |
7fd59977 | 393 | |
394 | MilliSecSleep(aDelay: Integer from Standard); | |
395 | ---Purpose: Commands the process to sleep for a number of milliseconds | |
0ac0c8b4 | 396 | ---Level: Public |
7fd59977 | 397 | |
0ac0c8b4 | 398 | RealToCString(aReal: Real; aString:out PCharacter) |
7fd59977 | 399 | returns Boolean ; |
400 | ---Purpose: | |
401 | -- Converts aReal into aCstring in exponential format with a period as | |
402 | -- decimal point, no thousand separator and no grouping of digits. | |
403 | -- The conversion is independant from the current locale | |
0ac0c8b4 | 404 | ---Level: Public |
7fd59977 | 405 | |
406 | CStringToReal(aString: CString; aReal: out Real) returns Boolean ; | |
407 | ---Purpose: | |
408 | -- Converts aCstring representing a real with a period as | |
409 | -- decimal point, no thousand separator and no grouping of digits | |
410 | -- into aReal . | |
411 | -- The conversion is independant from the current locale. | |
0ac0c8b4 | 412 | ---Level: Public |
7fd59977 | 413 | |
414 | IsDivisible(aDividend, aDivisor: Real from Standard) | |
415 | returns Boolean from Standard; | |
416 | ---Purpose: Tests if the quotient theDividend/theDivisor | |
417 | -- does not overflow | |
0ac0c8b4 RL |
418 | ---Level: Public |
419 | ||
7fd59977 | 420 | GetExponent(aReal: Real from Standard) |
421 | returns Integer from Standard; | |
422 | ---Purpose: Returns the exponent in base 2 of a floating-point number. | |
0ac0c8b4 RL |
423 | ---Level: Public |
424 | ||
7fd59977 | 425 | GetMantissa(aReal: Real from Standard) |
426 | returns Real from Standard; | |
427 | ---Purpose: Returns the mantissa of a floating-point number. | |
0ac0c8b4 RL |
428 | ---Level: Public |
429 | ||
7fd59977 | 430 | ------------------------- |
431 | -- Windows NT specific -- | |
432 | ------------------------- | |
0ac0c8b4 | 433 | |
7fd59977 | 434 | ControlBreak raises Exception_CTRL_BREAK; |
435 | ---Purpose: since Windows NT does not support 'SIGINT' signal like UNIX, | |
436 | -- then this method checks whether Ctrl-Break keystroke was or | |
437 | -- not. If yes then raises Exception_CTRL_BREAK. | |
438 | ||
7fd59977 | 439 | end OSD; |