diff options
Diffstat (limited to 'linden/indra/llmessage/lldispatcher.h')
-rw-r--r-- | linden/indra/llmessage/lldispatcher.h | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/linden/indra/llmessage/lldispatcher.h b/linden/indra/llmessage/lldispatcher.h new file mode 100644 index 0000000..2a103f0 --- /dev/null +++ b/linden/indra/llmessage/lldispatcher.h | |||
@@ -0,0 +1,114 @@ | |||
1 | /** | ||
2 | * @file lldispatcher.h | ||
3 | * @brief LLDispatcher class header file. | ||
4 | * | ||
5 | * Copyright (c) 2004-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #ifndef LL_LLDISPATCHER_H | ||
29 | #define LL_LLDISPATCHER_H | ||
30 | |||
31 | #include <map> | ||
32 | #include <vector> | ||
33 | #include <string> | ||
34 | |||
35 | class LLDispatcher; | ||
36 | class LLMessageSystem; | ||
37 | class LLUUID; | ||
38 | |||
39 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
40 | // Class LLDispatchHandler | ||
41 | // | ||
42 | // Abstract base class for handling dispatches. Derive your own | ||
43 | // classes, construct them, and add them to the dispatcher you want to | ||
44 | // use. | ||
45 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
46 | |||
47 | class LLDispatchHandler | ||
48 | { | ||
49 | public: | ||
50 | typedef std::vector<std::string> sparam_t; | ||
51 | //typedef std::vector<S32> iparam_t; | ||
52 | LLDispatchHandler() {} | ||
53 | virtual ~LLDispatchHandler() {} | ||
54 | virtual bool operator()( | ||
55 | const LLDispatcher* dispatcher, | ||
56 | const std::string& key, | ||
57 | const LLUUID& invoice, | ||
58 | const sparam_t& string) = 0; | ||
59 | //const iparam_t& integers) = 0; | ||
60 | }; | ||
61 | |||
62 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
63 | // Class LLDispatcher | ||
64 | // | ||
65 | // Basic utility class that handles dispatching keyed operations to | ||
66 | // function objects implemented as LLDispatchHandler derivations. | ||
67 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
68 | class LLDispatcher | ||
69 | { | ||
70 | public: | ||
71 | typedef std::string key_t; | ||
72 | typedef std::vector<std::string> keys_t; | ||
73 | typedef std::vector<std::string> sparam_t; | ||
74 | //typedef std::vector<S32> iparam_t; | ||
75 | |||
76 | // construct a dispatcher. | ||
77 | LLDispatcher(); | ||
78 | virtual ~LLDispatcher(); | ||
79 | |||
80 | // Returns if they keyed handler exists in this dispatcher. | ||
81 | bool isHandlerPresent(const key_t& name) const; | ||
82 | |||
83 | // copy all known keys onto keys_t structure | ||
84 | void copyAllHandlerNames(keys_t& names) const; | ||
85 | |||
86 | // Call this method with the name of the request that has come | ||
87 | // in. If the handler is present, it is called with the params and | ||
88 | // returns the return value from | ||
89 | bool dispatch( | ||
90 | const key_t& name, | ||
91 | const LLUUID& invoice, | ||
92 | const sparam_t& strings) const; | ||
93 | //const iparam_t& itegers) const; | ||
94 | |||
95 | // Add a handler. If one with the same key already exists, its | ||
96 | // pointer is returned, otherwise returns NULL. This object does | ||
97 | // not do memory management of the LLDispatchHandler, and relies | ||
98 | // on the caller to delete the object if necessary. | ||
99 | LLDispatchHandler* addHandler(const key_t& name, LLDispatchHandler* func); | ||
100 | |||
101 | // Helper method to unpack the dispatcher message bus | ||
102 | // format. Returns true on success. | ||
103 | static bool unpackMessage( | ||
104 | LLMessageSystem* msg, | ||
105 | key_t& method, | ||
106 | LLUUID& invoice, | ||
107 | sparam_t& parameters); | ||
108 | |||
109 | protected: | ||
110 | typedef std::map<key_t, LLDispatchHandler*> dispatch_map_t; | ||
111 | dispatch_map_t mHandlers; | ||
112 | }; | ||
113 | |||
114 | #endif // LL_LLDISPATCHER_H | ||