HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_Exit.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Exit.h ( UT Library, C++)
7  *
8  * COMMENTS: General exit mechanism... This allows a list of callback
9  * functions to be added when exit is being called
10  * The callbacks are called in the order that they were added.
11  * The callback function will only be added once (even if the data
12  * is different).
13  */
14 
15 #ifndef __UT_Exit__
16 #define __UT_Exit__
17 
18 #include "UT_API.h"
19 
21 {
22 public:
23  /// The enumeration of the exit codes that Houdini producs can use.
24  /// (see notes in http://tldp.org/LDP/abs/html/exitcodes.html)
25  /// @note The numeric values for the specific exit reasons should not
26  /// change: some customers explicitly test the numeric value of the
27  /// exit code and take a specific action based on it. E.g., they may
28  /// test the exit code for the license failure on a render farm for
29  /// re-submission, but if we change the exit code for license failure
30  /// their scripts will need to be updated to account for that.
31  ///
32  /// @note Don't use exit code value of 259. On Windows, the exit code 259
33  /// means STILL_ACTIVE, and should not be used as an exit error code;
34  /// otherwise the return value of GetExitCodeProcess() calls may be
35  /// misinterpreted.
37  {
38  /// no error
39  EXIT_OK = 0,
40 
41  /// catch-all error code
42  EXIT_GENERIC_ERROR = 1,
43 
44  /// misuse of shell builtins (according to Bash documentation)
45  EXIT_BUILTIN_ERROR = 2,
46 
47  /// failure to check out or verify an appropriate product license
48  EXIT_LICENSE_ERROR = 3,
49 
50  /// socket communication failure
51  EXIT_SOCKET_ERROR = 4,
52 
53  /// failed to parse the UI definition file
54  EXIT_PARSE_UI_ERROR = 5
55  };
56 
57  /// Calls exit(), which implicitly leads to our callbacks being called.
58  static void exit( UT_ExitCode exit_code = EXIT_OK );
59 
60  /// Just like exit(), except sets the exit code to the properly offset
61  /// signal number according to the convention: 128 + signal_number.
62  static void exitWithSignalNumber( int signal_number );
63 
64  /// An exit method that takes any exit code (as integer). Should be used
65  /// sparingly and only if necessary. We want the exit codes to be
66  /// consistent, stable and well-known to the customers (we can document
67  /// based on the above enum), so use exit() with UT_ExitCode, if possible.
68  static void exitWithSpecificCode( int exit_code );
69 
70  /// Return true if the application is in the process of exiting
71  /// and false otherwise.
72  static bool isExiting();
73 
74  /// Calls our callbacks directly, without calling exit(). This should
75  /// only be used by our core dump handler.
76  static void runExitCallbacks();
77 
78  /// Returns 1 if the function was added, the function can only be added one
79  /// time. Returns 0 if this is a duplicate.
80  ///
81  /// @warning Destructors of global variables are called BEFORE the callback
82  /// is invoked on Windows!
83  static int addExitCallback(void (*exitcallback)(void *data),
84  void *data = 0);
85  /// Returns 1 if the function was removed. Returns 0 if the function was
86  /// never added.
87  static int removeExitCallback(void (*exitcallback)(void *data),
88  void *data = 0);
89 
90  /// Remove all the exit callbacks.
91  static void removeAllExitCallbacks();
92 
93 #if defined(USE_QT5)
94  /// Register a callback to shut down the QApplication object (if any).
95  static void registerQtAppExitCallback(
96  void (*exitcallback)(void *data),
97  void *data=nullptr);
98 #endif
99 
100 private:
101  static void doExit(int exit_code, bool fast_exit);
102 };
103 
104 #endif
UT_ExitCode
Definition: UT_Exit.h:36
#define UT_API
Definition: UT_API.h:12
GLboolean * data
Definition: glcorearb.h:130