Function: dbus-register-monitor

dbus-register-monitor is a byte-compiled function defined in dbus.el.gz.

Signature

(dbus-register-monitor BUS &optional HANDLER &key TYPE SENDER DESTINATION PATH INTERFACE MEMBER)

Documentation

Register HANDLER for monitor events on the D-Bus BUS.

BUS is either a Lisp keyword, :system or :session, or a string denoting the bus address.

HANDLER is the function to be called when a monitor event arrives. It is called with the args slot of the monitor event, which are stripped off the type keywords. If HANDLER is nil, the default handler dbus-monitor-handler is applied.

The other arguments are keyword-value pairs. :type TYPE defines the message type to be monitored. If given, it must be equal one of the strings "method_call", "method_return",
"error" or "signal".

:sender SENDER and :destination DESTINATION are D-Bus names.
They can be unique names, or well-known service names.

:path PATH is the D-Bus object to be monitored. :interface
INTERFACE is the name of an interface, and :member MEMBER is either a method name, a signal name, or an error name.

Source Code

;; Defined in /usr/src/emacs/lisp/net/dbus.el.gz
(cl-defun dbus-register-monitor
    (bus &optional handler &key type sender destination path interface member)
  "Register HANDLER for monitor events on the D-Bus BUS.

BUS is either a Lisp keyword, `:system' or `:session', or a
string denoting the bus address.

HANDLER is the function to be called when a monitor event
arrives.  It is called with the `args' slot of the monitor event,
which are stripped off the type keywords.  If HANDLER is nil, the
default handler `dbus-monitor-handler' is applied.

The other arguments are keyword-value pairs.  `:type TYPE'
defines the message type to be monitored.  If given, it must be
equal one of the strings \"method_call\", \"method_return\",
\"error\" or \"signal\".

`:sender SENDER' and `:destination DESTINATION' are D-Bus names.
They can be unique names, or well-known service names.

`:path PATH' is the D-Bus object to be monitored.  `:interface
INTERFACE' is the name of an interface, and `:member MEMBER' is
either a method name, a signal name, or an error name."
  (let ((bus-private (if (eq bus :system) :system-private
                       (if (eq bus :session) :session-private bus)))
        rule key key1 value)
    (unless handler (setq handler #'dbus-monitor-handler))
    ;; Compose rule.
    (setq rule
          (string-join
           (delq nil (mapcar
                      (lambda (item)
                        (when (cdr item)
                          (format "%s='%s'" (car item) (cdr item))))
                      `(("type" . ,type) ("sender" . ,sender)
                        ("destination" . ,destination) ("path" . ,path)
                        ("interface" . ,interface) ("member" . ,member))))
           ",")
          rule (or rule ""))

    (when (fboundp 'dbus-get-unique-name)
      (unless (ignore-errors (dbus-get-unique-name bus-private))
        (dbus-init-bus bus 'private)))
    (dbus-call-method
     bus-private dbus-service-dbus dbus-path-dbus dbus-interface-monitoring
     "BecomeMonitor" `(:array :string ,rule) :uint32 0)

    (when dbus-debug (message "Matching rule \"%s\" created" rule))

    ;; Create a hash table entry.
    (setq key (list :monitor bus-private)
	  key1 (list nil nil nil handler rule)
	  value (gethash key dbus-registered-objects-table))
    (unless  (member key1 value)
      (puthash key (cons key1 value) dbus-registered-objects-table))

    (when dbus-debug (message "%s" dbus-registered-objects-table))

    ;; Return the object.
    (list key (list nil nil handler))))