llappviewer.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /**
  2. * @file llappviewer.h
  3. * @brief The LLAppViewer class declaration
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewergpl$
  6. *
  7. * Copyright (c) 2007-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLAPPVIEWER_H
  33. #define LL_LLAPPVIEWER_H
  34. #include "llapp.h"
  35. #include "llappcorehttp.h"
  36. #if LL_LINUX
  37. // Under Linux, calling viewer code from within a DBus callback dead-locked the
  38. // next gtk_main() call when the viewer was made gdk threads aware (i.e. with
  39. // gdk_threads_init() used, which allowed a non-blocking GTK file selector).
  40. // Note that since we do not use GDK/GTK any more now in the Cool VL Viewer,
  41. // this code seems to work again. Yet, it is super-dirty to call code that may
  42. // reenter glib (in the render loop, via LLWindowSDL) in a glib callback, so I
  43. // decided to keep it disabled. HB
  44. # define LL_CALL_SLURL_DISPATCHER_IN_CALLBACK 0
  45. #endif
  46. class LLCommandLineParser;
  47. class LLEventPump;
  48. class LLFile;
  49. class LLPumpIO;
  50. class LLThreadPool;
  51. class LLWorkQueue;
  52. class LLAppViewer : public LLApp
  53. {
  54. protected:
  55. LOG_CLASS(LLAppViewer);
  56. public:
  57. LLAppViewer();
  58. virtual ~LLAppViewer();
  59. //
  60. // Main application logic
  61. //
  62. virtual InitState init(); // Override to do application initialization
  63. virtual bool cleanup(); // Override to do application cleanup
  64. // Override for the application main loop. Needs to at least gracefully
  65. // notice the QUITTING state and exit.
  66. virtual bool mainLoop();
  67. enum EExitCode
  68. {
  69. EXIT_OK = 0,
  70. EXIT_INIT_FAILED,
  71. EXIT_CODE_BASH_RESERVED, // Reserved for bash: do not use !
  72. EXIT_LOGIN_FAILED,
  73. EXIT_FORCE_LOGGED_OUT,
  74. VIEWER_EXIT_CODES // Start of user-defined codes (e.g. Lua)
  75. };
  76. // Application control
  77. void forceQuit(); // Puts the viewer into 'shutting down without error' mode.
  78. void requestQuit(); // Request a quit. A kinder, gentler quit.
  79. void userQuit(); // The users asks to quit. Confirm, then requestQuit()
  80. // Displays an error dialog and forcibly quit.
  81. void earlyExit(const std::string& name,
  82. const LLSD& substitutions = LLSD());
  83. void forceExit(); // exit(-1) immediately (after minimal cleanup).
  84. void abortQuit(); // Called to abort a quit request.
  85. LL_INLINE bool quitRequested() { return mQuitRequested; }
  86. LL_INLINE bool logoutRequestSent() { return mLogoutRequestSent; }
  87. LL_INLINE bool isSecondInstance() { return mSecondInstance; }
  88. LL_INLINE bool isSecondInstanceSiblingViewer() { return mIsSiblingViewer; }
  89. void idleAFKCheck(bool force_afk = false);
  90. void writeDebugInfo(bool log_interesting_info = true);
  91. // Report true if under the control of a debugger. A null-op default.
  92. LL_INLINE virtual bool beingDebugged() { return false; }
  93. // Plateform-specific Vulkan driver presence and API version detections.
  94. virtual bool probeVulkan(std::string& version) = 0;
  95. // Require platform-specific override to reset error handling mechanism.
  96. // Returns false if the error trap needed restoration.
  97. virtual bool restoreErrorTrap() = 0;
  98. // Any low-level crash-prep that has to happen in the context of the
  99. // crashing thread before the crash report is delivered:
  100. virtual void handleSyncCrashTrace() = 0;
  101. // Hey ! The viewer crashed. Do this, soon:
  102. static void handleViewerCrash();
  103. // Hey ! The viewer crashed. Do this right NOW in the context of the
  104. // crashing thread:
  105. static void handleSyncViewerCrash();
  106. LL_INLINE const std::string& getSerialNumber() { return mSerialNumber; }
  107. LL_INLINE bool getPurgeCache() const { return mPurgeCache; }
  108. // Forces disconnection, with a message to the user.
  109. void forceDisconnect(const std::string& msg);
  110. // Causes a crash state due to bad network packet.
  111. void badNetworkHandler();
  112. LL_INLINE bool hasSavedFinalSnapshot() { return mSavedFinalSnapshot; }
  113. void saveFinalSnapshot();
  114. void loadNameCache();
  115. void saveNameCache();
  116. void loadExperienceCache();
  117. void saveExperienceCache();
  118. void stampMarkerFile(LLFile* marker_file);
  119. bool isOurMarkerFile(std::string& filename);
  120. void checkSiblingMarkerFile(std::string& filename);
  121. void removeMarkerFile(bool leave_logout_marker = false);
  122. // Load settings from the location specified by loction_key.
  123. // Key availale and rules for loading, are specified in
  124. // 'app_settings/settings_files.xml'
  125. bool loadSettingsFromDirectory(const std::string& location_key,
  126. bool set_defaults = false);
  127. std::string getSettingsFilename(const std::string& location_key,
  128. const std::string& file);
  129. // Saves the global settings, on the condition that we are the first
  130. // Cool VL Viewer running instance.
  131. void saveGlobalSettings();
  132. // Handle the 'login completed' event.
  133. void handleLoginComplete();
  134. // llcorehttp init/shutdown/config information.
  135. LL_INLINE LLAppCoreHttp& getAppCoreHttp() { return mAppCoreHttp; }
  136. // Called from llviewercontrol.cpp when UserLogFile is in use
  137. LL_INLINE void clearLogFilename() { mLogFileName.clear(); }
  138. bool isSavedMACValid() const { return mSavedMACValid; }
  139. static U32 getSettingU32(const std::string& name);
  140. static void setSettingU32(const std::string& name, U32 value);
  141. static void pauseTextureFetch();
  142. static void updateTextureFetch();
  143. #if LL_WINDOWS
  144. bool isRunningUnderWine() const { return mUnderWine; }
  145. #endif
  146. protected:
  147. virtual bool initWindow(); // Initialize the viewer's window.
  148. virtual void initLogging(); // Initialize log files, logging system.
  149. static void errorCallback(const std::string& error_string);
  150. // Rename the log as appropriate on exit and depending whether this
  151. // viewer is/was the first running instance or not.
  152. // This must be called both on start-up and on exit (on start-up, if we
  153. // are a new instance).
  154. void renameLog(bool on_exit);
  155. // Initialize OS level debugging console:
  156. LL_INLINE virtual void initConsole() {}
  157. // A false result indicates the app should quit:
  158. LL_INLINE virtual bool initHardwareTest() { return true; }
  159. virtual bool initAppMessagesHandler();
  160. virtual bool sendURLToOtherInstance(const std::string& url);
  161. #if LL_LINUX && !LL_CALL_SLURL_DISPATCHER_IN_CALLBACK
  162. virtual const std::string& getReceivedSLURL() = 0;
  163. virtual void clearReceivedSLURL() = 0;
  164. #endif
  165. // Allows platforms to specify the command line args.
  166. LL_INLINE virtual bool initParseCommandLine(LLCommandLineParser& clp)
  167. {
  168. return true;
  169. }
  170. // Platforms specific classes generate this.
  171. virtual std::string generateSerialNumber() = 0;
  172. private:
  173. // Initializes viewer threads.
  174. void initThreads();
  175. // Initializes settings from the command line/config file:
  176. InitState initConfiguration();
  177. void initGridChoice();
  178. bool initCache(); // Initialize local client cache.
  179. void purgeCache(); // Clear the local cache.
  180. void checkMemory();
  181. // We have switched locations of both Mac and Windows cache, make sure
  182. // files migrate and old cache is cleared out.
  183. void migrateCacheDirectory();
  184. // Sets some config data to current or default values during cleanup:
  185. void cleanupSavedSettings();
  186. // Deletes cached files the match the given wildcard:
  187. void removeCacheFiles(const char* filemask);
  188. // Writes system info to "debug_info.log":
  189. void writeSystemInfo();
  190. // This shall be called only once, at early initialization time.
  191. bool anotherInstanceRunning();
  192. // Called only when we are the only running instance.
  193. void initMarkerFile();
  194. void frame(LLEventPump& mainloop);
  195. void idle(bool run_rlv_maintenance = true);
  196. void idleShutdown();
  197. void idleNameCache();
  198. void idleNetwork();
  199. void sendLogoutRequest();
  200. void disconnectViewer();
  201. public:
  202. // *NOTE: There are currently 3 settings files: "Global" and "PerAccount"
  203. // The list is found in app_settings/settings_files.xml but since they are
  204. // used explicitly in code, the follow consts should also do the trick.
  205. static const std::string sGlobalSettingsName;
  206. static const std::string sPerAccountSettingsName;
  207. private:
  208. LLThreadPool* mGeneralThreadPool;
  209. // For tracking viewer<->region circuit death
  210. LLUUID mAgentRegionLastID;
  211. LLSD mSettingsLocationList;
  212. std::string mSerialNumber;
  213. // llcorehttp library init/shutdown helper
  214. LLAppCoreHttp mAppCoreHttp;
  215. F32 mMainloopTimeoutDefault;
  216. U32 mLastAgentControlFlags;
  217. F32 mLastAgentForceUpdate;
  218. std::string mLogFileName; // Our log file name.
  219. std::string mMarkerFileName;
  220. // A file created to indicate the app is running.
  221. LLFile* mMarkerFile;
  222. // A file created to indicate the app is running.
  223. std::string mLogoutMarkerFileName;
  224. bool mOwnsLogoutMarkerFile;
  225. bool mPurgeCache;
  226. bool mPurgeOnExit;
  227. bool mSavedFinalSnapshot;
  228. // Only save per account settings if login succeeded
  229. bool mSavePerAccountSettings;
  230. // User wants to quit, may have modified documents open.
  231. bool mQuitRequested;
  232. // Disconnect message sent to simulator, no longer safe to send messages to
  233. // the sim.
  234. bool mLogoutRequestSent;
  235. // For tracking viewer<->region circuit death
  236. bool mAgentRegionLastAlive;
  237. // Was the saved cyphered MAC address valid ?
  238. bool mSavedMACValid;
  239. // Is this another instance of a SL viewer ?
  240. bool mSecondInstance;
  241. // Is this a second instance of our viewer ?
  242. bool mIsOurViewer;
  243. // Is that 2nd instance another version of the same branch of our viewer ?
  244. bool mSameBranchViewer;
  245. // Is that 2nd instance an entirely different version of our viewer ?
  246. bool mIsSiblingViewer;
  247. #if LL_WINDOWS
  248. // Flag set when running a Windows build under Wine. HB
  249. bool mUnderWine;
  250. #endif
  251. };
  252. constexpr F32 AGENT_UPDATES_PER_SECOND = 10.f;
  253. constexpr F32 AGENT_FORCE_UPDATES_PER_SECOND = 1.f;
  254. // The LLAppViewer singleton is created in main()/WinMain(). So do not use it
  255. // in pre-entry (static initialization) code.
  256. extern LLAppViewer* gAppViewerp;
  257. // Globals with external linkage. From viewer.h
  258. //
  259. // "// llstartup" indicates that llstartup is the only client for this global.
  260. extern LLSD gDebugInfo;
  261. typedef enum
  262. {
  263. LAST_EXEC_NORMAL = 0,
  264. LAST_EXEC_FROZE,
  265. LAST_EXEC_LLERROR_CRASH,
  266. LAST_EXEC_OTHER_CRASH,
  267. LAST_EXEC_LOGOUT_FROZE,
  268. LAST_EXEC_LOGOUT_CRASH
  269. } eLastExecEvent;
  270. extern eLastExecEvent gLastExecEvent;
  271. extern U32 gFrameCount;
  272. extern U32 gForegroundFrameCount;
  273. extern LLPumpIO* gServicePumpIOp;
  274. extern LLWorkQueue* gMainloopWorkp;
  275. extern S32 gExitCode;
  276. // The timestamp of the most-recently-processed frame
  277. extern U64 gFrameTime;
  278. // Loses msec precision after ~4.5 hours...
  279. extern F32 gFrameTimeSeconds;
  280. // Elapsed time between current and previous gFrameTimeSeconds
  281. extern F32 gFrameIntervalSeconds;
  282. // Frames per second, smoothed, weighted toward last frame
  283. extern F32 gFPSClamped;
  284. extern F32 gFrameDT;
  285. extern U64 gStartTime;
  286. extern U32 gFrameSleepTime;
  287. extern LLTimer gRenderStartTime;
  288. extern LLFrameTimer gForegroundTime;
  289. extern F32 gLogoutMaxTime;
  290. extern LLTimer gLogoutTimer;
  291. extern F32 gSimLastTime;
  292. extern F32 gSimFrames;
  293. extern bool gAvatarMovedOnLogin;
  294. extern bool gLogoutInProgress;
  295. extern bool gDisconnected;
  296. extern LLFrameTimer gRestoreGLTimer;
  297. extern bool gRestoreGL;
  298. extern bool gUseWireframe;
  299. extern bool gEnableFastTimers;
  300. // Memory checks
  301. extern LLFrameTimer gMemoryCheckTimer;
  302. extern U64 gMemoryAllocated;
  303. extern bool gBalanceObjectCache;
  304. extern std::string gLastVersionChannel;
  305. extern LLVector3 gWindVec;
  306. extern LLVector3 gRelativeWindVec;
  307. extern U32 gPacketsIn;
  308. extern std::string gSecondLife;
  309. extern std::string gViewerVersionString;
  310. extern U64 gViewerVersionNumber;
  311. // Set after settings are loaded
  312. extern std::string gCurrentVersion;
  313. extern std::string gWindowTitle;
  314. // Plugin presence flag
  315. extern bool gHasGstreamer;
  316. extern bool gAllowTapTapHoldRun;
  317. extern bool gShowObjectUpdates;
  318. extern bool gAcceptTOS;
  319. extern bool gAcceptCriticalMessage;
  320. constexpr size_t MAC_ADDRESS_BYTES = 6;
  321. extern unsigned char gMACAddress[MAC_ADDRESS_BYTES];
  322. #endif // LL_LLAPPVIEWER_H