16 "<methodCall><methodName>";
28 XmlRpcUtil::log( 1,
"XmlRpcClient new client: host %s, port %d.", host, port );
32 if ( uri )
_uri = uri;
49 _disp.removeSource(
this );
66 XmlRpcUtil::log( 1,
"XmlRpcClient::execute: method %s (_connectionState %d).", method,
92 XmlRpcUtil::log( 1,
"XmlRpcClient::execute: method %s completed.", method );
104 "Error in XmlRpcClient::handleEvent: could not connect to server (%s).",
142 _disp.removeSource(
this );
153 XmlRpcUtil::error(
"Error in XmlRpcClient::doConnect: Could not create socket (%s).",
166 "Error in XmlRpcClient::doConnect: Could not set socket to non-blocking IO mode (%s).",
174 XmlRpcUtil::error(
"Error in XmlRpcClient::doConnect: Could not connect to server (%s).",
189 if ( params.
valid() )
194 for (
int i = 0; i < params.
size(); ++i )
197 body += params[i].
toXml();
204 body += params.
toXml();
214 "XmlRpcClient::generateRequest: header is %d bytes, content-length is %d.",
215 header.length(), body.length() );
223 std::string header =
"POST " +
_uri +
227 header +=
"\r\nHost: ";
234 header +=
"Content-Type: text/xml\r\nContent-length: ";
236 sprintf( buff,
"%d\r\n\r\n", body.size() );
238 return header + buff;
278 XmlRpcUtil::log( 4,
"XmlRpcClient::readHeader: re-trying connection" );
286 "Error in XmlRpcClient::readHeader: error while reading header (%s) on fd %d.",
293 char* hp = (
char*)
_header.c_str();
298 for (
char* cp = hp; ( bp == 0 ) && ( cp <
ep ); ++cp )
300 if ( (
ep - cp > 16 ) && ( strncasecmp( cp,
"Content-length: ", 16 ) == 0 ) ) lp = cp + 16;
301 else if ( (
ep - cp > 4 ) && ( strncmp( cp,
"\r\n\r\n", 4 ) == 0 ) ) bp = cp + 4;
302 else if ( (
ep - cp > 2 ) && ( strncmp( cp,
"\n\n", 2 ) == 0 ) ) bp = cp + 2;
310 XmlRpcUtil::error(
"Error in XmlRpcClient::readHeader: EOF while reading header" );
320 XmlRpcUtil::error(
"Error XmlRpcClient::readHeader: No Content-length specified" );
328 "Error in XmlRpcClient::readHeader: Invalid Content-length specified (%d).",
358 XmlRpcUtil::error(
"Error in XmlRpcClient::readResponse: EOF while reading response" );
380 XmlRpcUtil::error(
"Error in XmlRpcClient::parseResponse: Invalid response - no "
381 "methodResponse. Response:\n%s",
395 "Error in XmlRpcClient::parseResponse: Invalid response value. Response:\n%s",
403 XmlRpcUtil::error(
"Error in XmlRpcClient::parseResponse: Invalid response - no param or "
404 "fault tag. Response:\n%s",
411 return result.
valid();
sprintf(cut, "kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_" "pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
static const char PARAM_ETAG[]
static const char PARAMS_ETAG[]
static const char REQUEST_END[]
XmlRpcClient(const char *host, int port, const char *uri=0)
bool execute(const char *method, XmlRpcValue const ¶ms, XmlRpcValue &result)
virtual std::string generateHeader(std::string const &body)
virtual void close()
Close the connection.
static const char REQUEST_END_METHODNAME[]
ClientConnectionState _connectionState
virtual bool parseResponse(XmlRpcValue &result)
static const char REQUEST_BEGIN[]
static const char PARAM_TAG[]
virtual bool setupConnection()
virtual bool writeRequest()
virtual bool readResponse()
virtual ~XmlRpcClient()
Destructor.
virtual bool readHeader()
static const char METHODRESPONSE_TAG[]
static const char FAULT_TAG[]
static const char PARAMS_TAG[]
virtual bool generateRequest(const char *method, XmlRpcValue const ¶ms)
virtual unsigned handleEvent(unsigned eventType)
@ ReadableEvent
data available to read
@ WritableEvent
connected/data can be written without blocking
static int socket()
Creates a stream (TCP) socket. Returns -1 on failure.
static bool nbWrite(int socket, std::string &s, int *bytesSoFar)
Write text to the specified socket. Returns false on error.
static bool connect(int socket, std::string &host, int port)
Connect a socket to a server (from a client).
static bool setNonBlocking(int socket)
Sets a stream (TCP) socket to perform non-blocking IO. Returns false on failure.
static bool nbRead(int socket, std::string &s, bool *eof)
Read text from the specified socket. Returns false on error.
static std::string getErrorMsg()
Returns message corresponding to last error.
int getfd() const
Return the file descriptor being monitored.
void setKeepOpen(bool b=true)
Specify whether the file descriptor should be kept open if it is no longer monitored.
bool getKeepOpen() const
Return whether the file descriptor should be kept open if it is no longer monitored.
void setfd(int fd)
Specify the file descriptor to monitor.
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)
static void error(const char *fmt,...)
Dump error messages somewhere.
static bool findTag(const char *tag, std::string const &xml, int *offset)
Returns true if the tag is found and updates offset to the char after the tag.
static void log(int level, const char *fmt,...)
Dump messages somewhere.
RPC method arguments and results are represented by Values.
int size() const
Return the size for string, base64, array, and struct values.
void clear()
Erase the current value.
bool fromXml(std::string const &valueXml, int *offset)
Decode xml. Destroys any existing value.
bool valid() const
Return true if the value has been set to something.
std::string toXml() const
Encode the Value in xml.
Type const & getType() const
Return the type of the value stored.
const char XMLRPC_VERSION[]
Version identifier.
ClearFlagOnExit(bool &flag)