diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmessage/llsdrpcclient.h | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llmessage/llsdrpcclient.h | 310 |
1 files changed, 310 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llsdrpcclient.h b/linden/indra/llmessage/llsdrpcclient.h new file mode 100644 index 0000000..8de7f12 --- /dev/null +++ b/linden/indra/llmessage/llsdrpcclient.h | |||
@@ -0,0 +1,310 @@ | |||
1 | /** | ||
2 | * @file llsdrpcclient.h | ||
3 | * @author Phoenix | ||
4 | * @date 2005-11-05 | ||
5 | * @brief Implementation and helpers for structure data RPC clients. | ||
6 | * | ||
7 | * Copyright (c) 2005-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #ifndef LL_LLSDRPCCLIENT_H | ||
31 | #define LL_LLSDRPCCLIENT_H | ||
32 | |||
33 | /** | ||
34 | * This file declares classes to encapsulate a basic structured data | ||
35 | * remote procedure client. | ||
36 | */ | ||
37 | |||
38 | #include "llchainio.h" | ||
39 | #include "llfiltersd2xmlrpc.h" | ||
40 | #include "lliopipe.h" | ||
41 | #include "llurlrequest.h" | ||
42 | |||
43 | /** | ||
44 | * @class LLSDRPCClientResponse | ||
45 | * @brief Abstract base class to represent a response from an SD server. | ||
46 | * | ||
47 | * This is used as a base class for callbacks generated from an | ||
48 | * structured data remote procedure call. The | ||
49 | * <code>extractResponse</code> method will deal with the llsdrpc method | ||
50 | * call overhead, and keep track of what to call during the next call | ||
51 | * into <code>process</code>. If you use this as a base class, you | ||
52 | * need to implement <code>response</code>, <code>fault</code>, and | ||
53 | * <code>error</code> to do something useful. When in those methods, | ||
54 | * you can parse and utilize the mReturnValue member data. | ||
55 | */ | ||
56 | class LLSDRPCResponse : public LLIOPipe | ||
57 | { | ||
58 | public: | ||
59 | LLSDRPCResponse(); | ||
60 | virtual ~LLSDRPCResponse(); | ||
61 | |||
62 | /** | ||
63 | * @brief This method extracts the response out of the sd passed in | ||
64 | * | ||
65 | * Any appropriate data found in the sd passed in will be | ||
66 | * extracted and managed by this object - not copied or cloned. It | ||
67 | * will still be up to the caller to delete the pointer passed in. | ||
68 | * @param sd The raw structured data response from the remote server. | ||
69 | * @return Returns true if this was able to parse the structured data. | ||
70 | */ | ||
71 | bool extractResponse(const LLSD& sd); | ||
72 | |||
73 | protected: | ||
74 | /** | ||
75 | * @brief Method called when the response is ready. | ||
76 | */ | ||
77 | virtual bool response(LLPumpIO* pump) = 0; | ||
78 | |||
79 | /** | ||
80 | * @brief Method called when a fault is generated by the remote server. | ||
81 | */ | ||
82 | virtual bool fault(LLPumpIO* pump) = 0; | ||
83 | |||
84 | /** | ||
85 | * @brief Method called when there was an error | ||
86 | */ | ||
87 | virtual bool error(LLPumpIO* pump) = 0; | ||
88 | |||
89 | protected: | ||
90 | /* @name LLIOPipe virtual implementations | ||
91 | */ | ||
92 | //@{ | ||
93 | /** | ||
94 | * @brief Process the data in buffer | ||
95 | */ | ||
96 | virtual EStatus process_impl( | ||
97 | const LLChannelDescriptors& channels, | ||
98 | buffer_ptr_t& buffer, | ||
99 | bool& eos, | ||
100 | LLSD& context, | ||
101 | LLPumpIO* pump); | ||
102 | //@} | ||
103 | |||
104 | protected: | ||
105 | LLSD mReturnValue; | ||
106 | bool mIsError; | ||
107 | bool mIsFault; | ||
108 | }; | ||
109 | |||
110 | /** | ||
111 | * @class LLSDRPCClient | ||
112 | * @brief Client class for a structured data remote procedure call. | ||
113 | * | ||
114 | * This class helps deal with making structured data calls to a remote | ||
115 | * server. You can visualize the calls as: | ||
116 | * <code> | ||
117 | * response = uri.method(parameter) | ||
118 | * </code> | ||
119 | * where you pass in everything to <code>call</code> and this class | ||
120 | * takes care of the rest of the details. | ||
121 | * In typical usage, you will derive a class from this class and | ||
122 | * provide an API more useful for the specific application at | ||
123 | * hand. For example, if you were writing a service to send an instant | ||
124 | * message, you could create an API for it to send the messsage, and | ||
125 | * that class would do the work of translating it into the method and | ||
126 | * parameter, find the destination, and invoke <code>call</call> with | ||
127 | * a useful implementation of LLSDRPCResponse passed in to handle the | ||
128 | * response from the network. | ||
129 | */ | ||
130 | class LLSDRPCClient : public LLIOPipe | ||
131 | { | ||
132 | public: | ||
133 | LLSDRPCClient(); | ||
134 | virtual ~LLSDRPCClient(); | ||
135 | |||
136 | /** | ||
137 | * @brief Enumeration for tracking which queue to process the | ||
138 | * response. | ||
139 | */ | ||
140 | enum EPassBackQueue | ||
141 | { | ||
142 | EPBQ_PROCESS, | ||
143 | EPBQ_CALLBACK, | ||
144 | }; | ||
145 | |||
146 | /** | ||
147 | * @brief Call a method on a remote LLSDRPCServer | ||
148 | * | ||
149 | * @param uri The remote object to call, eg, | ||
150 | * http://localhost/usher. If you are using a factory with a fixed | ||
151 | * url, the uri passed in will probably be ignored. | ||
152 | * @param method The method to call on the remote object | ||
153 | * @param parameter The parameter to pass into the remote | ||
154 | * object. It is up to the caller to delete the value passed in. | ||
155 | * @param response The object which gets the response. | ||
156 | * @param queue Specifies to call the response on the process or | ||
157 | * callback queue. | ||
158 | * @return Returns true if this object will be able to make the RPC call. | ||
159 | */ | ||
160 | bool call( | ||
161 | const std::string& uri, | ||
162 | const std::string& method, | ||
163 | const LLSD& parameter, | ||
164 | LLSDRPCResponse* response, | ||
165 | EPassBackQueue queue); | ||
166 | |||
167 | /** | ||
168 | * @brief Call a method on a remote LLSDRPCServer | ||
169 | * | ||
170 | * @param uri The remote object to call, eg, | ||
171 | * http://localhost/usher. If you are using a factory with a fixed | ||
172 | * url, the uri passed in will probably be ignored. | ||
173 | * @param method The method to call on the remote object | ||
174 | * @param parameter The seriailized parameter to pass into the | ||
175 | * remote object. | ||
176 | * @param response The object which gets the response. | ||
177 | * @param queue Specifies to call the response on the process or | ||
178 | * callback queue. | ||
179 | * @return Returns true if this object will be able to make the RPC call. | ||
180 | */ | ||
181 | bool call( | ||
182 | const std::string& uri, | ||
183 | const std::string& method, | ||
184 | const std::string& parameter, | ||
185 | LLSDRPCResponse* response, | ||
186 | EPassBackQueue queue); | ||
187 | |||
188 | protected: | ||
189 | /** | ||
190 | * @brief Enumeration for tracking client state. | ||
191 | */ | ||
192 | enum EState | ||
193 | { | ||
194 | STATE_NONE, | ||
195 | STATE_READY, | ||
196 | STATE_WAITING_FOR_RESPONSE, | ||
197 | STATE_DONE | ||
198 | }; | ||
199 | |||
200 | /* @name LLIOPipe virtual implementations | ||
201 | */ | ||
202 | //@{ | ||
203 | /** | ||
204 | * @brief Process the data in buffer | ||
205 | */ | ||
206 | virtual EStatus process_impl( | ||
207 | const LLChannelDescriptors& channels, | ||
208 | buffer_ptr_t& buffer, | ||
209 | bool& eos, | ||
210 | LLSD& context, | ||
211 | LLPumpIO* pump); | ||
212 | //@} | ||
213 | |||
214 | protected: | ||
215 | EState mState; | ||
216 | std::string mURI; | ||
217 | std::string mRequest; | ||
218 | EPassBackQueue mQueue; | ||
219 | LLIOPipe::ptr_t mResponse; | ||
220 | }; | ||
221 | |||
222 | /** | ||
223 | * @class LLSDRPCClientFactory | ||
224 | * @brief Basic implementation for making an SD RPC client factory | ||
225 | * | ||
226 | * This class eases construction of a basic sd rpc client. Here is an | ||
227 | * example of it's use: | ||
228 | * <code> | ||
229 | * class LLUsefulService : public LLService { ... } | ||
230 | * LLService::registerCreator( | ||
231 | * "useful", | ||
232 | * LLService::creator_t(new LLSDRPCClientFactory<LLUsefulService>)) | ||
233 | * </code> | ||
234 | */ | ||
235 | template<class Client> | ||
236 | class LLSDRPCClientFactory : public LLChainIOFactory | ||
237 | { | ||
238 | public: | ||
239 | LLSDRPCClientFactory() {} | ||
240 | LLSDRPCClientFactory(const std::string& fixed_url) : mURL(fixed_url) {} | ||
241 | virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const | ||
242 | { | ||
243 | lldebugs << "LLSDRPCClientFactory::build" << llendl; | ||
244 | LLIOPipe::ptr_t service(new Client); | ||
245 | chain.push_back(service); | ||
246 | LLURLRequest* http(new LLURLRequest(LLURLRequest::HTTP_POST)); | ||
247 | LLIOPipe::ptr_t http_pipe(http); | ||
248 | http->addHeader("Content-Type: text/llsd"); | ||
249 | if(mURL.empty()) | ||
250 | { | ||
251 | chain.push_back(LLIOPipe::ptr_t(new LLContextURLExtractor(http))); | ||
252 | } | ||
253 | else | ||
254 | { | ||
255 | http->setURL(mURL); | ||
256 | } | ||
257 | chain.push_back(http_pipe); | ||
258 | chain.push_back(service); | ||
259 | return true; | ||
260 | } | ||
261 | protected: | ||
262 | std::string mURL; | ||
263 | }; | ||
264 | |||
265 | /** | ||
266 | * @class LLXMLSDRPCClientFactory | ||
267 | * @brief Basic implementation for making an XMLRPC to SD RPC client factory | ||
268 | * | ||
269 | * This class eases construction of a basic sd rpc client which uses | ||
270 | * xmlrpc as a serialization grammar. Here is an example of it's use: | ||
271 | * <code> | ||
272 | * class LLUsefulService : public LLService { ... } | ||
273 | * LLService::registerCreator( | ||
274 | * "useful", | ||
275 | * LLService::creator_t(new LLXMLSDRPCClientFactory<LLUsefulService>)) | ||
276 | * </code> | ||
277 | */ | ||
278 | template<class Client> | ||
279 | class LLXMLSDRPCClientFactory : public LLChainIOFactory | ||
280 | { | ||
281 | public: | ||
282 | LLXMLSDRPCClientFactory() {} | ||
283 | LLXMLSDRPCClientFactory(const std::string& fixed_url) : mURL(fixed_url) {} | ||
284 | virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const | ||
285 | { | ||
286 | lldebugs << "LLXMLSDRPCClientFactory::build" << llendl; | ||
287 | LLIOPipe::ptr_t service(new Client); | ||
288 | chain.push_back(service); | ||
289 | LLURLRequest* http(new LLURLRequest(LLURLRequest::HTTP_POST)); | ||
290 | LLIOPipe::ptr_t http_pipe(http); | ||
291 | http->addHeader("Content-Type: text/xml"); | ||
292 | if(mURL.empty()) | ||
293 | { | ||
294 | chain.push_back(LLIOPipe::ptr_t(new LLContextURLExtractor(http))); | ||
295 | } | ||
296 | else | ||
297 | { | ||
298 | http->setURL(mURL); | ||
299 | } | ||
300 | chain.push_back(LLIOPipe::ptr_t(new LLFilterSD2XMLRPCRequest(NULL))); | ||
301 | chain.push_back(http_pipe); | ||
302 | chain.push_back(LLIOPipe::ptr_t(new LLFilterXMLRPCResponse2LLSD)); | ||
303 | chain.push_back(service); | ||
304 | return true; | ||
305 | } | ||
306 | protected: | ||
307 | std::string mURL; | ||
308 | }; | ||
309 | |||
310 | #endif // LL_LLSDRPCCLIENT_H | ||