HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  /// SSL related error
57  EXIT_SSL_ERROR = 64,
58 
59  /// Process is already running
60  EXIT_PROCESS_RUN_ERROR = 100
61  };
62 
63  /// Calls exit(), which implicitly leads to our callbacks being called.
64  SYS_FUNC_NORETURN static void exit(UT_ExitCode exit_code = EXIT_OK);
65 
66  /// Just like exit(), except sets the exit code to the properly offset
67  /// signal number according to the convention: 128 + signal_number.
68  SYS_FUNC_NORETURN static void exitWithSignalNumber(int signal_number);
69 
70  /// An exit method that takes any exit code (as integer). Should be used
71  /// sparingly and only if necessary. We want the exit codes to be
72  /// consistent, stable and well-known to the customers (we can document
73  /// based on the above enum), so use exit() with UT_ExitCode, if possible.
74  SYS_FUNC_NORETURN static void exitWithSpecificCode(int exit_code);
75 
76  /// Synonym for exit(UT_Exit::EXIT_OK).
77  SYS_FUNC_NORETURN static inline void
79  {
80  UT_Exit::exit();
81  }
82 
83  /// Synonym for exit(UT_Exit::EXIT_GENERIC_ERROR)
84  SYS_FUNC_NORETURN static inline void
85  fail(const UT_ExitCode exit_code = EXIT_GENERIC_ERROR)
86  {
87  UT_Exit::exit(exit_code);
88  }
89 
90  /// Return true if the application is in the process of exiting
91  /// and false otherwise.
92  static bool isExiting();
93 
94  /// Return true if process is implicitly exiting, ie. from normal process
95  /// termination. This will be false when exit callbacks are being run
96  /// prior to process termination.
97  static bool isImplicitlyExiting();
98 
99  /// Calls our callbacks directly, without calling exit(). This should
100  /// only be used by our core dump handler.
101  static void runExitCallbacks();
102 
103  /// Adds a callback to the end of the list of callbacks to be run when the
104  /// process exits.
105  /// Returns 1 if the function was added, the function can only be added one
106  /// time. Returns 0 if this is a duplicate.
107  ///
108  /// @warning Destructors of global variables are called BEFORE the callback
109  /// is invoked on Windows!
110  static int addExitCallback(void (*exitcallback)(void *data),
111  void *data = 0);
112 
113  /// Returns 1 if the function was removed. Returns 0 if the function was
114  /// never added.
115  static int removeExitCallback(void (*exitcallback)(void *data),
116  void *data = 0);
117 
118  /// Remove all the exit callbacks.
119  static void removeAllExitCallbacks();
120 
121  /// Register a callback to shut down the QApplication object (if any).
122  /// DO NOT CALL THIS FUNCTION.
123  /// The function should only be called by main() in AP_Main.C.
124  static void registerQtAppExitCallback(
125  void (*exitcallback)(void *data),
126  void *data=nullptr);
127 
128  /// Register a callback to run Python's atexit callbacks.
129  /// DO NOT CALL THIS FUNCTION.
130  /// The function should only be called by pyInitializePython() in
131  /// PY_InterpreterAutoLock.C.
132  /// If you want to register a Python exit callback, then call
133  /// PYregisterAtExitCallback() from PY_Python.h instead.
134  static void registerPyAtExitCallback(
135  void (*exitcallback)(void *data),
136  void *data=nullptr);
137 
138 private:
139  SYS_FUNC_NORETURN static void doExit(int exit_code, bool fast_exit);
140 };
141 
142 #endif
UT_ExitCode
Definition: UT_Exit.h:36
#define UT_API
Definition: UT_API.h:13
static SYS_FUNC_NORETURN void exit(UT_ExitCode exit_code=EXIT_OK)
Calls exit(), which implicitly leads to our callbacks being called.
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
#define SYS_FUNC_NORETURN
Definition: SYS_Compiler.h:108
static SYS_FUNC_NORETURN void success()
Synonym for exit(UT_Exit::EXIT_OK).
Definition: UT_Exit.h:78
static SYS_FUNC_NORETURN void fail(const UT_ExitCode exit_code=EXIT_GENERIC_ERROR)
Synonym for exit(UT_Exit::EXIT_GENERIC_ERROR)
Definition: UT_Exit.h:85