XmlRpcServer.h

Go to the documentation of this file.
00001 
00002 #ifndef _XMLRPCSERVER_H_
00003 #define _XMLRPCSERVER_H_
00004 //
00005 // XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
00006 //
00007 
00013 #if defined(_MSC_VER)
00014 # pragma warning(disable:4786)    // identifier was truncated in debug info
00015 #endif
00016 
00017 #ifndef MAKEDEPEND
00018 # include <map>
00019 # include <string>
00020 #include <cstdio>
00021 #endif
00022 
00023 #include "XmlRpcDispatch.h"
00024 #include "XmlRpcSource.h"
00025 
00026 namespace XmlRpc {
00027 
00028 
00029   // An abstract class supporting XML RPC methods
00030   class XmlRpcServerMethod;
00031 
00032   // Class representing connections to specific clients
00033   class XmlRpcServerConnection;
00034 
00035   // Class representing argument and result values
00036   class XmlRpcValue;
00037 
00038 
00040   class XmlRpcServer : public XmlRpcSource {
00041   public:
00043     XmlRpcServer();
00045     virtual ~XmlRpcServer();
00046 
00048     void enableIntrospection(bool enabled=true);
00049 
00051     void addMethod(XmlRpcServerMethod* method);
00052 
00054     void removeMethod(XmlRpcServerMethod* method);
00055 
00057     void removeMethod(const std::string& methodName);
00058 
00060     XmlRpcServerMethod* findMethod(const std::string& name) const;
00061 
00066     bool bindAndListen(int port, int backlog = 5);
00067 
00069     int getPort(void) const;
00070 
00072     void work(double msTime);
00073 
00075     void exit();
00076 
00078     void shutdown();
00079 
00081     void listMethods(XmlRpcValue& result);
00082 
00083 
00086     virtual std::string executeRequest(std::string const& request);
00087 
00088 
00089     // XmlRpcSource interface implementation
00090 
00092     virtual unsigned handleEvent(unsigned eventType);
00093 
00095     virtual void removeConnection(XmlRpcServerConnection*);
00096 
00097   protected:
00098 
00099     // Static data
00100     static const char METHODNAME_TAG[];
00101     static const char PARAMS_TAG[];
00102     static const char PARAMS_ETAG[];
00103     static const char PARAM_TAG[];
00104     static const char PARAM_ETAG[];
00105 
00106     static const std::string SYSTEM_MULTICALL;
00107     static const std::string METHODNAME;
00108     static const std::string PARAMS;
00109 
00110     static const std::string FAULTCODE;
00111     static const std::string FAULTSTRING;
00112 
00113 
00115     virtual void acceptConnection();
00116 
00119     virtual XmlRpcServerConnection* createConnection(int socket);
00120 
00122     virtual void dispatchConnection(XmlRpcServerConnection* sc);
00123 
00124 
00127     std::string parseRequest(std::string const& request, XmlRpcValue& params);
00128 
00130     bool executeMethod(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result);
00131 
00134     bool executeMulticall(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result);
00135 
00137     std::string generateResponse(std::string const& resultXml);
00138 
00140     std::string generateFaultResponse(std::string const& msg, int errorCode = -1);
00141 
00143     std::string generateHeader(std::string const& body);
00144 
00145 
00146     
00148     bool _introspectionEnabled;
00149 
00151     XmlRpcDispatch _disp;
00152 
00154     typedef std::map< std::string, XmlRpcServerMethod* > MethodMap;
00155 
00157     MethodMap _methods;
00158 
00160     XmlRpcServerMethod* _listMethods;
00161 
00163     XmlRpcServerMethod* _methodHelp;
00164 
00165   };
00166 } // namespace XmlRpc
00167 
00168 #endif //_XMLRPCSERVER_H_
Generated on Wed May 26 16:21:15 2010 for OverSim by  doxygen 1.6.3