diff options
author | Armin Weatherwax | 2010-06-14 12:04:49 +0200 |
---|---|---|
committer | Armin Weatherwax | 2010-09-23 15:38:25 +0200 |
commit | 35df5441d3e2789663532c948731aff3a1e04728 (patch) | |
tree | ac7674289784a5f96106ea507637055a8dada78a /linden/indra/test_apps/llplugintest/demo_plugin.cpp | |
parent | Changed version to Experimental 2010.09.18 (diff) | |
download | meta-impy-35df5441d3e2789663532c948731aff3a1e04728.zip meta-impy-35df5441d3e2789663532c948731aff3a1e04728.tar.gz meta-impy-35df5441d3e2789663532c948731aff3a1e04728.tar.bz2 meta-impy-35df5441d3e2789663532c948731aff3a1e04728.tar.xz |
llmediaplugins first step
Diffstat (limited to '')
-rw-r--r-- | linden/indra/test_apps/llplugintest/demo_plugin.cpp | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/linden/indra/test_apps/llplugintest/demo_plugin.cpp b/linden/indra/test_apps/llplugintest/demo_plugin.cpp new file mode 100644 index 0000000..772fa16 --- /dev/null +++ b/linden/indra/test_apps/llplugintest/demo_plugin.cpp | |||
@@ -0,0 +1,220 @@ | |||
1 | /** | ||
2 | * @file demo_plugin.cpp | ||
3 | * @brief Test plugin to be loaded by the llplugin testbed. | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2008&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2008-2009, 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://secondlifegrid.net/programs/open_source/licensing/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://secondlifegrid.net/programs/open_source/licensing/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 | |||
33 | #include "linden_common.h" | ||
34 | |||
35 | #ifdef WIN32 | ||
36 | #include <windows.h> | ||
37 | #endif | ||
38 | |||
39 | #include "llplugininstance.h" | ||
40 | #include "llpluginmessage.h" | ||
41 | #include "llpluginmessageclasses.h" | ||
42 | |||
43 | // TODO: Make sure that the only symbol exported from this library is LLPluginInitEntryPoint | ||
44 | |||
45 | class DemoPlugin | ||
46 | { | ||
47 | public: | ||
48 | |||
49 | static int init(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data, LLPluginInstance::sendMessageFunction *plugin_send_func, void **plugin_user_data); | ||
50 | |||
51 | private: | ||
52 | DemoPlugin(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data); | ||
53 | ~DemoPlugin(); | ||
54 | |||
55 | static void staticReceiveMessage(const char *message_string, void **user_data); | ||
56 | void receiveMessage(const char *message_string); | ||
57 | void sendMessage(const LLPluginMessage &message); | ||
58 | |||
59 | LLPluginInstance::sendMessageFunction mHostSendFunction; | ||
60 | void *mHostUserData; | ||
61 | bool mDeleteMe; | ||
62 | |||
63 | int mSharedSegmentFillValue; | ||
64 | void *mSharedSegmentBase; | ||
65 | size_t mSharedSegmentSize; | ||
66 | }; | ||
67 | |||
68 | int DemoPlugin::init(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data, LLPluginInstance::sendMessageFunction *plugin_send_func, void **plugin_user_data) | ||
69 | { | ||
70 | DemoPlugin *self = new DemoPlugin(host_send_func, host_user_data); | ||
71 | *plugin_send_func = staticReceiveMessage; | ||
72 | *plugin_user_data = (void*)self; | ||
73 | |||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | DemoPlugin::DemoPlugin(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data) | ||
78 | { | ||
79 | std::cerr << "DemoPlugin constructor" << std::endl; | ||
80 | |||
81 | mHostSendFunction = host_send_func; | ||
82 | mHostUserData = host_user_data; | ||
83 | mDeleteMe = false; | ||
84 | mSharedSegmentBase = NULL; | ||
85 | mSharedSegmentSize = 0; | ||
86 | mSharedSegmentFillValue = 0; | ||
87 | } | ||
88 | |||
89 | DemoPlugin::~DemoPlugin() | ||
90 | { | ||
91 | std::cerr << "DemoPlugin destructor" << std::endl; | ||
92 | } | ||
93 | |||
94 | void DemoPlugin::staticReceiveMessage(const char *message_string, void **user_data) | ||
95 | { | ||
96 | DemoPlugin *self = (DemoPlugin*)*user_data; | ||
97 | |||
98 | if(self != NULL) | ||
99 | { | ||
100 | self->receiveMessage(message_string); | ||
101 | |||
102 | // If the plugin has processed the delete message, delete it. | ||
103 | if(self->mDeleteMe) | ||
104 | { | ||
105 | delete self; | ||
106 | *user_data = NULL; | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | |||
111 | void DemoPlugin::receiveMessage(const char *message_string) | ||
112 | { | ||
113 | // std::cerr << "DemoPlugin::receiveMessage: received message: \"" << message_string << "\"" << std::endl; | ||
114 | LLPluginMessage message_in; | ||
115 | |||
116 | if(message_in.parse(message_string) >= 0) | ||
117 | { | ||
118 | std::string message_class = message_in.getClass(); | ||
119 | std::string message_name = message_in.getName(); | ||
120 | if(message_class == "base") | ||
121 | { | ||
122 | if(message_name == "init") | ||
123 | { | ||
124 | LLPluginMessage message("base", "init_response"); | ||
125 | LLSD versions = LLSD::emptyMap(); | ||
126 | versions[LLPLUGIN_MESSAGE_CLASS_BASE] = LLPLUGIN_MESSAGE_CLASS_BASE_VERSION; | ||
127 | versions[LLPLUGIN_MESSAGE_CLASS_MEDIA] = LLPLUGIN_MESSAGE_CLASS_MEDIA_VERSION; | ||
128 | message.setValueLLSD("versions", versions); | ||
129 | sendMessage(message); | ||
130 | } | ||
131 | else if(message_name == "idle") | ||
132 | { | ||
133 | // no response is necessary here. | ||
134 | // std::cerr << "DemoPlugin::receiveMessage: idle processing" << std::endl; | ||
135 | if(mSharedSegmentBase != NULL) | ||
136 | { | ||
137 | // Fill the shared memory segment | ||
138 | memset(mSharedSegmentBase, mSharedSegmentFillValue, mSharedSegmentSize); | ||
139 | // and increment the fill value | ||
140 | mSharedSegmentFillValue++; | ||
141 | } | ||
142 | } | ||
143 | else if(message_name == "shutdown") | ||
144 | { | ||
145 | sendMessage(LLPluginMessage("base", "shutdown_response")); | ||
146 | |||
147 | mDeleteMe = true; | ||
148 | } | ||
149 | else if(message_name == "shm_added") | ||
150 | { | ||
151 | // Normally, we would check the name and match it up with something from another message. | ||
152 | // For this test, just fill any segment that comes in. | ||
153 | mSharedSegmentSize = (size_t)message_in.getValueS32("size"); | ||
154 | mSharedSegmentBase = (void*)message_in.getValueU32("address"); | ||
155 | |||
156 | std::cerr << "DemoPlugin::receiveMessage: shared memory added, name: " << message_in.getValue("name") | ||
157 | << ", size: " << mSharedSegmentSize | ||
158 | << ", address: " << mSharedSegmentBase | ||
159 | << std::endl; | ||
160 | |||
161 | memset(mSharedSegmentBase, mSharedSegmentFillValue, mSharedSegmentSize); | ||
162 | |||
163 | } | ||
164 | else if(message_name == "shm_remove") | ||
165 | { | ||
166 | std::cerr << "DemoPlugin::receiveMessage: shared memory remove" << std::endl; | ||
167 | |||
168 | // Normally, we would check the name and match it up with something from another message. | ||
169 | // For this test, just stop filling the only segment we track. | ||
170 | |||
171 | mSharedSegmentBase = NULL; | ||
172 | |||
173 | // Send the response so it can be cleaned up. | ||
174 | LLPluginMessage message("base", "shm_remove_response"); | ||
175 | message.setValue("name", message_in.getValue("name")); | ||
176 | sendMessage(message); | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | std::cerr << "DemoPlugin::receiveMessage: unknown base message: " << message_name << std::endl; | ||
181 | } | ||
182 | } | ||
183 | else | ||
184 | { | ||
185 | std::cerr << "DemoPlugin::receiveMessage: unknown message class: " << message_class << std::endl; | ||
186 | } | ||
187 | |||
188 | } | ||
189 | } | ||
190 | |||
191 | void DemoPlugin::sendMessage(const LLPluginMessage &message) | ||
192 | { | ||
193 | std::string output = message.generate(); | ||
194 | mHostSendFunction(output.c_str(), &mHostUserData); | ||
195 | } | ||
196 | |||
197 | |||
198 | extern "C" | ||
199 | { | ||
200 | #ifdef WIN32 | ||
201 | __declspec(dllexport) | ||
202 | #endif | ||
203 | int LLPluginInitEntryPoint(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data, LLPluginInstance::sendMessageFunction *plugin_send_func, void **plugin_user_data); | ||
204 | } | ||
205 | |||
206 | int | ||
207 | #ifdef WIN32 | ||
208 | __declspec(dllexport) | ||
209 | #endif | ||
210 | LLPluginInitEntryPoint(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data, LLPluginInstance::sendMessageFunction *plugin_send_func, void **plugin_user_data) | ||
211 | { | ||
212 | return DemoPlugin::init(host_send_func, host_user_data, plugin_send_func, plugin_user_data); | ||
213 | } | ||
214 | |||
215 | #ifdef WIN32 | ||
216 | int WINAPI DllEntryPoint( HINSTANCE hInstance, unsigned long reason, void* params ) | ||
217 | { | ||
218 | return 1; | ||
219 | } | ||
220 | #endif | ||