Class: DBus::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/dbus/bus.rb

Overview

Main event loop class.

Class that takes care of handling message and signal events asynchronously. Note: This is a native implement and therefore does not integrate with a graphical widget set main loop.

Instance Method Summary collapse

Constructor Details

#initializeMain

Create a new main event loop.



667
668
669
670
# File 'lib/dbus/bus.rb', line 667

def initialize
  @buses = Hash.new
  @quitting = false
end

Instance Method Details

#<<(bus) ⇒ Object

Add a bus to the list of buses to watch for events.



673
674
675
# File 'lib/dbus/bus.rb', line 673

def <<(bus)
  @buses[bus.socket] = bus
end

#quitObject

Quit a running main loop, to be used eg. from a signal handler



678
679
680
# File 'lib/dbus/bus.rb', line 678

def quit
  @quitting = true
end

#runObject

Run the main loop. This is a blocking call!



683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
# File 'lib/dbus/bus.rb', line 683

def run
  # before blocking, empty the buffers
  # https://bugzilla.novell.com/show_bug.cgi?id=537401
  @buses.each_value do |b|
    while m = b.pop_message
      b.process(m)
    end
  end
  while not @quitting and not @buses.empty?
    ready, dum, dum = IO.select(@buses.keys)
    ready.each do |socket|
      b = @buses[socket]
      begin
        b.update_buffer
      rescue EOFError
        @buses.delete socket # this bus died
        next
      end
      while m = b.pop_message
        b.process(m)
      end
    end
  end
end