Module: DInstaller::DBus::Interfaces::Progress

Included in:
Manager, Software::Manager
Defined in:
lib/dinstaller/dbus/interfaces/progress.rb

Overview

Note:

This mixin is expected to be included in a class inherited from BaseObject class and it requires a #backend method that returns an instance of a class including the WithProgress mixin.

Mixin to define the Progress D-Bus interface

Examples:

class Backend
  include DInstaller::WithProgress
end

class Demo < DInstaller::DBus::BaseObject
  include DInstaller::DBus::Interfaces::Progress

  def initialize
    super("org.test.Demo")
    register_progress_callbacks
  end

  def backend
    @backend ||= Backend.new
  end
end

Constant Summary collapse

PROGRESS_INTERFACE =
"org.opensuse.DInstaller.Progress1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/dinstaller/dbus/interfaces/progress.rb', line 101

def self.included(base)
  base.class_eval do
    dbus_interface PROGRESS_INTERFACE do
      dbus_reader :progress_total_steps, "u", dbus_name: "TotalSteps"
      dbus_reader :progress_current_step, "(us)", dbus_name: "CurrentStep"
      dbus_reader :progress_finished, "b", dbus_name: "Finished"
    end
  end
end

Instance Method Details

#progress_current_stepArray(Number,String)

Current step data

Returns:

  • (Array(Number,String))

    Step id and description



65
66
67
68
69
70
# File 'lib/dinstaller/dbus/interfaces/progress.rb', line 65

def progress_current_step
  current_step = backend.progress&.current_step
  return [0, ""] unless current_step

  [current_step.id, current_step.description]
end

#progress_finishedBoolean

Whether the progress has finished

Returns:

  • (Boolean)


75
76
77
78
79
# File 'lib/dinstaller/dbus/interfaces/progress.rb', line 75

def progress_finished
  return true unless backend.progress

  backend.progress.finished?
end

#progress_propertiesHash

D-Bus properties of the Progress interface

Returns:

  • (Hash)


84
85
86
# File 'lib/dinstaller/dbus/interfaces/progress.rb', line 84

def progress_properties
  interfaces_and_properties[PROGRESS_INTERFACE]
end

#progress_total_stepsInteger

Total number of steps of the progress

Returns:

  • (Integer)

    0 if no progress defined



56
57
58
59
60
# File 'lib/dinstaller/dbus/interfaces/progress.rb', line 56

def progress_total_steps
  return 0 unless backend.progress

  backend.progress.total_steps
end

#register_progress_callbacksObject

Note:

This method is expected to be called in the constructor.

Registers callbacks to be called when the progress changes or finishes



91
92
93
94
95
96
97
98
99
# File 'lib/dinstaller/dbus/interfaces/progress.rb', line 91

def register_progress_callbacks
  backend.on_progress_change do
    dbus_properties_changed(PROGRESS_INTERFACE, progress_properties, [])
  end

  backend.on_progress_finish do
    dbus_properties_changed(PROGRESS_INTERFACE, progress_properties, [])
  end
end