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 704 def initialize 705 @buses = {} 706 @quitting = false 707 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 710 def <<(bus) 711 @buses[bus.message_queue.socket] = bus 712 end
quit()
click to toggle source
Quit a running main loop, to be used eg. from a signal handler
# File lib/dbus/bus.rb 715 def quit 716 @quitting = true 717 end
run()
click to toggle source
Run the main loop. This is a blocking call!
# File lib/dbus/bus.rb 720 def run 721 # before blocking, empty the buffers 722 # https://bugzilla.novell.com/show_bug.cgi?id=537401 723 @buses.each_value do |b| 724 while (m = b.message_queue.message_from_buffer_nonblock) 725 b.process(m) 726 end 727 end 728 while !@quitting && !@buses.empty? 729 ready = IO.select(@buses.keys, [], [], 5) # timeout 5 seconds 730 next unless ready # timeout exceeds so continue unless quitting 731 ready.first.each do |socket| 732 b = @buses[socket] 733 begin 734 b.message_queue.buffer_from_socket_nonblock 735 rescue EOFError, SystemCallError 736 @buses.delete socket # this bus died 737 next 738 end 739 while (m = b.message_queue.message_from_buffer_nonblock) 740 b.process(m) 741 end 742 end 743 end 744 end