Class: DBus::SessionBus

Inherits:
Connection show all
Includes:
Singleton
Defined in:
lib/dbus/bus.rb

Overview

D-Bus session bus class

The session bus is a session specific bus (mostly for desktop use). This is a singleton class.

Constant Summary

Constants inherited from Connection

Connection::DBUSXMLINTRO, Connection::MSG_BUF_SIZE, Connection::NAME_FLAG_ALLOW_REPLACEMENT, Connection::NAME_FLAG_DO_NOT_QUEUE, Connection::NAME_FLAG_REPLACE_EXISTING, Connection::REQUEST_NAME_REPLY_ALREADY_OWNER, Connection::REQUEST_NAME_REPLY_EXISTS, Connection::REQUEST_NAME_REPLY_IN_QUEUE, Connection::REQUEST_NAME_REPLY_PRIMARY_OWNER

Instance Attribute Summary

Attributes inherited from Connection

#socket, #unique_name

Instance Method Summary collapse

Methods inherited from Connection

#add_match, #connect, #connect_to_tcp, #connect_to_unix, #emit, #glibize, #introspect, #introspect_data, #messages, #on_return, #poll_messages, #pop_message, #process, #proxy, #remove_match, #request_service, #send, #send_sync, #service, #update_buffer, #wait_for_message

Constructor Details

#initializeSessionBus

Get the the default session bus.



703
704
705
706
707
# File 'lib/dbus/bus.rb', line 703

def initialize
  super(ENV["DBUS_SESSION_BUS_ADDRESS"] || address_from_file)
  connect
  send_hello
end

Instance Method Details

#address_from_fileObject



709
710
711
712
713
714
715
716
717
718
719
# File 'lib/dbus/bus.rb', line 709

def address_from_file
  f = File.new("/var/lib/dbus/machine-id")
  machine_id = f.readline.chomp
  f.close
  display = ENV["DISPLAY"].gsub(/.*:([0-9]*).*/, '\1')
  File.open(ENV["HOME"] + "/.dbus/session-bus/#{machine_id}-#{display}").each do |line|
    if line =~ /^DBUS_SESSION_BUS_ADDRESS=(.*)/
      return $1
    end
  end
end