Class DBus::Bus
In: lib/dbus.rb
Parent: Object

Represents a connection to a DBus daemon

Methods

Constants

TYPE_SESSION = BUS_SESSION
TYPE_SYSTEM = BUS_SYSTEM
TYPE_ACTIVATION = BUS_ACTIVATION

Public Class methods

[Source]

    # File lib/dbus.rb, line 21
21:     def initialize(bus_type=TYPE_SESSION, glib_mainloop=true)
22:       @connection = DBus::Binding::bus_get(bus_type)
23:       @connection.add_filter(method(:signal_dispatcher))
24:       @rules = {}
25:       @connection.setup_with_g_main if glib_mainloop
26:     end

Public Instance methods

Activates the given service on this bus

[Source]

    # File lib/dbus.rb, line 91
91:     def activate_service(service_name, flags=0)
92:       DBus::Binding::bus_activate_service(@connection, service_name, flags)
93:     end

Add a handler handler_proc for the match rule resulting from passing the parameters to Bus#build_signal_rule. Multiple handlers can be installed for the same signal.

[Source]

    # File lib/dbus.rb, line 39
39:     def add_signal_receiver(handler_proc, signal_name=nil, interface=nil, service=nil, path=nil)
40:       rule = build_signal_rule(signal_name, interface, service, path)
41:       @rules[rule] ||= []
42:       @rules[rule] << handler_proc unless @rules[rule].include?(handler_proc)
43:       DBus::Binding::bus_add_match(@connection, rule)
44:     end

Generate a match rule for a signal with the specified arguments. If any of the method arguments is nil, its processing (below) is skipped.

  • The rule "type" is set to "signal"
  • The rule "interface" is set to the value of the interface argument
  • The rule "sender" is set as follows: If the given service argument does not start with ":", and is not "org.freedesktop.DBus", the "sender" value is set to the owner of the supplied service argument (determined with a GetServiceOwner call), otherwise, the service value is used
  • The "path" parameter is set to the value of the path argument
  • The "member" parameter is set to the value of the signal_name argument

[Source]

    # File lib/dbus.rb, line 67
67:     def build_signal_rule(signal_name, interface, service, path)
68:       rule = "type='signal'"
69:       if interface
70:         rule += ",interface='%s'" % interface
71:       end
72:       if service
73:         if service[0,1] != ":" && service != "org.freedesktop.DBus"
74:           bus_service = get_service("org.freedesktop.DBus")
75:           bus_object = bus_service.get_object("/org/freedesktop/DBus",
76:                                               "org.freedesktop.DBus")
77:           service = bus_object.GetServiceOwner(service)
78:         end
79:         rule += ",sender='%s'" % service
80:       end
81:       if path
82:         rule += ",path='%s'" % path
83:       end
84:       if signal_name
85:         rule += ",member='%s'" % signal_name
86:       end
87:       rule
88:     end

Returns the base service name of this bus

[Source]

     # File lib/dbus.rb, line 101
101:     def get_base_service
102:       DBus::Binding::bus_get_base_service(@connection)
103:     end

[Source]

    # File lib/dbus.rb, line 28
28:     def get_connection
29:       @connection
30:     end

[Source]

    # File lib/dbus.rb, line 32
32:     def get_service(name="org.freedesktop.Broadcast")
33:       RemoteService.new(self, name)
34:     end

Returns the UNIX user ID for the given service

[Source]

    # File lib/dbus.rb, line 96
96:     def get_unix_user(service_name)
97:       DBus::Binding::bus_get_unix_user(@connection, service_name)
98:     end

Remove the handler handler_proc for a match rule previously added using Bus#add_signal_receiver.

[Source]

    # File lib/dbus.rb, line 48
48:     def remove_signal_receiver(handler_proc, signal_name=nil, interface=nil, service=nil, path=nil)
49:       rule = build_signal_rule(signal_name, interface, service, path)
50:       return nil unless @rules.has_key?(rule)
51:       @rules[rule].remove(handler_proc)
52:       DBus::Binding::bus_remove_match(@conn, rule)
53:     end

Sets the base service name of this bus

[Source]

     # File lib/dbus.rb, line 106
106:     def set_base_service(service_name)
107:       DBus::Binding::bus_set_base_service(@connection, service_name)
108:     end

[Validate]