Files
qmp_client/lib/qmp_client.rb
Nick Thomas 51175ddf56 Initial, simple, unit-tested implementation of QMPClient.
This follows the README given earlier, at least in principle, but
doesn't implement the entirety of QMP, by any stretch of the
imagination.

Notable by their absence are error responses, argument validation
(for incoming and outgoing messsages of all types), and any visibility
into qmp_capabilities.

Also missing are integration tests.
2011-11-13 18:36:51 +00:00

35 lines
920 B
Ruby

require 'socket'
require 'qmp_client/api'
require 'qmp_client/connectors'
require 'qmp_client/messages'
# This library provides an interface to QEMU's QMP server, allowing you to
# manage and query running virtual machines.
#
# @author Nick Thomas <nick@lupine.me.uk>
module QMPClient
def self.connect_unix(filename, &blk)
sock = UNIXSocket.connect(filename)
connect_socket(sock, &blk)
ensure
sock.close if sock && !sock.closed?
end
def self.connect_tcp(host, port, local_host=nil, local_port=nil, &blk)
sock = TCPSocket.connect(host, port, local_host, local_port)
connect_socket(sock, &blk)
ensure
sock.close if sock && !sock.closed?
end
def self.connect_socket(read_socket, write_socket = nil, &blk)
conn = Connectors::Socket.new(QMPClient::Messages, QMPClient::Messages)
conn.run(read_socket, write_socket) do |rq, wq|
API.run(rq, wq, &blk)
end
end
end