• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #ifndef _XMLRPCSERVER_H_
3 #define _XMLRPCSERVER_H_
4 //
5 // XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
6 //
7 #if defined(_MSC_VER)
8 # pragma warning(disable:4786)    // identifier was truncated in debug info
9 #endif
10 
11 #ifndef MAKEDEPEND
12 # include <map>
13 # include <string>
14 #endif
15 
16 #include "XmlRpcDispatch.h"
17 #include "XmlRpcSource.h"
18 
19 namespace XmlRpc {
20 
21 
22   // An abstract class supporting XML RPC methods
23   class XmlRpcServerMethod;
24 
25   // Class representing connections to specific clients
26   class XmlRpcServerConnection;
27 
28   // Class representing argument and result values
29   class XmlRpcValue;
30 
31 
32   //! A class to handle XML RPC requests
33   class XmlRpcServer : public XmlRpcSource {
34   public:
35     //! Create a server object.
36     XmlRpcServer();
37     //! Destructor.
38     virtual ~XmlRpcServer();
39 
40     //! Specify whether introspection is enabled or not. Default is not enabled.
41     void enableIntrospection(bool enabled=true);
42 
43     //! Add a command to the RPC server
44     void addMethod(XmlRpcServerMethod* method);
45 
46     //! Remove a command from the RPC server
47     void removeMethod(XmlRpcServerMethod* method);
48 
49     //! Remove a command from the RPC server by name
50     void removeMethod(const std::string& methodName);
51 
52     //! Look up a method by name
53     XmlRpcServerMethod* findMethod(const std::string& name) const;
54 
55     //! Create a socket, bind to the specified port, and
56     //! set it in listen mode to make it available for clients.
57     bool bindAndListen(int port, int backlog = 5);
58 
59     //! Process client requests for the specified time
60     void work(double msTime);
61 
62     //! Temporarily stop processing client requests and exit the work() method.
63     void exit();
64 
65     //! Close all connections with clients and the socket file descriptor
66     void shutdown();
67 
68     //! Introspection support
69     void listMethods(XmlRpcValue& result);
70 
71     // XmlRpcSource interface implementation
72 
73     //! Handle client connection requests
74     virtual unsigned handleEvent(unsigned eventType);
75 
76     //! Remove a connection from the dispatcher
77     virtual void removeConnection(XmlRpcServerConnection*);
78 
79   protected:
80 
81     //! Accept a client connection request
82     virtual void acceptConnection();
83 
84     //! Create a new connection object for processing requests from a specific client.
85     virtual XmlRpcServerConnection* createConnection(int socket);
86 
87     // Whether the introspection API is supported by this server
88     bool _introspectionEnabled;
89 
90     // Event dispatcher
91     XmlRpcDispatch _disp;
92 
93     // Collection of methods. This could be a set keyed on method name if we wanted...
94     typedef std::map< std::string, XmlRpcServerMethod* > MethodMap;
95     MethodMap _methods;
96 
97     // system methods
98     XmlRpcServerMethod* _listMethods;
99     XmlRpcServerMethod* _methodHelp;
100 
101   };
102 } // namespace XmlRpc
103 
104 #endif //_XMLRPCSERVER_H_
105