Class: SystemdMon::DBusUnit

Inherits:
Object
  • Object
show all
Defined in:
lib/systemd_mon/dbus_unit.rb

Constant Summary collapse

IFACE_UNIT =
"org.freedesktop.systemd1.Unit"
IFACE_PROPS =
"org.freedesktop.DBus.Properties"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path, dbus_object) ⇒ DBusUnit

Returns a new instance of DBusUnit.



10
11
12
13
14
15
# File 'lib/systemd_mon/dbus_unit.rb', line 10

def initialize(name, path, dbus_object)
  self.name = name
  self.path = path
  self.dbus_object = dbus_object
  prepare_dbus_objects!
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/systemd_mon/dbus_unit.rb', line 5

def name
  @name
end

Instance Method Details

#on_change(&callback) ⇒ Object



26
27
28
# File 'lib/systemd_mon/dbus_unit.rb', line 26

def on_change(&callback)
  self.change_callback = callback
end

#on_each_state_change(&callback) ⇒ Object



30
31
32
# File 'lib/systemd_mon/dbus_unit.rb', line 30

def on_each_state_change(&callback)
  self.each_state_change_callback = callback
end

#property(name) ⇒ Object



34
35
36
# File 'lib/systemd_mon/dbus_unit.rb', line 34

def property(name)
  dbus_object.Get(IFACE_UNIT, name).first
end

#register_listener!(queue) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/systemd_mon/dbus_unit.rb', line 17

def register_listener!(queue)
  queue.enq [self, build_state] # initial state
  dbus_object.on_signal("PropertiesChanged") do |iface|
    if iface == IFACE_UNIT
      queue.enq [self, build_state]
    end
  end
end