# class DBus::ASessionBus

# D-Bus session bus class¶ ↑

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

Use `SessionBus`, the non-singleton `ASessionBus` is for the test suite.

### Public Class Methods

address_from_file() click to toggle source

        # File lib/dbus/bus.rb
    620 def self.address_from_file
    621   # systemd uses /etc/machine-id
    622   # traditional dbus uses /var/lib/dbus/machine-id
    623   machine_id_path = Dir["{/etc,/var/lib/dbus,/var/db/dbus}/machine-id"].first
    624   return nil unless machine_id_path
    625   machine_id = File.read(machine_id_path).chomp
    626
    627   display = ENV["DISPLAY"][/:(\d+)\.?/, 1]
    628
    629   bus_file_path = File.join(ENV["HOME"], "/.dbus/session-bus/#{machine_id}-#{display}")
    630   return nil unless File.exist?(bus_file_path)
    631
    632   File.open(bus_file_path).each_line do |line|
    633     if line =~ /^DBUS_SESSION_BUS_ADDRESS=(.*)/
    634       address = Regexp.last_match(1)
    635       return address[/\A'(.*)'\z/, 1] || address[/\A"(.*)"\z/, 1] || address
    636     end
    637   end
    638 end

new() click to toggle source

Get the the default session bus.

Calls superclass method `DBus::Connection::new`

        # File lib/dbus/bus.rb
    609 def initialize
    610   super(self.class.session_bus_address)
    611   send_hello
    612 end

session_bus_address() click to toggle source

        # File lib/dbus/bus.rb
    614 def self.session_bus_address
    615   ENV["DBUS_SESSION_BUS_ADDRESS"] ||
    616     address_from_file ||
    617     "launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET"
    618 end