PageRenderTime 75ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llappviewer.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 370 lines | 205 code | 90 blank | 75 comment | 0 complexity | a6a9cd44a04b0302772fa73d9fd5b026 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llappviewer.h
  3. * @brief The LLAppViewer class declaration
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLAPPVIEWER_H
  27. #define LL_LLAPPVIEWER_H
  28. #include "llallocator.h"
  29. #include "llcontrol.h"
  30. #include "llsys.h" // for LLOSInfo
  31. #include "lltimer.h"
  32. class LLCommandLineParser;
  33. class LLFrameTimer;
  34. class LLPumpIO;
  35. class LLTextureCache;
  36. class LLImageDecodeThread;
  37. class LLTextureFetch;
  38. class LLWatchdogTimeout;
  39. class LLUpdaterService;
  40. struct apr_dso_handle_t;
  41. class LLAppViewer : public LLApp
  42. {
  43. public:
  44. LLAppViewer();
  45. virtual ~LLAppViewer();
  46. /**
  47. * @brief Access to the LLAppViewer singleton.
  48. *
  49. * The LLAppViewer singleton is created in main()/WinMain().
  50. * So don't use it in pre-entry (static initialization) code.
  51. */
  52. static LLAppViewer* instance() {return sInstance; }
  53. //
  54. // Main application logic
  55. //
  56. virtual bool init(); // Override to do application initialization
  57. virtual bool cleanup(); // Override to do application cleanup
  58. virtual bool mainLoop(); // Override for the application main loop. Needs to at least gracefully notice the QUITTING state and exit.
  59. // Application control
  60. void flushVFSIO(); // waits for vfs transfers to complete
  61. void forceQuit(); // Puts the viewer into 'shutting down without error' mode.
  62. void fastQuit(S32 error_code = 0); // Shuts down the viewer immediately after sending a logout message
  63. void requestQuit(); // Request a quit. A kinder, gentler quit.
  64. void userQuit(); // The users asks to quit. Confirm, then requestQuit()
  65. void earlyExit(const std::string& name,
  66. const LLSD& substitutions = LLSD()); // Display an error dialog and forcibly quit.
  67. void earlyExitNoNotify(); // Do not display error dialog then forcibly quit.
  68. void abortQuit(); // Called to abort a quit request.
  69. bool quitRequested() { return mQuitRequested; }
  70. bool logoutRequestSent() { return mLogoutRequestSent; }
  71. void writeDebugInfo();
  72. const LLOSInfo& getOSInfo() const { return mSysOSInfo; }
  73. // Report true if under the control of a debugger. A null-op default.
  74. virtual bool beingDebugged() { return false; }
  75. virtual bool restoreErrorTrap() = 0; // Require platform specific override to reset error handling mechanism.
  76. // return false if the error trap needed restoration.
  77. virtual void handleCrashReporting(bool reportFreeze = false) = 0; // What to do with crash report?
  78. static void handleViewerCrash(); // Hey! The viewer crashed. Do this, soon.
  79. void checkForCrash();
  80. // Thread accessors
  81. static LLTextureCache* getTextureCache() { return sTextureCache; }
  82. static LLImageDecodeThread* getImageDecodeThread() { return sImageDecodeThread; }
  83. static LLTextureFetch* getTextureFetch() { return sTextureFetch; }
  84. static U32 getTextureCacheVersion() ;
  85. static U32 getObjectCacheVersion() ;
  86. const std::string& getSerialNumber() { return mSerialNumber; }
  87. bool getPurgeCache() const { return mPurgeCache; }
  88. std::string getSecondLifeTitle() const; // The Second Life title.
  89. std::string getWindowTitle() const; // The window display name.
  90. void forceDisconnect(const std::string& msg); // Force disconnection, with a message to the user.
  91. void badNetworkHandler(); // Cause a crash state due to bad network packet.
  92. bool hasSavedFinalSnapshot() { return mSavedFinalSnapshot; }
  93. void saveFinalSnapshot();
  94. void loadNameCache();
  95. void saveNameCache();
  96. void removeMarkerFile(bool leave_logout_marker = false);
  97. // LLAppViewer testing helpers.
  98. // *NOTE: These will potentially crash the viewer. Only for debugging.
  99. virtual void forceErrorLLError();
  100. virtual void forceErrorBreakpoint();
  101. virtual void forceErrorBadMemoryAccess();
  102. virtual void forceErrorInfiniteLoop();
  103. virtual void forceErrorSoftwareException();
  104. virtual void forceErrorDriverCrash();
  105. // The list is found in app_settings/settings_files.xml
  106. // but since they are used explicitly in code,
  107. // the follow consts should also do the trick.
  108. static const std::string sGlobalSettingsName;
  109. LLCachedControl<bool> mRandomizeFramerate;
  110. LLCachedControl<bool> mPeriodicSlowFrame;
  111. // Load settings from the location specified by loction_key.
  112. // Key availale and rules for loading, are specified in
  113. // 'app_settings/settings_files.xml'
  114. bool loadSettingsFromDirectory(const std::string& location_key,
  115. bool set_defaults = false);
  116. std::string getSettingsFilename(const std::string& location_key,
  117. const std::string& file);
  118. void loadColorSettings();
  119. // For thread debugging.
  120. // llstartup needs to control init.
  121. // llworld, send_agent_pause() also controls pause/resume.
  122. void initMainloopTimeout(const std::string& state, F32 secs = -1.0f);
  123. void destroyMainloopTimeout();
  124. void pauseMainloopTimeout();
  125. void resumeMainloopTimeout(const std::string& state = "", F32 secs = -1.0f);
  126. void pingMainloopTimeout(const std::string& state, F32 secs = -1.0f);
  127. // Handle the 'login completed' event.
  128. // *NOTE:Mani Fix this for login abstraction!!
  129. void handleLoginComplete();
  130. LLAllocator & getAllocator() { return mAlloc; }
  131. // On LoginCompleted callback
  132. typedef boost::signals2::signal<void (void)> login_completed_signal_t;
  133. login_completed_signal_t mOnLoginCompleted;
  134. boost::signals2::connection setOnLoginCompletedCallback( const login_completed_signal_t::slot_type& cb ) { return mOnLoginCompleted.connect(cb); }
  135. void addOnIdleCallback(const boost::function<void()>& cb); // add a callback to fire (once) when idle
  136. void purgeCache(); // Clear the local cache.
  137. // mute/unmute the system's master audio
  138. virtual void setMasterSystemAudioMute(bool mute);
  139. virtual bool getMasterSystemAudioMute();
  140. // Metrics policy helper statics.
  141. static void metricsUpdateRegion(U64 region_handle);
  142. static void metricsSend(bool enable_reporting);
  143. protected:
  144. virtual bool initWindow(); // Initialize the viewer's window.
  145. virtual bool initLogging(); // Initialize log files, logging system, return false on failure.
  146. virtual void initConsole() {}; // Initialize OS level debugging console.
  147. virtual bool initHardwareTest() { return true; } // A false result indicates the app should quit.
  148. virtual bool initSLURLHandler();
  149. virtual bool sendURLToOtherInstance(const std::string& url);
  150. virtual bool initParseCommandLine(LLCommandLineParser& clp)
  151. { return true; } // Allow platforms to specify the command line args.
  152. virtual std::string generateSerialNumber() = 0; // Platforms specific classes generate this.
  153. virtual bool meetsRequirementsForMaximizedStart(); // Used on first login to decide to launch maximized
  154. private:
  155. void initMaxHeapSize();
  156. bool initThreads(); // Initialize viewer threads, return false on failure.
  157. bool initConfiguration(); // Initialize settings from the command line/config file.
  158. void initUpdater(); // Initialize the updater service.
  159. bool initCache(); // Initialize local client cache.
  160. void checkMemory() ;
  161. // We have switched locations of both Mac and Windows cache, make sure
  162. // files migrate and old cache is cleared out.
  163. void migrateCacheDirectory();
  164. void cleanupSavedSettings(); // Sets some config data to current or default values during cleanup.
  165. void removeCacheFiles(const std::string& filemask); // Deletes cached files the match the given wildcard.
  166. void writeSystemInfo(); // Write system info to "debug_info.log"
  167. bool anotherInstanceRunning();
  168. void initMarkerFile();
  169. void idle();
  170. void idleShutdown();
  171. // update avatar SLID and display name caches
  172. void idleNameCache();
  173. void idleNetwork();
  174. void sendLogoutRequest();
  175. void disconnectViewer();
  176. void loadEventHostModule(S32 listen_port);
  177. // *FIX: the app viewer class should be some sort of singleton, no?
  178. // Perhaps its child class is the singleton and this should be an abstract base.
  179. static LLAppViewer* sInstance;
  180. bool mSecondInstance; // Is this a second instance of the app?
  181. std::string mMarkerFileName;
  182. LLAPRFile mMarkerFile; // A file created to indicate the app is running.
  183. std::string mLogoutMarkerFileName;
  184. apr_file_t* mLogoutMarkerFile; // A file created to indicate the app is running.
  185. LLOSInfo mSysOSInfo;
  186. bool mReportedCrash;
  187. // Thread objects.
  188. static LLTextureCache* sTextureCache;
  189. static LLImageDecodeThread* sImageDecodeThread;
  190. static LLTextureFetch* sTextureFetch;
  191. S32 mNumSessions;
  192. std::string mSerialNumber;
  193. bool mPurgeCache;
  194. bool mPurgeOnExit;
  195. bool mSavedFinalSnapshot;
  196. bool mForceGraphicsDetail;
  197. bool mQuitRequested; // User wants to quit, may have modified documents open.
  198. bool mLogoutRequestSent; // Disconnect message sent to simulator, no longer safe to send messages to the sim.
  199. S32 mYieldTime;
  200. struct SettingsFiles* mSettingsLocationList;
  201. LLWatchdogTimeout* mMainloopTimeout;
  202. // For performance and metric gathering
  203. LLThread* mFastTimerLogThread;
  204. // for tracking viewer<->region circuit death
  205. bool mAgentRegionLastAlive;
  206. LLUUID mAgentRegionLastID;
  207. LLAllocator mAlloc;
  208. std::set<struct apr_dso_handle_t*> mPlugins;
  209. LLFrameTimer mMemCheckTimer;
  210. boost::scoped_ptr<LLUpdaterService> mUpdater;
  211. //---------------------------------------------
  212. //*NOTE: Mani - legacy updater stuff
  213. // Still useable?
  214. public:
  215. //some information for updater
  216. typedef struct
  217. {
  218. std::string mUpdateExePath;
  219. std::ostringstream mParams;
  220. }LLUpdaterInfo ;
  221. static LLUpdaterInfo *sUpdaterInfo ;
  222. void launchUpdater();
  223. //---------------------------------------------
  224. };
  225. // consts from viewer.h
  226. const S32 AGENT_UPDATES_PER_SECOND = 10;
  227. // Globals with external linkage. From viewer.h
  228. // *NOTE:Mani - These will be removed as the Viewer App Cleanup project continues.
  229. //
  230. // "// llstartup" indicates that llstartup is the only client for this global.
  231. extern LLSD gDebugInfo;
  232. extern BOOL gShowObjectUpdates;
  233. typedef enum
  234. {
  235. LAST_EXEC_NORMAL = 0,
  236. LAST_EXEC_FROZE,
  237. LAST_EXEC_LLERROR_CRASH,
  238. LAST_EXEC_OTHER_CRASH,
  239. LAST_EXEC_LOGOUT_FROZE,
  240. LAST_EXEC_LOGOUT_CRASH
  241. } eLastExecEvent;
  242. extern eLastExecEvent gLastExecEvent; // llstartup
  243. extern U32 gFrameCount;
  244. extern U32 gForegroundFrameCount;
  245. extern LLPumpIO* gServicePump;
  246. extern U64 gFrameTime; // The timestamp of the most-recently-processed frame
  247. extern F32 gFrameTimeSeconds; // Loses msec precision after ~4.5 hours...
  248. extern F32 gFrameIntervalSeconds; // Elapsed time between current and previous gFrameTimeSeconds
  249. extern F32 gFPSClamped; // Frames per second, smoothed, weighted toward last frame
  250. extern F32 gFrameDTClamped;
  251. extern U64 gStartTime;
  252. extern U32 gFrameStalls;
  253. extern LLTimer gRenderStartTime;
  254. extern LLFrameTimer gForegroundTime;
  255. extern LLFrameTimer gLoggedInTime;
  256. extern F32 gLogoutMaxTime;
  257. extern LLTimer gLogoutTimer;
  258. extern F32 gSimLastTime;
  259. extern F32 gSimFrames;
  260. extern BOOL gDisconnected;
  261. extern LLFrameTimer gRestoreGLTimer;
  262. extern BOOL gRestoreGL;
  263. extern BOOL gUseWireframe;
  264. // VFS globals - gVFS is for general use
  265. // gStaticVFS is read-only and is shipped w/ the viewer
  266. // it has pre-cache data like the UI .TGAs
  267. class LLVFS;
  268. extern LLVFS *gStaticVFS;
  269. extern LLMemoryInfo gSysMemory;
  270. extern U64 gMemoryAllocated;
  271. extern std::string gLastVersionChannel;
  272. extern LLVector3 gWindVec;
  273. extern LLVector3 gRelativeWindVec;
  274. extern U32 gPacketsIn;
  275. extern BOOL gPrintMessagesThisFrame;
  276. extern LLUUID gSunTextureID;
  277. extern LLUUID gMoonTextureID;
  278. extern BOOL gRandomizeFramerate;
  279. extern BOOL gPeriodicSlowFrame;
  280. #endif // LL_LLAPPVIEWER_H