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/main.rb, line 20 def initialize @buses = {} @quitting = false end
Public Instance Methods
<<(bus)
click to toggle source
Add a bus to the list of buses to watch for events.
# File lib/dbus/main.rb, line 26 def <<(bus) @buses[bus.message_queue.socket] = bus end
quit()
click to toggle source
Quit a running main loop, to be used eg. from a signal handler
# File lib/dbus/main.rb, line 31 def quit @quitting = true end
run()
click to toggle source
Run the main loop. This is a blocking call!
# File lib/dbus/main.rb, line 36 def run # before blocking, empty the buffers # https://bugzilla.novell.com/show_bug.cgi?id=537401 @buses.each_value do |b| while (m = b.message_queue.message_from_buffer_nonblock) b.process(m) end end while !@quitting && !@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.message_queue.buffer_from_socket_nonblock rescue EOFError, SystemCallError => e DBus.logger.debug "Got #{e.inspect} from #{socket.inspect}" @buses.delete socket # this bus died next end while (m = b.message_queue.message_from_buffer_nonblock) b.process(m) end end end DBus.logger.debug "Main loop quit" if @quitting DBus.logger.debug "Main loop quit, no connections left" if @buses.empty? end