summaryrefslogtreecommitdiff
path: root/indra/newview/llsyntaxid.h
blob: f14693d619fe32b8e032195a4fe50b627a0f060f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/** 
 * @file llsyntaxid.h
 * @brief Contains methods to access the LSLSyntaxId feature and LSLSyntax capability
 * to use the appropriate syntax file for the current region's LSL version.
 * @author Ima Mechanique
 *
 * $LicenseInfo:firstyear=2013&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2013, Linden Research, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */
#ifndef LL_SYNTAXID_H
#define LL_SYNTAXID_H

#include "llviewerprecompiledheaders.h"

#include "llagent.h"
#include "llenvmanager.h"
#include "llhttpclient.h"
#include "llsingleton.h"
#include "llviewerregion.h"

class LLSyntaxIdLSL : public LLSingleton<LLSyntaxIdLSL>
{
friend class fetchKeywordsFileResponder;

public:
	LLSyntaxIdLSL();

	bool			checkSyntaxIdChanged();
	bool			fetching();
	std::string		getFileNameCurrent()	const { return mFileNameCurrent; }
	ELLPath			getFilePath()			const { return mFilePath; }
	std::string		getFileSpec()			const { return mFullFileSpec; }
	LLSD			getKeywordsXML()		const { return mKeywordsXml; }
	LLUUID			getSyntaxId()			const { return mSyntaxIdCurrent; }
	bool			isDifferentVersion()	const { return mVersionChanged; }
	bool			isInitialized()			const { return mInitialized; }

	void			initialize();
	bool			isLoaded() { return mLoaded; }

	bool			isSupportedVersion(const LLSD& content);
	void			setKeywordsXml(const LLSD& content) { mKeywordsXml = content; }
	typedef			boost::signals2::signal<void()> file_fetched_signal_t;
	boost::signals2::connection		addFileFetchedCallback(const file_fetched_signal_t::slot_type& cb);

protected:
	std::string		buildFileNameNew();
	std::string		buildFullFileSpec();
	void			fetchKeywordsFile();
	void			loadDefaultKeywordsIntoLLSD();
	void			loadKeywordsIntoLLSD();
	void			setSyntaxId(LLUUID SyntaxId) { mSyntaxIdCurrent = SyntaxId; }
	void			setFileNameCurrent(const std::string& name) { mFileNameCurrent = name; }
	void			setFileNameNew(const std::string name) { mFileNameNew = name; }
	
private:
	static const std::string CAPABILITY_NAME;
	static const std::string FILENAME_DEFAULT;
	static const std::string SIMULATOR_FEATURE;

	bool		mInitialized;
	LLSD		mKeywordsXml;
	bool		mLoaded;
	bool		mLoadFailed;
	bool		mVersionChanged;
	file_fetched_signal_t	mFileFetchedSignal;
	
	std::string		mCapabilityName;
	std::string		mCapabilityURL;
	std::string		mFileNameCurrent;
	std::string		mFileNameDefault;
	std::string		mFileNameNew;
	ELLPath			mFilePath;
	std::string		mFullFileSpec;
	std::string		mSimulatorFeature;
	LLUUID			mSyntaxIdCurrent;
	LLUUID			mSyntaxIdNew;
};


class fetchKeywordsFileResponder : public LLHTTPClient::Responder
{
public:
	std::string	mFileSpec;

	/**
	 * @brief fetchKeywordsFileResponder
	 * @param filespec	File path and name of where to save the returned data
	 */
	fetchKeywordsFileResponder(std::string filespec);

	void errorWithContent(U32 status,
						const std::string& reason,
						const LLSD& content);

	/**
	 * @brief Checks the returned LLSD for version and stores it in the LLSyntaxIdLSL object.
	 * @param content_ref The returned LLSD.
	 */
	void result(const LLSD& content_ref);

	/**
	 * @brief Saves the returned file to the location provided at instantiation.
	 *			Could be extended to manage cached entries.
	 * @param content_ref	The LSL syntax file for the sim.
	 */
	void cacheFile(const LLSD& content_ref);
};

#endif // LLSYNTAXID_H