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