aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llapp.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcommon/llapp.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llcommon/llapp.h')
-rw-r--r--linden/indra/llcommon/llapp.h279
1 files changed, 279 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llapp.h b/linden/indra/llcommon/llapp.h
new file mode 100644
index 0000000..aef5cde
--- /dev/null
+++ b/linden/indra/llcommon/llapp.h
@@ -0,0 +1,279 @@
1/**
2 * @file llapp.h
3 * @brief Declaration of the LLApp class.
4 *
5 * Copyright (c) 2003-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#ifndef LL_LLAPP_H
29#define LL_LLAPP_H
30
31#include <map>
32#include "llapr.h"
33#include "llrun.h"
34#include "llsd.h"
35
36// Forward declarations
37class LLErrorThread;
38class LLApp;
39
40
41typedef void (*LLAppErrorHandler)();
42typedef void (*LLAppChildCallback)(int pid, bool exited, int status);
43
44#if !LL_WINDOWS
45extern const S32 LL_SMACKDOWN_SIGNAL;
46
47// Clear all of the signal handlers (which we want to do for the child process when we fork
48void clear_signals();
49
50class LLChildInfo
51{
52public:
53 LLChildInfo() : mGotSigChild(FALSE), mCallback(NULL) {}
54 BOOL mGotSigChild;
55 LLAppChildCallback mCallback;
56};
57#endif
58
59class LLApp
60{
61 friend class LLErrorThread;
62public:
63 typedef enum e_app_status
64 {
65 APP_STATUS_RUNNING, // The application is currently running - the default status
66 APP_STATUS_QUITTING, // The application is currently quitting - threads should listen for this and clean up
67 APP_STATUS_STOPPED, // The application is no longer running - tells the error thread it can exit
68 APP_STATUS_ERROR // The application had a fatal error occur - tells the error thread to run
69 } EAppStatus;
70
71
72 LLApp();
73 virtual ~LLApp();
74
75 /**
76 * @brief Return the static app instance if one was created.
77 */
78 static LLApp* instance();
79
80 /** @name Runtime options */
81 //@{
82 /**
83 * @brief Enumeration to specify option priorities in highest to
84 * lowest order.
85 */
86 enum OptionPriority
87 {
88 PRIORITY_RUNTIME_OVERRIDE,
89 PRIORITY_COMMAND_LINE,
90 PRIORITY_SPECIFIC_CONFIGURATION,
91 PRIORITY_GENERAL_CONFIGURATION,
92 PRIORITY_DEFAULT,
93 PRIORITY_COUNT
94 };
95
96 /**
97 * @brief Get the application option at the highest priority.
98 *
99 * If the return value is undefined, the option does not exist.
100 * @param name The name of the option.
101 * @return Returns the option data.
102 */
103 LLSD getOption(const std::string& name) const;
104
105 /**
106 * @brief Parse command line options and insert them into
107 * application command line options.
108 *
109 * The name inserted into the option will have leading option
110 * identifiers (a minus or double minus) stripped. All options
111 * with values will be stored as a string, while all options
112 * without values will be stored as true.
113 * @param argc The argc passed into main().
114 * @param argv The argv passed into main().
115 * @return Returns true if the parse succeeded.
116 */
117 bool parseCommandOptions(int argc, char** argv);
118
119 /**
120 * @brief Set the options at the specified priority.
121 *
122 * This function completely replaces the options at the priority
123 * level with the data specified. This function will make sure
124 * level and data might be valid before doing the replace.
125 * @param level The priority level of the data.
126 * @param data The data to set.
127 * @return Returns true if the option was set.
128 */
129 bool setOptionData(OptionPriority level, LLSD data);
130
131 /**
132 * @brief Get the option data at the specified priority.
133 *
134 * This method is probably not so useful except when merging
135 * information.
136 * @param level The priority level of the data.
137 * @return Returns The data (if any) at the level priority.
138 */
139 LLSD getOptionData(OptionPriority level);
140 //@}
141
142
143
144 //
145 // Main application logic
146 //
147 virtual bool init() = 0; // Override to do application initialization
148
149 //
150 // cleanup()
151 //
152 // It's currently assumed that the cleanup() method will only get
153 // called from the main thread or the error handling thread, as it will
154 // likely do thread shutdown, among other things.
155 //
156 virtual bool cleanup() = 0; // Override to do application cleanup
157
158 //
159 // mainLoop()
160 //
161 // Runs the application main loop. It's assumed that when you exit
162 // this method, the application is in one of the cleanup states, either QUITTING or ERROR
163 //
164 virtual bool mainLoop() = 0; // Override for the application main loop. Needs to at least gracefully notice the QUITTING state and exit.
165
166
167 //
168 // Application status
169 //
170 static void setQuitting(); // Set status to QUITTING, the app is now shutting down
171 static void setStopped(); // Set status to STOPPED, the app is done running and should exit
172 static void setError(); // Set status to ERROR, the error handler should run
173 static bool isStopped();
174 static bool isRunning();
175 static bool isQuitting();
176 static bool isError();
177 static bool isExiting(); // Either quitting or error (app is exiting, cleanly or not)
178#if !LL_WINDOWS
179 static U32 getSigChildCount();
180 static void incSigChildCount();
181#endif
182 static int getPid();
183
184 //
185 // Error handling methods
186 //
187 void setErrorHandler(LLAppErrorHandler handler);
188
189#if !LL_WINDOWS
190 //
191 // Child process handling (Unix only for now)
192 //
193 // Set a callback to be run on exit of a child process
194 // WARNING! This callback is run from the signal handler due to the extreme crappiness of
195 // Linux threading requiring waitpid() to be called from the thread that spawned the process.
196 // At some point I will make this more behaved, but I'm not going to fix this right now - djs
197 void setChildCallback(pid_t pid, LLAppChildCallback callback);
198
199 // The child callback to run if no specific handler is set
200 void setDefaultChildCallback(LLAppChildCallback callback);
201
202 // Fork and do the proper signal handling/error handling mojo
203 // WARNING: You need to make sure your signal handling callback is correct after
204 // you fork, because not all threads are duplicated when you fork!
205 pid_t fork();
206#endif
207
208 /**
209 * @brief Get a reference to the application runner
210 *
211 * Please use the runner with caution. Since the Runner usage
212 * pattern is not yet clear, this method just gives access to it
213 * to add and remove runnables.
214 * @return Returns the application runner. Do not save the
215 * pointer past the caller's stack frame.
216 */
217 LLRunner& getRunner() { return mRunner; }
218
219public:
220 typedef std::map<std::string, std::string> string_map;
221 string_map mOptionMap; // Contains all command-line options and arguments in a map
222
223protected:
224
225 static void setStatus(EAppStatus status); // Use this to change the application status.
226 static EAppStatus sStatus; // Reflects current application status
227 static BOOL sErrorThreadRunning; // Set while the error thread is running
228
229#if !LL_WINDOWS
230 static LLAtomicU32* sSigChildCount; // Number of SIGCHLDs received.
231 typedef std::map<pid_t, LLChildInfo> child_map; // Map key is a PID
232 static child_map sChildMap;
233 static LLAppChildCallback sDefaultChildCallback;
234#endif
235
236 /**
237 * @brief This method is called once a frame to do once a frame tasks.
238 */
239 void stepFrame();
240
241private:
242 void setupErrorHandling(); // Do platform-specific error-handling setup (signals, structured exceptions)
243
244 static void runErrorHandler();
245
246 // *NOTE: On Windows, we need a routine to reset the structured
247 // exception handler when some evil driver has taken it over for
248 // their own purposes
249 typedef int(*signal_handler_func)(int signum);
250 static LLAppErrorHandler sErrorHandler;
251
252 // Default application threads
253 LLErrorThread* mThreadErrorp; // Waits for app to go to status ERROR, then runs the error callback
254
255 // This is the application level runnable scheduler.
256 LLRunner mRunner;
257
258 /** @name Runtime option implementation */
259 //@{
260
261 // The application options.
262 LLSD mOptions;
263
264 //@}
265
266private:
267 // the static application instance if it was created.
268 static LLApp* sApplication;
269
270
271#if !LL_WINDOWS
272 friend void default_unix_signal_handler(int signum, siginfo_t *info, void *);
273#endif
274
275public:
276 static BOOL sLogInSignal;
277};
278
279#endif // LL_LLAPP_H