PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/lllivefile.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 95 lines | 20 code | 13 blank | 62 comment | 0 complexity | 9887c1afb9a279e9cebdceae8fe1b3b4 MD5 | raw file
 1/** 
 2 * @file lllivefile.h
 3 * @brief Automatically reloads a file whenever it changes or is removed.
 4 *
 5 * $LicenseInfo:firstyear=2006&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_LLLIVEFILE_H
28#define LL_LLLIVEFILE_H
29
30extern const F32 DEFAULT_CONFIG_FILE_REFRESH;
31
32
33class LL_COMMON_API LLLiveFile
34{
35public:
36	LLLiveFile(const std::string& filename, const F32 refresh_period = 5.f);
37	virtual ~LLLiveFile();
38
39	/**
40	 * @brief Check to see if this live file should reload.
41	 *
42	 * Call this before using anything that was read & cached
43	 * from the file.
44	 *
45	 * This method calls the <code>loadFile()</code> method if
46	 * any of:
47	 *   file has a new modify time since the last check
48	 *   file used to exist and now does not
49	 *   file used to not exist but now does
50	 * @return Returns true if the file was reloaded.
51	 */
52	bool checkAndReload();
53	
54
55	std::string filename() const;
56
57	/**
58	 * @brief Add this live file to an automated recheck.
59	 *
60	 * Normally, just calling checkAndReload() is enough. In some
61	 * cases though, you may need to let the live file periodically
62	 * check itself.
63	 */
64	void addToEventTimer();
65
66	void setRefreshPeriod(F32 seconds);
67
68protected:
69	/**
70	 * @breif Implement this to load your file if it changed.
71	 *
72	 * This method is called automatically by <code>checkAndReload()</code>,
73	 * so though you must implement this in derived classes, you do
74	 * not need to call it manually.
75	 * @return Returns true if the file was successfully loaded.
76	 */
77	virtual bool loadFile() = 0;
78
79	/**
80	 * @brief Implement this method if you want to get a change callback.
81	 *
82	 * This virtual function will be called automatically at the end
83	 * of <code>checkAndReload()</code> if a new configuration was
84	 * loaded. This does not track differences between the current and
85	 * newly loaded file, so any successful load event will trigger a
86	 * <code>changed()</code> callback. Default is to do nothing.
87	 */
88	virtual void changed() {}
89
90private:
91	class Impl;
92	Impl& impl;
93};
94
95#endif //LL_LLLIVEFILE_H