llsdrpcclient.h

Go to the documentation of this file.
00001 
00034 #ifndef LL_LLSDRPCCLIENT_H
00035 #define LL_LLSDRPCCLIENT_H
00036 
00042 #include "llchainio.h"
00043 #include "llfiltersd2xmlrpc.h"
00044 #include "lliopipe.h"
00045 #include "llurlrequest.h"
00046 
00060 class LLSDRPCResponse : public LLIOPipe
00061 {
00062 public:
00063         LLSDRPCResponse();
00064         virtual ~LLSDRPCResponse();
00065 
00075         bool extractResponse(const LLSD& sd);
00076 
00077 protected:
00081         virtual bool response(LLPumpIO* pump) = 0;
00082 
00086         virtual bool fault(LLPumpIO* pump) = 0;
00087 
00091         virtual bool error(LLPumpIO* pump) = 0;
00092 
00093 protected:
00094         /* @name LLIOPipe virtual implementations
00095          */
00097 
00100         virtual EStatus process_impl(
00101                 const LLChannelDescriptors& channels,
00102                 buffer_ptr_t& buffer,
00103                 bool& eos,
00104                 LLSD& context,
00105                 LLPumpIO* pump);
00107         
00108 protected:
00109         LLSD mReturnValue;
00110         bool mIsError;
00111         bool mIsFault;
00112 };
00113 
00134 class LLSDRPCClient : public LLIOPipe
00135 {
00136 public:
00137         LLSDRPCClient();
00138         virtual ~LLSDRPCClient();
00139 
00144         enum EPassBackQueue
00145         {
00146                 EPBQ_PROCESS,
00147                 EPBQ_CALLBACK,
00148         };
00149 
00164         bool call(
00165                 const std::string& uri,
00166                 const std::string& method,
00167                 const LLSD& parameter,
00168                 LLSDRPCResponse* response,
00169                 EPassBackQueue queue);
00170 
00185         bool call(
00186                 const std::string& uri,
00187                 const std::string& method,
00188                 const std::string& parameter,
00189                 LLSDRPCResponse* response,
00190                 EPassBackQueue queue);
00191 
00192 protected:
00196         enum EState
00197         {
00198                 STATE_NONE,
00199                 STATE_READY,
00200                 STATE_WAITING_FOR_RESPONSE,
00201                 STATE_DONE
00202         };
00203         
00204         /* @name LLIOPipe virtual implementations
00205          */
00207 
00210         virtual EStatus process_impl(
00211                 const LLChannelDescriptors& channels,
00212                 buffer_ptr_t& buffer,
00213                 bool& eos,
00214                 LLSD& context,
00215                 LLPumpIO* pump);
00217 
00218 protected:
00219         EState mState;
00220         std::string mURI;
00221         std::string mRequest;
00222         EPassBackQueue mQueue;
00223         LLIOPipe::ptr_t mResponse;
00224 };
00225 
00239 template<class Client>
00240 class LLSDRPCClientFactory : public LLChainIOFactory
00241 {
00242 public:
00243         LLSDRPCClientFactory() {}
00244         LLSDRPCClientFactory(const std::string& fixed_url) : mURL(fixed_url) {}
00245         virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const
00246         {
00247                 lldebugs << "LLSDRPCClientFactory::build" << llendl;
00248                 LLIOPipe::ptr_t service(new Client);
00249                 chain.push_back(service);
00250                 LLURLRequest* http(new LLURLRequest(LLURLRequest::HTTP_POST));
00251                 LLIOPipe::ptr_t http_pipe(http);
00252                 http->addHeader("Content-Type: text/llsd");
00253                 if(mURL.empty())
00254                 {
00255                         chain.push_back(LLIOPipe::ptr_t(new LLContextURLExtractor(http)));
00256                 }
00257                 else
00258                 {
00259                         http->setURL(mURL);
00260                 }
00261                 chain.push_back(http_pipe);
00262                 chain.push_back(service);
00263                 return true;
00264         }
00265 protected:
00266         std::string mURL;
00267 };
00268 
00282 template<class Client>
00283 class LLXMLSDRPCClientFactory : public LLChainIOFactory
00284 {
00285 public:
00286         LLXMLSDRPCClientFactory() {}
00287         LLXMLSDRPCClientFactory(const std::string& fixed_url) : mURL(fixed_url) {}
00288         virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const
00289         {
00290                 lldebugs << "LLXMLSDRPCClientFactory::build" << llendl;
00291                 LLIOPipe::ptr_t service(new Client);
00292                 chain.push_back(service);
00293                 LLURLRequest* http(new LLURLRequest(LLURLRequest::HTTP_POST));
00294                 LLIOPipe::ptr_t http_pipe(http);
00295                 http->addHeader("Content-Type: text/xml");
00296                 if(mURL.empty())
00297                 {
00298                         chain.push_back(LLIOPipe::ptr_t(new LLContextURLExtractor(http)));
00299                 }
00300                 else
00301                 {
00302                         http->setURL(mURL);
00303                 }
00304                 chain.push_back(LLIOPipe::ptr_t(new LLFilterSD2XMLRPCRequest(NULL)));
00305                 chain.push_back(http_pipe);
00306                 chain.push_back(LLIOPipe::ptr_t(new LLFilterXMLRPCResponse2LLSD));
00307                 chain.push_back(service);
00308                 return true;
00309         }
00310 protected:
00311         std::string mURL;
00312 };
00313 
00314 #endif // LL_LLSDRPCCLIENT_H

Generated on Thu Jul 1 06:09:08 2010 for Second Life Viewer by  doxygen 1.4.7