Module: Kaede::DBus::Properties

Included in:
Program
Defined in:
lib/kaede/dbus/properties.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

PROPERTY_INTERFACE =
'org.freedesktop.DBus.Properties'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/kaede/dbus/properties.rb', line 6

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#get_properties(iface) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/kaede/dbus/properties.rb', line 75

def get_properties(iface)
  if sym = self.class.properties_method[iface]
    [send(sym)]
  else
    unknown_interface!
  end
end

#get_property(iface, prop) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/kaede/dbus/properties.rb', line 66

def get_property(iface, prop)
  props = get_properties(iface).first
  if props.has_key?(prop)
    [props[prop]]
  else
    raise_unknown_property!
  end
end

#raise_access_denied!Object



91
92
93
# File 'lib/kaede/dbus/properties.rb', line 91

def raise_access_denied!
  raise ::DBus.error('org.freedesktop.DBus.Error.AccessDenied')
end

#raise_unknown_interface!Object



83
84
85
# File 'lib/kaede/dbus/properties.rb', line 83

def raise_unknown_interface!
  raise ::DBus.error('org.freedesktop.DBus.Error.UnknownInterface')
end

#raise_unknown_property!Object



87
88
89
# File 'lib/kaede/dbus/properties.rb', line 87

def raise_unknown_property!
  raise ::DBus.error('org.freedesktop.DBus.Error.UnknownProperty')
end

#xml_for_dbus_properties(xml) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kaede/dbus/properties.rb', line 36

def xml_for_dbus_properties(xml)
  xml.interface(name: PROPERTY_INTERFACE) do
    xml.method_(name: 'GetAll') do
      xml.arg(name: 'interface', direction: 'in', type: 's')
      xml.arg(name: 'properties', direction: 'out', type: 'a{sv}')
    end

    helper = lambda do |verb, dir|
      xml.method_(name: verb) do
        xml.arg(name: 'interface', direction: 'in', type: 's')
        xml.arg(name: 'property', direction: 'in', type: 's')
        xml.arg(name: 'value', direction: dir, type: 'v')
      end
    end
    helper.call('Get', 'out')
    helper.call('Set', 'in')
  end
end

#xml_for_properties(xml) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/kaede/dbus/properties.rb', line 55

def xml_for_properties(xml)
  xml_for_dbus_properties(xml)
  self.class.properties_method.each do |iface, method_sym|
    xml.interface(name: iface) do
      send(method_sym).each_key do |key|
        xml.property(name: key, type: 's', access: 'read')
      end
    end
  end
end