Fix the Greeting message - package is an attribute of version, not QMP.

At this stage, we can connect to a QEMU server and issue commands and queries.
This commit is contained in:
Nick Thomas
2011-11-13 19:50:13 +00:00
parent ce41993a1b
commit d96239dd65
2 changed files with 14 additions and 20 deletions

View File

@@ -3,40 +3,34 @@ require 'qmp_client/messages/message'
module QMPClient module QMPClient
module Messages module Messages
class Greeting < Message class Greeting < Message
attr_reader :qmp_version attr_reader :version
attr_reader :qmp_package
attr_reader :capabilities attr_reader :capabilities
def self.represents?(hsh) def self.represents?(hsh)
super(hsh) && hsh['QMP'].is_a?(Hash) && super(hsh) && hsh['QMP'].is_a?(Hash) &&
hsh['QMP']['version'].is_a?(Hash) && hsh['QMP']['version'].is_a?(Hash) &&
hsh['QMP']['package'].is_a?(String) && hsh['QMP']['capabilities'].is_a?(Array)
hsh['capabilities'].is_a?(Array)
end end
# build an event from a Hash # build an event from a Hash
def self.build(hsh) def self.build(hsh)
new(hsh['QMP']['version'], hsh['QMP']['package'], hsh['capabilities']) new(hsh['QMP']['version'], hsh['QMP']['package'], hsh['QMP']['capabilities'])
end end
def ==(other) def ==(other)
other.is_a?(Greeting) && other.qmp_version == self.qmp_version && other.is_a?(Greeting) && other.version == self.version &&
other.qmp_package == self.qmp_package &&
other.capabilities == self.capabilities other.capabilities == self.capabilities
end end
def initialize(qmp_version, qmp_package, capabilities) def initialize(version, package, capabilities)
@qmp_version = qmp_version @version = version
@qmp_package = qmp_package @package = package
@capabilities = capabilities @capabilities = capabilities
end end
def to_hash def to_hash
{ { 'QMP' => { 'version' => version, 'capabilities' => capabilities } }
'QMP' => {'version' => qmp_version, 'package' => qmp_package},
'capabilities' => capabilities
}
end end
protected protected

View File

@@ -12,16 +12,16 @@ module TestQMPClient
COMMAND_TXT = COMMAND_HSH.to_json COMMAND_TXT = COMMAND_HSH.to_json
GREETING_MSG = Messages::Greeting.new( GREETING_MSG = Messages::Greeting.new(
{'qemu' => {'micro' => 50, 'minor' => 13, 'major' => 0}}, {'qemu' => {'micro' => 50, 'minor' => 13, 'major' => 0}, 'package' => ''},
"", [] "", []
) )
GREETING_HSH = { GREETING_HSH = { 'QMP' => {
'QMP' => { 'version' => {
'version' => {'qemu' => {'micro' => 50, 'minor' => 13, 'major' => 0}}, 'qemu' => {'micro' => 50, 'minor' => 13, 'major' => 0},
'package' => "", 'package' => ''
}, },
'capabilities' => [] 'capabilities' => []
} }}
GREETING_TXT = GREETING_HSH.to_json GREETING_TXT = GREETING_HSH.to_json
ETIME = Time.now ETIME = Time.now