PageRenderTime 30ms CodeModel.GetById 14ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llui/llcommandmanager.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 202 lines | 127 code | 50 blank | 25 comment | 2 complexity | fff90c6aba6f008957b0716d52cbd3b5 MD5 | raw file
  1/** 
  2 * @file llcommandmanager.h
  3 * @brief LLCommandManager class to hold commands
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2011, 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_LLCOMMANDMANAGER_H
 28#define LL_LLCOMMANDMANAGER_H
 29
 30#include "llinitparam.h"
 31#include "llsingleton.h"
 32
 33
 34class LLCommand;
 35class LLCommandManager;
 36
 37
 38class LLCommandId
 39{
 40public:
 41	friend class LLCommand;
 42	friend class LLCommandManager;
 43
 44	struct Params : public LLInitParam::Block<Params>
 45	{
 46		Mandatory<std::string> name;
 47
 48		Params()
 49		:	name("name")
 50		{}
 51	};
 52
 53	LLCommandId(const std::string& name)
 54	{
 55		mUUID = LLUUID::generateNewID(name);
 56	}
 57
 58	LLCommandId(const Params& p)
 59	{
 60		mUUID = LLUUID::generateNewID(p.name);
 61	}
 62
 63	LLCommandId(const LLUUID& uuid)
 64	:	mUUID(uuid)
 65	{}
 66	
 67	const LLUUID& uuid() const { return mUUID; }
 68
 69	bool operator!=(const LLCommandId& command) const
 70	{
 71		return (mUUID != command.mUUID);
 72	}
 73
 74	bool operator==(const LLCommandId& command) const
 75	{
 76		return (mUUID == command.mUUID);
 77	}
 78
 79	static const LLCommandId null;
 80
 81private:
 82	LLUUID		mUUID;
 83};
 84
 85typedef std::list<LLCommandId> command_id_list_t;
 86
 87
 88class LLCommand
 89{
 90public:
 91	struct Params : public LLInitParam::Block<Params>
 92	{
 93		Mandatory<bool>			available_in_toybox;
 94		Mandatory<std::string>	icon;
 95		Mandatory<std::string>	label_ref;
 96		Mandatory<std::string>	name;
 97		Mandatory<std::string>	tooltip_ref;
 98
 99		Mandatory<std::string>	execute_function;
100		Optional<LLSD>			execute_parameters;
101
102		Optional<std::string>	execute_stop_function;
103		Optional<LLSD>			execute_stop_parameters;
104		
105		Optional<std::string>	is_enabled_function;
106		Optional<LLSD>			is_enabled_parameters;
107
108		Optional<std::string>	is_running_function;
109		Optional<LLSD>			is_running_parameters;
110
111		Optional<std::string>	is_starting_function;
112		Optional<LLSD>			is_starting_parameters;
113
114		Params();
115	};
116
117	LLCommand(const LLCommand::Params& p);
118
119	const bool availableInToybox() const { return mAvailableInToybox; }
120	const std::string& icon() const { return mIcon; }
121	const LLCommandId& id() const { return mIdentifier; }
122	const std::string& labelRef() const { return mLabelRef; }
123	const std::string& name() const { return mName; }
124	const std::string& tooltipRef() const { return mTooltipRef; }
125
126	const std::string& executeFunctionName() const { return mExecuteFunction; }
127	const LLSD& executeParameters() const { return mExecuteParameters; }
128
129	const std::string& executeStopFunctionName() const { return mExecuteStopFunction; }
130	const LLSD& executeStopParameters() const { return mExecuteStopParameters; }
131	
132	const std::string& isEnabledFunctionName() const { return mIsEnabledFunction; }
133	const LLSD& isEnabledParameters() const { return mIsEnabledParameters; }
134
135	const std::string& isRunningFunctionName() const { return mIsRunningFunction; }
136	const LLSD& isRunningParameters() const { return mIsRunningParameters; }
137
138	const std::string& isStartingFunctionName() const { return mIsStartingFunction; }
139	const LLSD& isStartingParameters() const { return mIsStartingParameters; }
140
141private:
142	LLCommandId mIdentifier;
143
144	bool        mAvailableInToybox;
145	std::string mIcon;
146	std::string mLabelRef;
147	std::string mName;
148	std::string mTooltipRef;
149
150	std::string mExecuteFunction;
151	LLSD        mExecuteParameters;
152
153	std::string mExecuteStopFunction;
154	LLSD        mExecuteStopParameters;
155	
156	std::string mIsEnabledFunction;
157	LLSD        mIsEnabledParameters;
158
159	std::string mIsRunningFunction;
160	LLSD        mIsRunningParameters;
161
162	std::string mIsStartingFunction;
163	LLSD        mIsStartingParameters;
164};
165
166
167class LLCommandManager
168:	public LLSingleton<LLCommandManager>
169{
170public:
171	struct Params : public LLInitParam::Block<Params>
172	{
173		Multiple< LLCommand::Params, AtLeast<1> > commands;
174
175		Params()
176			:	commands("command")
177		{
178		}
179	};
180
181	LLCommandManager();
182	~LLCommandManager();
183
184	U32 commandCount() const;
185	LLCommand * getCommand(U32 commandIndex);
186	LLCommand * getCommand(const LLCommandId& commandId);
187
188	static bool load();
189
190protected:
191	void addCommand(LLCommand * command);
192
193private:
194	typedef std::map<LLUUID, U32>		CommandIndexMap;
195	typedef std::vector<LLCommand *>	CommandVector;
196	
197	CommandVector	mCommands;
198	CommandIndexMap	mCommandIndices;
199};
200
201
202#endif // LL_LLCOMMANDMANAGER_H