Class: Catfriend::DBus
- Inherits:
-
Object
- Object
- Catfriend::DBus
- Includes:
- Thread, Events::Emitter
- Defined in:
- lib/catfriend/dbus.rb
Overview
Represent a DBUS server interface and includes an associated thread in which to run the dbus methods.
Defined Under Namespace
Classes: DBusObject
Instance Method Summary collapse
-
#init ⇒ Object
Start the DBus interface.
-
#run ⇒ Object
Thread mixin interface: Run the DBus server in a virtual thread.
-
#send_shutdown ⇒ Object
Attempt to shutdown another application listening on catfriend’s address.
-
#start_service ⇒ Object
Call send_shutdown then start the DBus interface.
Methods included from Thread
#join, #kill, #start, #stopped?
Instance Method Details
#init ⇒ Object
Start the DBus interface
36 37 38 |
# File 'lib/catfriend/dbus.rb', line 36 def init @bus = ::DBus::SessionBus.instance unless @bus end |
#run ⇒ Object
Thread mixin interface: Run the DBus server in a virtual thread
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/catfriend/dbus.rb', line 61 def run init if send_shutdown Catfriend.whisper "shut down existing catfriend" end @main = ::DBus::Main.new start_service @main << @bus @main.run rescue => e puts "dbus unknown error #{e.}\n#{e.backtrace.join("\n")}" end |
#send_shutdown ⇒ Object
Attempt to shutdown another application listening on catfriend’s address.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/catfriend/dbus.rb', line 41 def send_shutdown init service = @bus.service(SERVICE) object = service.object(PATH) object.introspect object.default_iface = INTERFACE object.stop true rescue false end |
#start_service ⇒ Object
Call send_shutdown then start the DBus interface.
54 55 56 57 58 |
# File 'lib/catfriend/dbus.rb', line 54 def start_service object = DBusObject.new(@main, self) service = @bus.request_service(SERVICE) service.export object end |