llsdrpcserver.h

Go to the documentation of this file.
00001 
00034 #ifndef LL_LLSDRPCSERVER_H
00035 #define LL_LLSDRPCSERVER_H
00036 
00072 #include <map>
00073 #include "lliopipe.h"
00074 #include "lliohttpserver.h"
00075 #include "llfiltersd2xmlrpc.h"
00076 
00077 class LLSD;
00078 
00084 enum ESDRPCSStatus
00085 {
00086         // The call went ok, but the response is not yet ready. The
00087         // method will arrange for the clearLock() call to be made at
00088         // a later date, after which, once the chain is being pumped
00089         // again, deferredResponse() will be called to gather the result
00090         ESDRPCS_DEFERRED,
00091 
00092         // The LLSDRPCServer would like to handle the method on the
00093         // callback queue of the pump.
00094         ESDRPCS_CALLBACK,
00095 
00096         // The method call finished and generated output.
00097         ESDRPCS_DONE,
00098 
00099         // Method failed for some unspecified reason - you should avoid
00100         // this. A generic fault will be sent to the output.
00101         ESDRPCS_ERROR,
00102 
00103         ESDRPCS_COUNT,
00104 };
00105 
00111 class LLSDRPCMethodCallBase
00112 {
00113 public:
00114         LLSDRPCMethodCallBase() {}
00115         virtual ~LLSDRPCMethodCallBase() {}
00116 
00117         virtual ESDRPCSStatus call(
00118                 const LLSD& params,
00119                 const LLChannelDescriptors& channels,
00120                 LLBufferArray* response) = 0;
00121 protected:
00122 };
00123 
00128 template<class Server>
00129 class LLSDRPCMethodCall : public LLSDRPCMethodCallBase
00130 {
00131 public:
00132         typedef ESDRPCSStatus (Server::*mem_fn)(
00133                 const LLSD& params,
00134                 const LLChannelDescriptors& channels,
00135                 LLBufferArray* data);
00136         LLSDRPCMethodCall(Server* s, mem_fn fn) :
00137                 mServer(s),
00138                 mMemFn(fn)
00139         {
00140         }
00141         virtual ~LLSDRPCMethodCall() {}
00142         virtual ESDRPCSStatus call(
00143                 const LLSD& params,
00144                 const LLChannelDescriptors& channels,
00145                 LLBufferArray* data)
00146         {
00147                 return (*mServer.*mMemFn)(params, channels, data);
00148         }
00149 
00150 protected:
00151         Server* mServer;
00152         mem_fn mMemFn;
00153         //bool (Server::*mMemFn)(const LLSD& params, LLBufferArray& data);
00154 };
00155 
00156 
00168 class LLSDRPCServer : public LLIOPipe
00169 {
00170 public:
00171         LLSDRPCServer();
00172         virtual ~LLSDRPCServer();
00173 
00177         enum
00178         {
00179                 FAULT_BAD_REQUEST = 2000,
00180                 FAULT_NO_RESPONSE = 2001,
00181         };
00182 
00191         static void buildFault(
00192                 const LLChannelDescriptors& channels,
00193                 LLBufferArray* data,
00194                 S32 code,
00195                 const std::string& msg);
00196 
00204         static void buildResponse(
00205                 const LLChannelDescriptors& channels,
00206                 LLBufferArray* data,
00207                 const LLSD& response);
00208 
00209 protected:
00210         /* @name LLIOPipe virtual implementations
00211          */
00213 
00216         virtual EStatus process_impl(
00217                 const LLChannelDescriptors& channels,
00218                 buffer_ptr_t& buffer,
00219                 bool& eos,
00220                 LLSD& context,
00221                 LLPumpIO* pump);
00223 
00224 protected:
00225 
00229         enum EState
00230         {
00231                 STATE_NONE,
00232                 STATE_CALLBACK,
00233                 STATE_DEFERRED,
00234                 STATE_DONE
00235         };
00236 
00251         virtual ESDRPCSStatus callMethod(
00252                 const std::string& method,
00253                 const LLSD& params,
00254                 const LLChannelDescriptors& channels,
00255                 LLBufferArray* data);
00256 
00271         virtual ESDRPCSStatus callbackMethod(
00272                 const std::string& method,
00273                 const LLSD& params,
00274                 const LLChannelDescriptors& channels,
00275                 LLBufferArray* data);
00276 
00287         virtual ESDRPCSStatus deferredResponse(
00288                 const LLChannelDescriptors& channels,
00289                 LLBufferArray* data);
00290 
00291         // donovan put this public here 7/27/06
00292 public:
00296         void clearLock();
00297 
00298 protected:
00299         EState mState;
00300         LLSD mRequest;
00301         LLPumpIO* mPump;
00302         S32 mLock;
00303         typedef std::map<std::string, LLSDRPCMethodCallBase*> method_map_t;
00304         method_map_t mMethods;
00305         method_map_t mCallbackMethods;
00306 };
00307 
00324 
00325 template<class Server>
00326 class LLSDRPCServerFactory : public LLChainIOFactory
00327 {
00328 public:
00329         virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const
00330         {
00331                 lldebugs << "LLXMLSDRPCServerFactory::build" << llendl;
00332                 chain.push_back(LLIOPipe::ptr_t(new Server));
00333                 return true;
00334         }
00335 };
00336 
00337 template<class Server>
00338 class LLSDRPCNode : public LLHTTPNodeForFactory<
00339                                                                 LLSDRPCServerFactory<Server> >
00340 {
00341 };
00342 
00343 template<class Server>
00344 class LLXMLRPCServerFactory : public LLChainIOFactory
00345 {
00346 public:
00347         virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const
00348         {
00349                 lldebugs << "LLXMLSDRPCServerFactory::build" << llendl;
00350                 chain.push_back(LLIOPipe::ptr_t(new LLFilterXMLRPCRequest2LLSD));
00351                 chain.push_back(LLIOPipe::ptr_t(new Server));
00352                 chain.push_back(LLIOPipe::ptr_t(new LLFilterSD2XMLRPCResponse));
00353                 return true;
00354         }
00355 };
00356 
00357 template<class Server>
00358 class LLXMLRPCNode : public LLHTTPNodeForFactory<
00359                                                                 LLXMLRPCServerFactory<Server> >
00360 {
00361 };
00362 
00364 
00365 #endif // LL_LLSDRPCSERVER_H

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