00001
00032 #ifndef LL_LLAPP_H
00033 #define LL_LLAPP_H
00034
00035 #include <map>
00036 #include "llapr.h"
00037 #include "llrun.h"
00038 #include "llsd.h"
00039
00040
00041 class LLErrorThread;
00042 class LLApp;
00043
00044
00045 typedef void (*LLAppErrorHandler)();
00046 typedef void (*LLAppChildCallback)(int pid, bool exited, int status);
00047
00048 #if !LL_WINDOWS
00049 extern S32 LL_SMACKDOWN_SIGNAL;
00050 extern S32 LL_HEARTBEAT_SIGNAL;
00051
00052
00053 void clear_signals();
00054
00055 class LLChildInfo
00056 {
00057 public:
00058 LLChildInfo() : mGotSigChild(FALSE), mCallback(NULL) {}
00059 BOOL mGotSigChild;
00060 LLAppChildCallback mCallback;
00061 };
00062 #endif
00063
00064 class LLApp
00065 {
00066 friend class LLErrorThread;
00067 public:
00068 typedef enum e_app_status
00069 {
00070 APP_STATUS_RUNNING,
00071 APP_STATUS_QUITTING,
00072 APP_STATUS_STOPPED,
00073 APP_STATUS_ERROR
00074 } EAppStatus;
00075
00076
00077 LLApp();
00078 virtual ~LLApp();
00079
00083 static LLApp* instance();
00084
00091 enum OptionPriority
00092 {
00093 PRIORITY_RUNTIME_OVERRIDE,
00094 PRIORITY_COMMAND_LINE,
00095 PRIORITY_SPECIFIC_CONFIGURATION,
00096 PRIORITY_GENERAL_CONFIGURATION,
00097 PRIORITY_DEFAULT,
00098 PRIORITY_COUNT
00099 };
00100
00108 LLSD getOption(const std::string& name) const;
00109
00122 bool parseCommandOptions(int argc, char** argv);
00123
00134 bool setOptionData(OptionPriority level, LLSD data);
00135
00144 LLSD getOptionData(OptionPriority level);
00146
00147
00148
00149
00150
00151
00152 virtual bool init() = 0;
00153
00154
00155
00156
00157
00158
00159
00160
00161 virtual bool cleanup() = 0;
00162
00163
00164
00165
00166
00167
00168
00169 virtual bool mainLoop() = 0;
00170
00171
00172
00173
00174
00175 static void setQuitting();
00176 static void setStopped();
00177 static void setError();
00178 static bool isStopped();
00179 static bool isRunning();
00180 static bool isQuitting();
00181 static bool isError();
00182 static bool isExiting();
00183 #if !LL_WINDOWS
00184 static U32 getSigChildCount();
00185 static void incSigChildCount();
00186 #endif
00187 static int getPid();
00188
00189
00190
00191
00192 void setErrorHandler(LLAppErrorHandler handler);
00193 void setSyncErrorHandler(LLAppErrorHandler handler);
00194
00195 #if !LL_WINDOWS
00196
00197
00198
00199
00200
00201
00202
00203 void setChildCallback(pid_t pid, LLAppChildCallback callback);
00204
00205
00206 void setDefaultChildCallback(LLAppChildCallback callback);
00207
00208
00209
00210
00211 pid_t fork();
00212 #endif
00213
00223 LLRunner& getRunner() { return mRunner; }
00224
00225 public:
00226 typedef std::map<std::string, std::string> string_map;
00227 string_map mOptionMap;
00228
00229 protected:
00230
00231 static void setStatus(EAppStatus status);
00232 static EAppStatus sStatus;
00233 static BOOL sErrorThreadRunning;
00234
00235 #if !LL_WINDOWS
00236 static LLAtomicU32* sSigChildCount;
00237 typedef std::map<pid_t, LLChildInfo> child_map;
00238 static child_map sChildMap;
00239 static LLAppChildCallback sDefaultChildCallback;
00240 #endif
00241
00245 void stepFrame();
00246
00247 private:
00248 void setupErrorHandling();
00249
00250 static void runErrorHandler();
00251 static void runSyncErrorHandler();
00252
00253
00254
00255
00256 typedef int(*signal_handler_func)(int signum);
00257 static LLAppErrorHandler sErrorHandler;
00258 static LLAppErrorHandler sSyncErrorHandler;
00259
00260
00261 LLErrorThread* mThreadErrorp;
00262
00263
00264 LLRunner mRunner;
00265
00268
00269
00270 LLSD mOptions;
00271
00273
00274 private:
00275
00276 static LLApp* sApplication;
00277
00278
00279 #if !LL_WINDOWS
00280 friend void default_unix_signal_handler(int signum, siginfo_t *info, void *);
00281 #endif
00282
00283 public:
00284 static BOOL sLogInSignal;
00285 };
00286
00287 #endif // LL_LLAPP_H