Class: DBus::Systemd::Importd::Manager

Inherits:
Object
  • Object
show all
Includes:
Mixin::MethodMissing, Mixin::Properties
Defined in:
lib/dbus/systemd/importd/manager.rb

Constant Summary collapse

NODE =

the importd manager dbus node path

'/org/freedesktop/import1'.freeze
INTERFACE =

the importd manager dbus interface

'org.freedesktop.import1.Manager'.freeze
TRANSFER_INDICES =

index mapping of transfer array returned from ListTransfers()

{
  id: 0,
  operation: 1,
  remote_file: 2,
  image_name: 3,
  progress: 4,
  object_path: 5
}.freeze

Instance Attribute Summary collapse

Attributes included from Mixin::MethodMissing

#object

Instance Method Summary collapse

Methods included from Mixin::Properties

#properties

Methods included from Mixin::MethodMissing

#method_missing, #respond_to_missing?

Constructor Details

#initialize(bus = Systemd::Helpers.system_bus) ⇒ Manager

Creates a new Manager object for interfacing with the hostnamed Manager interface

Parameters:

  • bus (DBus::SystemBus, DBus::SessionBus) (defaults to: Systemd::Helpers.system_bus)

    dbus instance



60
61
62
63
64
65
# File 'lib/dbus/systemd/importd/manager.rb', line 60

def initialize(bus = Systemd::Helpers.system_bus)
  @service = bus.service(Importd::SERVICE)
  @object = @service.object(NODE)
  @object.default_iface = INTERFACE
  @object.introspect
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DBus::Systemd::Mixin::MethodMissing

Instance Attribute Details

#serviceDBus::Service (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (DBus::Service)


53
54
55
# File 'lib/dbus/systemd/importd/manager.rb', line 53

def service
  @service
end

Instance Method Details

#get_transfer_by_path(path) ⇒ DBus::Systemd::Importd::Transfer

Create a transfer object from the transfer node path

Parameters:

  • path (String)

    transfer dbus node path

Returns:



89
90
91
92
93
# File 'lib/dbus/systemd/importd/manager.rb', line 89

def get_transfer_by_path(path)
  obj = @service.object(path)
                .tap(&:introspect)
  Transfer.new(obj.Get(Transfer::INTERFACE, 'Id').first, self)
end

#map_transfer(transfer_array) ⇒ Hash

map a transfer array as returned from ListTransfers to a hash with keys from TRANSER_INDICES

Parameters:

  • transfer_array (Array)

    a transfer array

Returns:

  • (Hash)

    mapped transfer array to named fields



101
102
103
# File 'lib/dbus/systemd/importd/manager.rb', line 101

def map_transfer(transfer_array)
  Systemd::Helpers.map_array(transfer_array, TRANSFER_INDICES)
end

#transfer(id) ⇒ DBus::Systemd::Importd::Transfer

Create a transfer object from a transfer id

Parameters:

  • id (Integer)

    transfer id

Returns:



80
81
82
# File 'lib/dbus/systemd/importd/manager.rb', line 80

def transfer(id)
  Transfer.new(id, self)
end

#transfersArray

return a list of mapped transfers

Returns:

  • (Array)

    array of hashes with transfer data



71
72
73
# File 'lib/dbus/systemd/importd/manager.rb', line 71

def transfers
  self.ListTransfers.first.map { |t| map_transfer(t) }
end