Module: DInstaller::DBus::Clients::WithServiceStatus

Included in:
Manager, Software, Users
Defined in:
lib/dinstaller/dbus/clients/with_service_status.rb

Overview

Note:

This mixin is expected to be included in a class inherited from Base and it requires a #dbus_object method that returns a DBus::Object implementing the ServiceStatus interface.

Mixin for clients of services that define the ServiceStatus D-Bus interface

Provides methods to interact with the API of the ServiceStatus interface.

Instance Method Summary collapse

Instance Method Details

#on_service_status_change(&block) {|service_status| ... } ⇒ Object

Registers a callback to run when the current status property changes

Parameters:

  • block (Proc)

Yield Parameters:



51
52
53
54
55
56
57
58
# File 'lib/dinstaller/dbus/clients/with_service_status.rb', line 51

def on_service_status_change(&block)
  on_properties_change(dbus_object) do |interface, changes, _|
    if interface == Interfaces::ServiceStatus::SERVICE_STATUS_INTERFACE
      service_status = to_service_status(changes["Current"])
      block.call(service_status)
    end
  end
end

#service_statusServiceStatus::IDLE, ServiceStatus::BUSY

Current value of the service status



42
43
44
45
# File 'lib/dinstaller/dbus/clients/with_service_status.rb', line 42

def service_status
  dbus_status = dbus_object[Interfaces::ServiceStatus::SERVICE_STATUS_INTERFACE]["Current"]
  to_service_status(dbus_status)
end

#to_service_status(dbus_status) ⇒ ServiceStatus::IDLE, ServiceStatus::BUSY

Converts the D-Bus status value to the equivalent service status value

Parameters:

  • dbus_status (Integer)

Returns:



64
65
66
67
68
69
70
71
# File 'lib/dinstaller/dbus/clients/with_service_status.rb', line 64

def to_service_status(dbus_status)
  case dbus_status
  when Interfaces::ServiceStatus::SERVICE_STATUS_IDLE
    ServiceStatus::IDLE
  when Interfaces::ServiceStatus::SERVICE_STATUS_BUSY
    ServiceStatus::BUSY
  end
end