Class: DBus::Main
- Inherits:
-
Object
- Object
- DBus::Main
- 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
-
#<<(bus) ⇒ Object
Add a bus to the list of buses to watch for events.
-
#initialize ⇒ Main
constructor
Create a new main event loop.
-
#quit ⇒ Object
Quit a running main loop, to be used eg.
-
#run ⇒ Object
Run the main loop.
Constructor Details
#initialize ⇒ Main
Create a new main event loop.
814 815 816 817 |
# File 'lib/dbus/bus.rb', line 814 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.
820 821 822 |
# File 'lib/dbus/bus.rb', line 820 def <<(bus) @buses[bus.socket] = bus end |
#quit ⇒ Object
Quit a running main loop, to be used eg. from a signal handler
825 826 827 |
# File 'lib/dbus/bus.rb', line 825 def quit @quitting = true end |
#run ⇒ Object
Run the main loop. This is a blocking call!
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 |
# File 'lib/dbus/bus.rb', line 830 def run # before blocking, empty the buffers # https://bugzilla.novell.com/show_bug.cgi?id=537401 @buses.each_value do |b| while m = b. b.process(m) end end while not @quitting and not @buses.empty? ready = IO.select(@buses.keys, [], [], 5) # timeout 5 seconds next unless ready # timeout exceeds so continue unless quitting ready.first.each do |socket| b = @buses[socket] begin b.update_buffer rescue EOFError, SystemCallError @buses.delete socket # this bus died next end while m = b. b.process(m) end end end end |