Skip to content

Commit

Permalink
Fixed "undefined method `get_node' for nil:NilClass" on Ubuntu Karmic…
Browse files Browse the repository at this point in the history
… (Ticket#34).

Always initialize Connection#@service, because we can get an unexpected
method call (usually Introspect). indicator-messages in Ubuntu will do
that.
Here we initialize the name to the :1.42 unique name that Hello returns.

Also MatchRule#from_s did not work at all, fixed.
  • Loading branch information
mvidner committed Mar 28, 2010
1 parent 28c5464 commit 7422334
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/dbus/bus.rb
Expand Up @@ -353,7 +353,7 @@ def introspect_data(dest, path)
if rmsg.is_a?(Error)
raise rmsg
else
return rmsg.params[0]
return rmsg.params[0] # return value of introspect_data
end
end
else
Expand Down Expand Up @@ -610,6 +610,7 @@ def send_hello
@unique_name = rmsg.destination
puts "Got hello reply. Our unique_name is #{@unique_name}" if $DEBUG
end
@service = Service.new(@unique_name, self)
end

# Parse the session string (socket address).
Expand Down
9 changes: 5 additions & 4 deletions lib/dbus/matchrule.rb
Expand Up @@ -39,7 +39,7 @@ def initialize
# Possible message types are: signal, method_call, method_return, and error.
def type=(t)
if not ['signal', 'method_call', 'method_return', 'error'].member?(t)
raise MatchRuleException
raise MatchRuleException, t
end
@type = t
end
Expand All @@ -56,18 +56,19 @@ def to_s

# Parses a match rule string _s_ and sets the filters on the object.
def from_s(str)
s.split(",").each do |eq|
str.split(",").each do |eq|
if eq =~ /^(.*)='([^']*)'$/
# "
name = $1
val = $1
val = $2
if FILTERS.member?(name.to_sym)
method(name + "=").call(val)
else
raise MatchRuleException
raise MatchRuleException, name
end
end
end
self
end

# Sets the match rule to filter for the given _signal_ and the
Expand Down
15 changes: 15 additions & 0 deletions test/service_newapi.rb
Expand Up @@ -77,6 +77,21 @@ class Test < DBus::Object
myobj = Test.new("/org/ruby/MyInstance")
service.export(myobj)

# introspect every other connection, Ticket #34
# (except the one that activates us - it has already emitted
# NOC by the time we run this. Therefore the test for #34 will not work
# by running t2.rb alone, one has to run t1 before it; 'rake' does it)
mr = DBus::MatchRule.new.from_s "type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged'"
bus.add_match(mr) do |msg|
new_unique_name = msg.params[2]
unless new_unique_name.empty?
# puts "RRRING #{new_unique_name}"
bus.introspect_data(new_unique_name, "/") do
# ignore the result
end
end
end

puts "listening"
main = DBus::Main.new
main << bus
Expand Down

0 comments on commit 7422334

Please sign in to comment.