Class: DBus::Main
- Inherits:
-
Object
- Object
- DBus::Main
- Defined in:
- lib/dbus/main.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.
20 21 22 23 |
# File 'lib/dbus/main.rb', line 20 def initialize @buses = {} @quitting = false end |
Instance Method Details
#<<(bus) ⇒ Object
Add a bus to the list of buses to watch for events.
26 27 28 |
# File 'lib/dbus/main.rb', line 26 def <<(bus) @buses[bus..socket] = bus end |
#quit ⇒ Object
Quit a running main loop, to be used eg. from a signal handler
31 32 33 |
# File 'lib/dbus/main.rb', line 31 def quit @quitting = true end |
#run ⇒ Object
Run the main loop. This is a blocking call!
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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..) 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..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..) 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 |