37 MethodMap::iterator i =
_methods.find( methodName );
43 MethodMap::const_iterator i =
_methods.find( name );
66 "XmlRpcServer::bindAndListen: Could not set socket to non-blocking input mode (%s).",
76 "XmlRpcServer::bindAndListen: Could not set SO_REUSEADDR socket option (%s).",
85 XmlRpcUtil::error(
"XmlRpcServer::bindAndListen: Could not bind to specified port (%s).",
95 "XmlRpcServer::bindAndListen: Could not set socket in listening mode (%s).",
100 XmlRpcUtil::log( 2,
"XmlRpcServer::bindAndListen: server listening on port %d fd %d", port,
112 _disp.work( msTime );
130 XmlRpcUtil::error(
"XmlRpcServer::acceptConnection: Could not accept connection (%s).",
136 XmlRpcUtil::error(
"XmlRpcServer::acceptConnection: Could not set socket to non-blocking "
142 XmlRpcUtil::log( 2,
"XmlRpcServer::acceptConnection: creating a connection" );
165static const std::string LIST_METHODS(
"system.listMethods" );
166static const std::string METHOD_HELP(
"system.methodHelp" );
167static const std::string MULTICALL(
"system.multicall" );
177 return std::string(
"List all methods available on a server as an array of strings" );
191 if ( !m )
throw XmlRpcException( METHOD_HELP +
": Unknown method name" );
196 std::string
help() {
return std::string(
"Retrieve the help string for a named method" ); }
228 for ( MethodMap::iterator it =
_methods.begin(); it !=
_methods.end(); ++it )
229 result[i++] = it->first;
232 result[i] = MULTICALL;
void execute(XmlRpcValue ¶ms, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
ListMethods(XmlRpcServer *s)
MethodHelp(XmlRpcServer *s)
void execute(XmlRpcValue ¶ms, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
@ ReadableEvent
data available to read
A class to handle XML RPC requests from a particular client.
Abstract class representing a single RPC method.
virtual std::string help()
std::string & name()
Returns the name of the method.
XmlRpcServerMethod(std::string const &name, XmlRpcServer *server=0)
Constructor.
A class to handle XML RPC requests.
void shutdown()
Close all connections with clients and the socket file descriptor.
XmlRpcServerMethod * _listMethods
bool bindAndListen(int port, int backlog=5)
void enableIntrospection(bool enabled=true)
Specify whether introspection is enabled or not. Default is not enabled.
XmlRpcServer()
Create a server object.
void removeMethod(XmlRpcServerMethod *method)
Remove a command from the RPC server.
virtual void removeConnection(XmlRpcServerConnection *)
Remove a connection from the dispatcher.
virtual XmlRpcServerConnection * createConnection(int socket)
Create a new connection object for processing requests from a specific client.
XmlRpcServerMethod * _methodHelp
virtual unsigned handleEvent(unsigned eventType)
Handle client connection requests.
bool _introspectionEnabled
void addMethod(XmlRpcServerMethod *method)
Add a command to the RPC server.
XmlRpcServerMethod * findMethod(const std::string &name) const
Look up a method by name.
void work(double msTime)
Process client requests for the specified time.
virtual ~XmlRpcServer()
Destructor.
virtual void acceptConnection()
Accept a client connection request.
void listMethods(XmlRpcValue &result)
Introspection support.
void exit()
Temporarily stop processing client requests and exit the work() method.
static int socket()
Creates a stream (TCP) socket. Returns -1 on failure.
static bool listen(int socket, int backlog)
Set socket in listen mode.
static int accept(int socket)
Accept a client connection request.
static bool setReuseAddr(int socket)
static bool setNonBlocking(int socket)
Sets a stream (TCP) socket to perform non-blocking IO. Returns false on failure.
static void close(int socket)
Closes a socket.
static bool bind(int socket, int port)
Bind to a specified port.
static std::string getErrorMsg()
Returns message corresponding to last error.
int getfd() const
Return the file descriptor being monitored.
void setfd(int fd)
Specify the file descriptor to monitor.
static void error(const char *fmt,...)
Dump error messages somewhere.
static void log(int level, const char *fmt,...)
Dump messages somewhere.
RPC method arguments and results are represented by Values.
void setSize(int size)
Specify the size for array values. Array values will grow beyond this size if needed.