Skip to content

Instantly share code, notes, and snippets.

@mvidner
Last active November 20, 2015 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvidner/ba5f61da200a286ae435 to your computer and use it in GitHub Desktop.
Save mvidner/ba5f61da200a286ae435 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# https://lists.luon.net/pipermail/ruby-dbus-devel/2015-November/000500.html
require 'dbus'
def dbus_get_service_prefix path
bus = DBus::SystemBus.instance
service = bus.service path.join('.')
service.introspect # othewise cannot walk dbus namespace
root = service.root
prefix = root
path.each{|e|
prefix = prefix[e]
}
[service,prefix]
end
service_path = %w(org bluez)
iface = (service_path.clone << 'Media1').join '.'
service, prefix = dbus_get_service_prefix service_path
interfaces = Hash.new
# this is where interfaces seem to be visible. not sure if there is specification for this
prefix.keys.each{|i|
interfaces[i] = service.object ("/" + (service_path.clone << i).join('/'))
interfaces[i].default_iface = iface
}
class Endpoint < DBus::Object
# This is the whole MediaEndpoint interface. I did not find an
# example
# that specifies return value but it should be obvious either
# way
dbus_interface "org.bluez.MediaEndpoint1" do
dbus_method :SetConfiguration, "in transport:o, in props:d" do |transport, props|
p :SetConfiguration, transport, props
nil
end
dbus_method :SelectConfiguration, "in caps:au" do |caps|
p :SelectConfiguration, caps
caps
end
dbus_method :ClearConfiguration, "in transport:o" do |transport|
p :ClearConfiguration, transport
nil
end
dbus_method :Release do
p :Release
nil
end
end
end
interfaces.each{|k,i|
p k, i.class
e = Endpoint.new "/testenkrumppel/#{k}"
r = i.RegisterEndpoint e.path, {
'UUID' => '0000110A-0000-1000-8000-00805F9B34FB',
'Codec' => DBus.variant("y", 0)
}
p r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment