Class: DBus::ASessionBus

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

Overview

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.

Direct Known Subclasses

SessionBus

Constant Summary

Constants inherited from Connection

Connection::DBUSXMLINTRO, 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

#message_queue, #unique_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Connection

#add_match, #dispatch_message_queue, #emit, #glibize, #introspect, #introspect_data, #on_return, #process, #proxy, #remove_match, #request_service, #send_sync, #send_sync_or_async, #service, #wait_for_message

Constructor Details

#initializeASessionBus

Get the the default session bus.



655
656
657
658
# File 'lib/dbus/bus.rb', line 655

def initialize
  super(self.class.session_bus_address)
  send_hello
end

Class Method Details

.address_from_fileObject



666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/dbus/bus.rb', line 666

def self.address_from_file
  # systemd uses /etc/machine-id
  # traditional dbus uses /var/lib/dbus/machine-id
  machine_id_path = Dir["{/etc,/var/lib/dbus,/var/db/dbus}/machine-id"].first
  return nil unless machine_id_path

  machine_id = File.read(machine_id_path).chomp

  display = ENV["DISPLAY"][/:(\d+)\.?/, 1]

  bus_file_path = File.join(ENV["HOME"], "/.dbus/session-bus/#{machine_id}-#{display}")
  return nil unless File.exist?(bus_file_path)

  File.open(bus_file_path).each_line do |line|
    if line =~ /^DBUS_SESSION_BUS_ADDRESS=(.*)/
      address = Regexp.last_match(1)
      return address[/\A'(.*)'\z/, 1] || address[/\A"(.*)"\z/, 1] || address
    end
  end
end

.session_bus_addressObject



660
661
662
663
664
# File 'lib/dbus/bus.rb', line 660

def self.session_bus_address
  ENV["DBUS_SESSION_BUS_ADDRESS"] ||
    address_from_file ||
    "launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET"
end