Class: Circus::Agents::DBusConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/circus/agents/dbus_connection.rb

Direct Known Subclasses

SSHConnection

Instance Method Summary collapse

Constructor Details

#initialize(bus = nil) ⇒ DBusConnection

Returns a new instance of DBusConnection.



7
8
9
# File 'lib/circus/agents/dbus_connection.rb', line 7

def initialize(bus = nil)
  @bus = bus || DBus::SystemBus.instance
end

Instance Method Details

#call(target, object, iface, method, args, logger) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/circus/agents/dbus_connection.rb', line 19

def call(target, object, iface, method, args, logger)
  action_id = UUID.generate
  
  @service = @bus.service("com.deployacircus.#{object}")
  obj = @service.object("/com/deployacircus/#{object}")
  obj.introspect
  obj_iface = obj["com.deployacircus.#{iface}"]
  dbus_method = obj_iface.methods[method]
  raise ArgumentError.new("Method #{method} on #{object} not found") unless dbus_method
  
  msg = DBus::Message.new(DBus::Message::METHOD_CALL)
  msg.path = obj.path
  msg.interface = obj_iface.name
  msg.destination = obj.destination
  msg.member = dbus_method.name
  msg.sender = @bus.unique_name
  dbus_method.params.each do |p|
    if p.name == 'id'
      msg.add_param p.type, action_id
    else
      msg.add_param(p.type, args[p.name])
    end
  end
  promise = DBusPromise.new(@bus)
  @bus.on_return(msg) do |rmsg|
    promise.completed!(rmsg)
  end
  obj_iface.on_signal(@bus, 'LogEntry') do |log_action_id, msg|
    logger.info(msg) if action_id == log_action_id
  end
  @bus.send(msg.marshall)
  
  promise
end

#configure_bg!(options = {}) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/circus/agents/dbus_connection.rb', line 11

def configure_bg!(options = {})
  Thread.new do
    l = DBus::Main.new
    l << @bus
    l.run
  end 
end

#send_file(fn) ⇒ Object



54
55
56
57
58
# File 'lib/circus/agents/dbus_connection.rb', line 54

def send_file(fn)
  # Normal DBus connections can see the file locally just fine, so we don't need to
  # do anything with it.
  fn
end