Class: Kaede::DBus::Program

Inherits:
DBus::Object
  • Object
show all
Defined in:
lib/kaede/dbus/program.rb

Constant Summary collapse

PATH =
'/cc/wanko/kaede1/program'
PROPERTY_INTERFACE =
'org.freedesktop.DBus.Properties'
INTROSPECT_INTERFACE =
'org.freedesktop.DBus.Introspectable'
PROGRAM_INTERFACE =
'cc.wanko.kaede1.Program'

Instance Method Summary collapse

Constructor Details

#initialize(program, enqueued_at) ⇒ Program



13
14
15
16
17
# File 'lib/kaede/dbus/program.rb', line 13

def initialize(program, enqueued_at)
  super("#{PATH}/#{program.pid}")
  @program = program
  @enqueued_at = enqueued_at
end

Instance Method Details

#propertiesObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/kaede/dbus/program.rb', line 94

def properties
  @properties ||= {
    'Pid' => @program.pid,
    'Tid' => @program.tid,
    'StartTime' => @program.start_time.iso8601,
    'EndTime' => @program.end_time.iso8601,
    'ChannelName' => @program.channel_name,
    'ChannelForSyoboi' => @program.channel_for_syoboi,
    'ChannelForRecorder' => @program.channel_for_recorder,
    'Count' => @program.count,
    'StartOffset' => @program.start_offset,
    'SubTitle' => @program.subtitle,
    'Title' => @program.title,
    'Comment' => @program.comment,
    'EnqueuedAt' => @enqueued_at.iso8601,
  }
end

#raise_access_denied!Object



120
121
122
# File 'lib/kaede/dbus/program.rb', line 120

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

#raise_unknown_interface!Object



112
113
114
# File 'lib/kaede/dbus/program.rb', line 112

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

#raise_unknown_property!Object



116
117
118
# File 'lib/kaede/dbus/program.rb', line 116

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

#to_xmlObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/kaede/dbus/program.rb', line 19

def to_xml
  Nokogiri::XML::Builder.new do |xml|
    xml.doc.create_internal_subset(
      'node',
      '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN',
      'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd',
    )
    xml.node do
      xml.interface(name: INTROSPECT_INTERFACE) do
        xml.method_(name: 'Introspect') do
          xml.arg(name: 'data', direction: 'out', type: 's')
        end
      end

      xml.interface(name: PROPERTY_INTERFACE) do
        xml.method_(name: 'Get') do
          xml.arg(name: 'interface', direction: 'in', type: 's')
          xml.arg(name: 'property', direction: 'in', type: 's')
          xml.arg(name: 'value', direction: 'out', type: 'v')
        end

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

        xml.method_(name: 'Set') do
          xml.arg(name: 'interface', direction: 'in', type: 's')
          xml.arg(name: 'property', direction: 'in', type: 's')
          xml.arg(name: 'value', direction: 'in', type: 'v')
        end
      end

      xml.interface(name: PROGRAM_INTERFACE) do
        properties.each_key do |key|
          xml.property(name: key, type: 's', access: 'read')
        end
      end
    end
  end.to_xml
end