aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llcommandhandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llcommandhandler.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/linden/indra/newview/llcommandhandler.cpp b/linden/indra/newview/llcommandhandler.cpp
new file mode 100644
index 0000000..fd3aef9
--- /dev/null
+++ b/linden/indra/newview/llcommandhandler.cpp
@@ -0,0 +1,103 @@
1/**
2 * @file llcommandhandler.cpp
3 * @brief Central registry for text-driven "commands", most of
4 * which manipulate user interface. For example, the command
5 * "agent (uuid) about" will open the UI for an avatar's profile.
6 *
7 * $LicenseInfo:firstyear=2007&license=viewergpl$
8 *
9 * Copyright (c) 2007, Linden Research, Inc.
10 *
11 * Second Life Viewer Source Code
12 * The source code in this file ("Source Code") is provided by Linden Lab
13 * to you under the terms of the GNU General Public License, version 2.0
14 * ("GPL"), unless you have obtained a separate licensing agreement
15 * ("Other License"), formally executed by you and Linden Lab. Terms of
16 * the GPL can be found in doc/GPL-license.txt in this distribution, or
17 * online at http://secondlife.com/developers/opensource/gplv2
18 *
19 * There are special exceptions to the terms and conditions of the GPL as
20 * it is applied to this Source Code. View the full text of the exception
21 * in the file doc/FLOSS-exception.txt in this software distribution, or
22 * online at http://secondlife.com/developers/opensource/flossexception
23 *
24 * By copying, modifying or distributing this software, you acknowledge
25 * that you have read and understood your obligations described above,
26 * and agree to abide by those obligations.
27 *
28 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
29 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
30 * COMPLETENESS OR PERFORMANCE.
31 * $/LicenseInfo$
32 */
33#include "llviewerprecompiledheaders.h"
34
35#include "llcommandhandler.h"
36
37// system includes
38#include <boost/tokenizer.hpp>
39
40//---------------------------------------------------------------------------
41// Underlying registry for command handlers, not directly accessible.
42//---------------------------------------------------------------------------
43
44class LLCommandHandlerRegistry
45{
46public:
47 static LLCommandHandlerRegistry& instance();
48 void add(const char* cmd, LLCommandHandler* handler);
49 bool dispatch(const std::string& cmd, const std::vector<std::string>& params);
50
51private:
52 std::map<std::string, LLCommandHandler*> mMap;
53};
54
55// static
56LLCommandHandlerRegistry& LLCommandHandlerRegistry::instance()
57{
58 // Force this to be initialized on first call, because we're going
59 // to be adding items to the std::map before main() and we can't
60 // rely on a global being initialized in the right order.
61 static LLCommandHandlerRegistry instance;
62 return instance;
63}
64
65void LLCommandHandlerRegistry::add(const char* cmd, LLCommandHandler* handler)
66{
67 mMap[cmd] = handler;
68}
69
70bool LLCommandHandlerRegistry::dispatch(const std::string& cmd,
71 const std::vector<std::string>& params)
72{
73 std::map<std::string, LLCommandHandler*>::iterator it = mMap.find(cmd);
74 if (it == mMap.end()) return false;
75 LLCommandHandler* handler = it->second;
76 if (!handler) return false;
77 return handler->handle(params);
78}
79
80//---------------------------------------------------------------------------
81// Automatic registration of commands, runs before main()
82//---------------------------------------------------------------------------
83
84LLCommandHandler::LLCommandHandler(const char* cmd)
85{
86 LLCommandHandlerRegistry::instance().add(cmd, this);
87}
88
89LLCommandHandler::~LLCommandHandler()
90{
91 // Don't care about unregistering these, all the handlers
92 // should be static objects.
93}
94
95//---------------------------------------------------------------------------
96// Public interface
97//---------------------------------------------------------------------------
98
99// static
100bool LLCommandDispatcher::dispatch(const std::string& cmd, const std::vector<std::string>& params)
101{
102 return LLCommandHandlerRegistry::instance().dispatch(cmd, params);
103}