diff options
Diffstat (limited to 'linden/indra/llplugin/llpluginmessage.h')
-rwxr-xr-x | linden/indra/llplugin/llpluginmessage.h | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/linden/indra/llplugin/llpluginmessage.h b/linden/indra/llplugin/llpluginmessage.h new file mode 100755 index 0000000..fe504c8 --- /dev/null +++ b/linden/indra/llplugin/llpluginmessage.h | |||
@@ -0,0 +1,144 @@ | |||
1 | /** | ||
2 | * @file llpluginmessage.h | ||
3 | * | ||
4 | * @cond | ||
5 | * $LicenseInfo:firstyear=2008&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2008-2010, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at | ||
21 | * http://secondlife.com/developers/opensource/flossexception | ||
22 | * | ||
23 | * By copying, modifying or distributing this software, you acknowledge | ||
24 | * that you have read and understood your obligations described above, | ||
25 | * and agree to abide by those obligations. | ||
26 | * | ||
27 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
28 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
29 | * COMPLETENESS OR PERFORMANCE. | ||
30 | * $/LicenseInfo$ | ||
31 | * | ||
32 | * @endcond | ||
33 | */ | ||
34 | |||
35 | #ifndef LL_LLPLUGINMESSAGE_H | ||
36 | #define LL_LLPLUGINMESSAGE_H | ||
37 | |||
38 | #include "llsd.h" | ||
39 | |||
40 | /** | ||
41 | * @brief LLPluginMessage encapsulates the serialization/deserialization of messages passed to and from plugins. | ||
42 | */ | ||
43 | class LLPluginMessage | ||
44 | { | ||
45 | LOG_CLASS(LLPluginMessage); | ||
46 | public: | ||
47 | LLPluginMessage(); | ||
48 | LLPluginMessage(const LLPluginMessage &p); | ||
49 | LLPluginMessage(const std::string &message_class, const std::string &message_name); | ||
50 | ~LLPluginMessage(); | ||
51 | |||
52 | // reset all internal state | ||
53 | void clear(void); | ||
54 | |||
55 | // Sets the message class and name | ||
56 | // Also has the side-effect of clearing any key/value pairs in the message. | ||
57 | void setMessage(const std::string &message_class, const std::string &message_name); | ||
58 | |||
59 | // Sets a key/value pair in the message | ||
60 | void setValue(const std::string &key, const std::string &value); | ||
61 | void setValueLLSD(const std::string &key, const LLSD &value); | ||
62 | void setValueS32(const std::string &key, S32 value); | ||
63 | void setValueU32(const std::string &key, U32 value); | ||
64 | void setValueBoolean(const std::string &key, bool value); | ||
65 | void setValueReal(const std::string &key, F64 value); | ||
66 | void setValuePointer(const std::string &key, void *value); | ||
67 | |||
68 | std::string getClass(void) const; | ||
69 | std::string getName(void) const; | ||
70 | |||
71 | // Returns true if the specified key exists in this message (useful for optional parameters) | ||
72 | bool hasValue(const std::string &key) const; | ||
73 | |||
74 | // get the value of a particular key as a string. If the key doesn't exist in the message, an empty string will be returned. | ||
75 | std::string getValue(const std::string &key) const; | ||
76 | |||
77 | // get the value of a particular key as LLSD. If the key doesn't exist in the message, a null LLSD will be returned. | ||
78 | LLSD getValueLLSD(const std::string &key) const; | ||
79 | |||
80 | // get the value of a key as a S32. If the value wasn't set as a S32, behavior is undefined. | ||
81 | S32 getValueS32(const std::string &key) const; | ||
82 | |||
83 | // get the value of a key as a U32. Since there isn't an LLSD type for this, we use a hexadecimal string instead. | ||
84 | U32 getValueU32(const std::string &key) const; | ||
85 | |||
86 | // get the value of a key as a Boolean. | ||
87 | bool getValueBoolean(const std::string &key) const; | ||
88 | |||
89 | // get the value of a key as a float. | ||
90 | F64 getValueReal(const std::string &key) const; | ||
91 | |||
92 | // get the value of a key as a pointer. | ||
93 | void* getValuePointer(const std::string &key) const; | ||
94 | |||
95 | // Flatten the message into a string | ||
96 | std::string generate(void) const; | ||
97 | |||
98 | // Parse an incoming message into component parts | ||
99 | // (this clears out all existing state before starting the parse) | ||
100 | // Returns -1 on failure, otherwise returns the number of key/value pairs in the message. | ||
101 | int parse(const std::string &message); | ||
102 | |||
103 | |||
104 | private: | ||
105 | |||
106 | LLSD mMessage; | ||
107 | |||
108 | }; | ||
109 | |||
110 | /** | ||
111 | * @brief Listener for plugin messages. | ||
112 | */ | ||
113 | class LLPluginMessageListener | ||
114 | { | ||
115 | public: | ||
116 | virtual ~LLPluginMessageListener(); | ||
117 | /** Plugin receives message from plugin loader shell. */ | ||
118 | virtual void receivePluginMessage(const LLPluginMessage &message) = 0; | ||
119 | |||
120 | }; | ||
121 | |||
122 | /** | ||
123 | * @brief Dispatcher for plugin messages. | ||
124 | * | ||
125 | * Manages the set of plugin message listeners and distributes messages to plugin message listeners. | ||
126 | */ | ||
127 | class LLPluginMessageDispatcher | ||
128 | { | ||
129 | public: | ||
130 | virtual ~LLPluginMessageDispatcher(); | ||
131 | |||
132 | void addPluginMessageListener(LLPluginMessageListener *); | ||
133 | void removePluginMessageListener(LLPluginMessageListener *); | ||
134 | protected: | ||
135 | void dispatchPluginMessage(const LLPluginMessage &message); | ||
136 | |||
137 | /** A set of message listeners. */ | ||
138 | typedef std::set<LLPluginMessageListener*> listener_set_t; | ||
139 | /** The set of message listeners. */ | ||
140 | listener_set_t mListeners; | ||
141 | }; | ||
142 | |||
143 | |||
144 | #endif // LL_LLPLUGINMESSAGE_H | ||