Skip to content

Commit 9daa4bf

Browse files
committed
Merge branch 'autointrospect'
2 parents baa0ebc + 0fc1ae1 commit 9daa4bf

20 files changed

Lines changed: 60 additions & 45 deletions

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
## Unreleased
44

5+
Bug fixes:
6+
* It is no longer required to explicitly call ProxyObject#introspect,
7+
it will be done automatically once ([#28][]).
8+
59
Requirements:
610
* Introduced RuboCop to keep a consistent coding style.
711
* Replaced Gemfile.ci with a regular Gemfile.
812

13+
[#28]: http://github.com/mvidner/ruby-dbus/issue/28
14+
915
## Ruby D-Bus 0.12.0 - 2016-09-12
1016

1117
API:

doc/Reference.md

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,15 @@ is simply "dbus"
2323
#### Calling Methods
2424

2525
1. {DBus.session_bus Connect to the session bus};
26-
{DBus::Connection#[] get the screensaver service}
27-
{DBus::Service#[] and its screensaver object}.
28-
2. Perform {DBus::ProxyObject#introspect explicit introspection}
29-
to define the interfaces and methods
30-
on the {DBus::ProxyObject object proxy}
31-
([I#28](https://github.com/mvidner/ruby-dbus/issues/28)).
32-
3. Call one of its methods in a loop, solving [xkcd#196](http://xkcd.com/196).
26+
2. {DBus::Connection#[] get the screensaver service}
27+
3. {DBus::Service#[] and its screensaver object}.
28+
4. Call one of its methods in a loop, solving [xkcd#196](http://xkcd.com/196).
3329

3430
 
3531

3632
mybus = DBus.session_bus
3733
service = mybus["org.freedesktop.ScreenSaver"]
3834
object = service["/ScreenSaver"]
39-
object.introspect
4035
loop do
4136
object.SimulateUserActivity
4237
sleep 5 * 60
@@ -50,7 +45,6 @@ In this example SuspendAllowed returns a boolean:
5045
mybus = DBus.session_bus
5146
pm_s = mybus["org.freedesktop.PowerManagement"]
5247
pm_o = pm_s["/org/freedesktop/PowerManagement"]
53-
pm_o.introspect
5448
pm_i = pm_o["org.freedesktop.PowerManagement"]
5549

5650
if pm_i.CanSuspend
@@ -74,7 +68,6 @@ For nearly all methods you used `Method[0]` or
7468
pm_s = mybus["org.freedesktop.PowerManagement"]
7569
# use legacy compatibility API
7670
pm_o = pm_s.object["/org/freedesktop/PowerManagement"]
77-
pm_o.introspect
7871
pm_i = pm_o["org.freedesktop.PowerManagement"]
7972

8073
# wrong
@@ -97,7 +90,6 @@ an actual Hash of them.
9790
sysbus = DBus.system_bus
9891
upower_s = sysbus["org.freedesktop.UPower"]
9992
upower_o = upower_s["/org/freedesktop/UPower"]
100-
upower_o.introspect
10193
upower_i = upower_o["org.freedesktop.UPower"]
10294

10395
on_battery = upower_i["OnBattery"]
@@ -137,7 +129,6 @@ To receive signals for a specific object and interface, use
137129
sysbus = DBus.system_bus
138130
login_s = sysbus["org.freedesktop.login1"] # part of systemd
139131
login_o = login_s.object "/org/freedesktop/login1"
140-
login_o.introspect
141132
login_o.default_iface = "org.freedesktop.login1.Manager"
142133

143134
main = DBus::Main.new
@@ -148,7 +139,6 @@ To receive signals for a specific object and interface, use
148139
puts "New session: #{name}"
149140

150141
session_o = login_s.object(opath)
151-
session_o.introspect
152142
session_i = session_o["org.freedesktop.login1.Session"]
153143
uid, _user_opath = session_i["User"]
154144
puts "Its UID: #{uid}"
@@ -218,7 +208,6 @@ D-Bus calls can reply with an error instead of a return value. An error is
218208
translated to a Ruby exception, an instance of {DBus::Error}.
219209

220210
nm_o = DBus.system_bus["org.freedesktop.NetworkManager"]["/org/freedesktop/NetworkManager"]
221-
nm_o.introspect
222211
nm = nm_o["org.freedesktop.NetworkManager"]
223212
begin
224213
nm.Sleep(false)

examples/service/call_service.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
# Get the object from this service
1010
player = ruby_srv.object("/org/ruby/MyInstance")
1111

12-
# Introspect it
13-
puts player.introspect
1412
player.default_iface = "org.ruby.SampleInterface"
1513
player.test_variant(["s", "coucou"])
1614
player.on_signal("SomethingJustHappened") do |u, v|

examples/simple/call_introspect.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# Get the object from this service
1111
player = rhythmbox.object("/org/gnome/Rhythmbox/Player")
1212

13-
# Introspect it
14-
player.introspect
1513
if player.has_iface? "org.gnome.Rhythmbox.Player"
1614
puts "We have Rhythmbox Player interface"
1715
end

examples/simple/get_id.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# p driver_svc
1111
driver_obj = driver_svc["/"]
1212
# p driver_obj
13-
driver_obj.introspect
14-
1513
driver_ifc = driver_obj["org.freedesktop.DBus"]
1614
# p driver_ifc
1715

examples/simple/properties.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
bus = DBus::SystemBus.instance
55
nm_service = bus["org.freedesktop.NetworkManager"]
6-
network_manager_object = nm_service.object("/org/freedesktop/NetworkManager")
7-
network_manager_object.introspect
6+
network_manager_object = nm_service["/org/freedesktop/NetworkManager"]
87
nm_iface = network_manager_object["org.freedesktop.NetworkManager"]
98

109
# read a property

examples/utils/notify.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
end
1010

1111
d = DBus::SessionBus.instance
12-
o = d.service("org.freedesktop.Notifications").object("/org/freedesktop/Notifications")
13-
o.introspect
12+
o = d["org.freedesktop.Notifications"]["/org/freedesktop/Notifications"]
1413

1514
i = o["org.freedesktop.Notifications"]
1615

lib/dbus/proxy_object.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,31 @@ def initialize(bus, dest, path, api: ApiOptions::CURRENT)
3737
@bus = bus
3838
@destination = dest
3939
@path = path
40+
@introspected = false
4041
@interfaces = {}
4142
@subnodes = []
4243
@api = api
4344
end
4445

4546
# Returns the interfaces of the object.
4647
def interfaces
48+
introspect unless introspected
4749
@interfaces.keys
4850
end
4951

5052
# Retrieves an interface of the proxy object
5153
# @param [String] intfname
5254
# @return [ProxyObjectInterface]
5355
def [](intfname)
56+
introspect unless introspected
5457
@interfaces[intfname]
5558
end
5659

5760
# Maps the given interface name _intfname_ to the given interface _intf.
5861
# @param [String] intfname
5962
# @param [ProxyObjectInterface] intf
6063
# @return [ProxyObjectInterface]
64+
# @api private
6165
def []=(intfname, intf)
6266
@interfaces[intfname] = intf
6367
end
@@ -98,7 +102,7 @@ def define_shortcut_methods
98102
# creates a shortcut function that forwards each call to the method on
99103
# the appropriate intf
100104
singleton_class.class_eval do
101-
define_method name do |*args, &reply_handler|
105+
redefine_method name do |*args, &reply_handler|
102106
intf.method(name).call(*args, &reply_handler)
103107
end
104108
end
@@ -107,8 +111,8 @@ def define_shortcut_methods
107111

108112
# Returns whether the object has an interface with the given _name_.
109113
def has_iface?(name)
110-
raise "Cannot call has_iface? if not introspected" if !@introspected
111-
@interfaces.member?(name)
114+
introspect unless introspected
115+
@interfaces.key?(name)
112116
end
113117

114118
# Registers a handler, the code block, for a signal with the given _name_.

spec/async_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
@bus = DBus::ASessionBus.new
99
@svc = @bus.service("org.ruby.service")
1010
@obj = @svc.object "/org/ruby/MyInstance"
11-
@obj.introspect
1211
@obj.default_iface = "org.ruby.SampleInterface"
1312
end
1413

spec/binding_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
@bus = DBus::ASessionBus.new
1010
@svc = @bus.service("org.ruby.service")
1111
@base = @svc.object "/org/ruby/MyInstance"
12-
@base.introspect
1312
@base.default_iface = "org.ruby.SampleInterface"
1413
end
1514

1615
# https://trac.luon.net/ruby-dbus/ticket/36#comment:3
1716
it "tests class inheritance" do
1817
derived = @svc.object "/org/ruby/MyDerivedInstance"
19-
derived.introspect
2018

2119
# it should inherit from the parent
2220
expect(derived["org.ruby.SampleInterface"]).not_to be_nil
@@ -26,7 +24,6 @@
2624
# Interfaces and methods/signals appeared on all classes
2725
it "tests separation of classes" do
2826
test2 = @svc.object "/org/ruby/MyInstance2"
29-
test2.introspect
3027

3128
# it should have its own interface
3229
expect(test2["org.ruby.Test2"]).not_to be_nil

0 commit comments

Comments
 (0)