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::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

#main_message_queue, #main_thread, #queue_used_by_thread, #read_thread, #rescuemethod, #socket, #thread_waiting_for_message, #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, #send_sync_or_async, #service, #start_read_thread, #update_buffer, #wait_for_message

Constructor Details

#initializeASessionBus

Get the the default session bus.



789
790
791
792
793
# File 'lib/dbus/bus.rb', line 789

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

Instance Method Details

#address_from_fileObject



795
796
797
798
799
800
801
802
803
804
805
# File 'lib/dbus/bus.rb', line 795

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