Function: zeroconf-service-add-hook
zeroconf-service-add-hook is a byte-compiled function defined in
zeroconf.el.gz.
Signature
(zeroconf-service-add-hook TYPE EVENT FUNCTION)
Documentation
Add FUNCTION to the hook of service type TYPE.
EVENT must be either :new or :removed, indicating whether FUNCTION shall be called when a new service has been newly detected, or removed.
FUNCTION must accept one argument SERVICE, which identifies the new service. Initially, when EVENT is :new, FUNCTION is called for all already detected services of service type TYPE.
The attributes of SERVICE can be retrieved via the functions
zeroconf-service-interface
zeroconf-service-protocol
zeroconf-service-name
zeroconf-service-type
zeroconf-service-domain
zeroconf-service-flags
zeroconf-service-host
zeroconf-service-aprotocol
zeroconf-service-address
zeroconf-service-port
zeroconf-service-txt
Source Code
;; Defined in /usr/src/emacs/lisp/net/zeroconf.el.gz
(defun zeroconf-service-add-hook (type event function)
"Add FUNCTION to the hook of service type TYPE.
EVENT must be either `:new' or `:removed', indicating whether
FUNCTION shall be called when a new service has been newly
detected, or removed.
FUNCTION must accept one argument SERVICE, which identifies the
new service. Initially, when EVENT is :new, FUNCTION is called
for all already detected services of service type TYPE.
The attributes of SERVICE can be retrieved via the functions
`zeroconf-service-interface'
`zeroconf-service-protocol'
`zeroconf-service-name'
`zeroconf-service-type'
`zeroconf-service-domain'
`zeroconf-service-flags'
`zeroconf-service-host'
`zeroconf-service-aprotocol'
`zeroconf-service-address'
`zeroconf-service-port'
`zeroconf-service-txt'"
(cond
((equal event :new)
(cl-pushnew function (gethash type zeroconf-service-added-hooks-hash)
:test #'equal)
(dolist (service (zeroconf-list-services type))
(funcall function service)))
((equal event :removed)
(cl-pushnew function (gethash type zeroconf-service-removed-hooks-hash)
:test #'equal))
(t (error "EVENT must be either `:new' or `:removed'"))))