class SystemdMon::DBusUnit

Constants

IFACE_PROPS
IFACE_SERVICE
IFACE_UNIT

Attributes

change_callback[RW]
dbus_object[RW]
each_state_change_callback[RW]
maybe_service_type[RW]
name[RW]
path[RW]

Public Class Methods

new(name, path, dbus_object) click to toggle source
# File lib/systemd_mon/dbus_unit.rb, line 11
def initialize(name, path, dbus_object)
  self.name = name
  self.path = path
  self.dbus_object = dbus_object
  prepare_dbus_objects!
  self.maybe_service_type = service_type
end

Public Instance Methods

on_change(&callback) click to toggle source
# File lib/systemd_mon/dbus_unit.rb, line 28
def on_change(&callback)
  self.change_callback = callback
end
on_each_state_change(&callback) click to toggle source
# File lib/systemd_mon/dbus_unit.rb, line 32
def on_each_state_change(&callback)
  self.each_state_change_callback = callback
end
property(name) click to toggle source
# File lib/systemd_mon/dbus_unit.rb, line 36
def property(name)
  dbus_object.Get(IFACE_UNIT, name).first
end
register_listener!(queue) click to toggle source
# File lib/systemd_mon/dbus_unit.rb, line 19
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
to_s() click to toggle source
# File lib/systemd_mon/dbus_unit.rb, line 40
def to_s
  "#{name}" << (maybe_service_type ? " (#{maybe_service_type})" : '')
end

Protected Instance Methods

build_state() click to toggle source
# File lib/systemd_mon/dbus_unit.rb, line 48
def build_state
  State.new(
    property("ActiveState"),
    property("SubState"),
    property("LoadState"),
    property("UnitFileState"),
    maybe_service_type
  )
end
prepare_dbus_objects!() click to toggle source
# File lib/systemd_mon/dbus_unit.rb, line 58
def prepare_dbus_objects!
  dbus_object.introspect
  self.dbus_object.default_iface = IFACE_PROPS
  self
end
service_type() click to toggle source
# File lib/systemd_mon/dbus_unit.rb, line 64
def service_type
  if dbus_object[IFACE_SERVICE]
    dbus_object[IFACE_SERVICE]['Type']
  end
end