# 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
    233 def self.address_from_file
    234   # systemd uses /etc/machine-id
    235   # traditional dbus uses /var/lib/dbus/machine-id
    236   machine_id_path = Dir["{/etc,/var/lib/dbus,/var/db/dbus}/machine-id"].first
    237   return nil unless machine_id_path
    238
    239   machine_id = File.read(machine_id_path).chomp
    240
    241   display = ENV["DISPLAY"][/:(\d+)\.?/, 1]
    242
    243   bus_file_path = File.join(ENV["HOME"], "/.dbus/session-bus/#{machine_id}-#{display}")
    244   return nil unless File.exist?(bus_file_path)
    245
    246   File.open(bus_file_path).each_line do |line|
    247     if line =~ /^DBUS_SESSION_BUS_ADDRESS=(.*)/
    248       address = Regexp.last_match(1)
    249       return address[/\A'(.*)'\z/, 1] || address[/\A"(.*)"\z/, 1] || address
    250     end
    251   end
    252 end

new() click to toggle source

Get the the default session bus.

Calls superclass method `DBus::BusConnection::new`

        # File lib/dbus/bus.rb
    222 def initialize
    223   super(self.class.session_bus_address)
    224 end

session_bus_address() click to toggle source

        # File lib/dbus/bus.rb
    226 def self.session_bus_address
    227   ENV["DBUS_SESSION_BUS_ADDRESS"] ||
    228     address_from_file ||
    229     ("launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET" if Platform.macos?) ||
    230     (raise NotImplementedError, "Cannot find session bus; sorry, haven't figured out autolaunch yet")
    231 end