class DBus::Main
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.
Public Class Methods
new()
click to toggle source
Create a new main event loop.
# File lib/dbus/bus.rb 701 def initialize 702 @buses = {} 703 @quitting = false 704 end
Public Instance Methods
<<(bus)
click to toggle source
Add a bus to the list of buses to watch for events.
# File lib/dbus/bus.rb 707 def <<(bus) 708 @buses[bus.message_queue.socket] = bus 709 end
quit()
click to toggle source
Quit a running main loop, to be used eg. from a signal handler
# File lib/dbus/bus.rb 712 def quit 713 @quitting = true 714 end
run()
click to toggle source
Run the main loop. This is a blocking call!
# File lib/dbus/bus.rb 717 def run 718 # before blocking, empty the buffers 719 # https://bugzilla.novell.com/show_bug.cgi?id=537401 720 @buses.each_value do |b| 721 while (m = b.message_queue.message_from_buffer_nonblock) 722 b.process(m) 723 end 724 end 725 while !@quitting && !@buses.empty? 726 ready = IO.select(@buses.keys, [], [], 5) # timeout 5 seconds 727 next unless ready # timeout exceeds so continue unless quitting 728 ready.first.each do |socket| 729 b = @buses[socket] 730 begin 731 b.message_queue.buffer_from_socket_nonblock 732 rescue EOFError, SystemCallError 733 @buses.delete socket # this bus died 734 next 735 end 736 while (m = b.message_queue.message_from_buffer_nonblock) 737 b.process(m) 738 end 739 end 740 end 741 end