Ejemplo n.º 1
0
function send($xmlrpc, $cmd)
{
    print "Send: " . $cmd->toString() . "\n";
    if (!$xmlrpc->query_arg($cmd->serialize())) {
        die(__LINE__ . ": Failed to send command: " . $xmlrpc->getErrorCode() . ": " . $xmlrpc->getErrorMessage() . "\n");
    }
    $respdata = $xmlrpc->getResponse();
    $resp = commandFactory::createFromBytes($respdata);
    if (!$resp) {
        die(__LINE__ . ": No response!\n");
    }
    print "Recv: " . $resp->toString() . "\n";
    return $resp;
}
Ejemplo n.º 2
0
 public function executeCommand($cmd, $ignoreError = false)
 {
     $this->log_debug("Sending command " . $cmd->toString());
     $data = $cmd->serialize();
     if (!$this->xmlrpc->query_arg($data)) {
         // Failed to send
         $this->log_error($this->xmlrpc->getErrorMessage(), BTG::ERR_CONNECTING);
         return NULL;
     }
     // Executed OK, check response
     $resp_data = $this->xmlrpc->getResponse();
     try {
         // Try to deserialize it
         $resp_cmd = commandFactory::createFromBytes($resp_data);
     } catch (BTGException $e) {
         // Failed to receive.
         $this->log_error("Failed to decode received command:" . $e->getMessage());
         $this->log_debug("BTGException on createFromBytes: " . $e->getTraceAsString());
         return NULL;
     }
     $this->log_debug("Received command: " . $resp_cmd->toString() . "\n");
     if (!$ignoreError && $resp_cmd instanceof errorCommand) {
         $this->log_error($resp_cmd->getMessage());
     }
     return $resp_cmd;
 }