aboutsummaryrefslogtreecommitdiffstats
path: root/doc/misc/dbus.texi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/misc/dbus.texi')
-rw-r--r--doc/misc/dbus.texi151
1 files changed, 71 insertions, 80 deletions
diff --git a/doc/misc/dbus.texi b/doc/misc/dbus.texi
index 59685087ae8..5b302c883ad 100644
--- a/doc/misc/dbus.texi
+++ b/doc/misc/dbus.texi
@@ -64,7 +64,7 @@ another. An overview of D-Bus can be found at
64* Alternative Buses:: Alternative buses and environments. 64* Alternative Buses:: Alternative buses and environments.
65* Errors and Events:: Errors and events. 65* Errors and Events:: Errors and events.
66* Monitoring Messages:: Monitoring messages. 66* Monitoring Messages:: Monitoring messages.
67* Inhibitor Locks:: Inhibit system shutdowns and sleep states. 67* File Descriptors:: Handle file descriptors.
68* Index:: Index including concepts, functions, variables. 68* Index:: Index including concepts, functions, variables.
69 69
70* GNU Free Documentation License:: The license for this documentation. 70* GNU Free Documentation License:: The license for this documentation.
@@ -1212,7 +1212,7 @@ which carries the input parameters to the object owning the method to
1212be called, and a reply message returning the resulting output 1212be called, and a reply message returning the resulting output
1213parameters from the object. 1213parameters from the object.
1214 1214
1215@defun dbus-call-method bus service path interface method &optional :timeout timeout :authorizable auth &rest args 1215@defun dbus-call-method bus service path interface method &optional :timeout timeout :authorizable auth :keep-fd &rest args
1216@anchor{dbus-call-method} 1216@anchor{dbus-call-method}
1217This function calls @var{method} on the D-Bus @var{bus}. @var{bus} is 1217This function calls @var{method} on the D-Bus @var{bus}. @var{bus} is
1218either the keyword @code{:system} or the keyword @code{:session}. 1218either the keyword @code{:system} or the keyword @code{:session}.
@@ -1245,6 +1245,11 @@ running):
1245@result{} "/org/freedesktop/systemd1/job/17508" 1245@result{} "/org/freedesktop/systemd1/job/17508"
1246@end lisp 1246@end lisp
1247 1247
1248If the parameter @code{:keep-fd} is given, and the return message has a
1249first argument with a D-Bus type @code{:unix-fd}, the returned file
1250descriptor is kept internally, and can be used in a later call of
1251@code{dbus--close-fd} (@pxref{File Descriptors}).
1252
1248The remaining arguments @var{args} are passed to @var{method} as 1253The remaining arguments @var{args} are passed to @var{method} as
1249arguments. They are converted into D-Bus types as described in 1254arguments. They are converted into D-Bus types as described in
1250@ref{Type Conversion}. 1255@ref{Type Conversion}.
@@ -1324,7 +1329,7 @@ emulate the @code{lshal} command on GNU/Linux systems:
1324@cindex method calls, asynchronous 1329@cindex method calls, asynchronous
1325@cindex asynchronous method calls 1330@cindex asynchronous method calls
1326 1331
1327@defun dbus-call-method-asynchronously bus service path interface method handler &optional :timeout timeout :authorizable auth &rest args 1332@defun dbus-call-method-asynchronously bus service path interface method handler &optional :timeout timeout :authorizable auth :keep-fd &rest args
1328This function calls @var{method} on the D-Bus @var{bus} 1333This function calls @var{method} on the D-Bus @var{bus}
1329asynchronously. @var{bus} is either the keyword @code{:system} or the 1334asynchronously. @var{bus} is either the keyword @code{:system} or the
1330keyword @code{:session}. 1335keyword @code{:session}.
@@ -1347,6 +1352,11 @@ If the parameter @code{:authorizable} is given and the following
1347@var{auth} is non-@code{nil}, the invoked method may interactively 1352@var{auth} is non-@code{nil}, the invoked method may interactively
1348prompt the user for authorization. The default is @code{nil}. 1353prompt the user for authorization. The default is @code{nil}.
1349 1354
1355If the parameter @code{:keep-fd} is given, and the return message has a
1356first argument with a D-Bus type @code{:unix-fd}, the returned file
1357descriptor is kept internally, and can be used in a later call of
1358@code{dbus--close-fd} (@pxref{File Descriptors}).
1359
1350The remaining arguments @var{args} are passed to @var{method} as 1360The remaining arguments @var{args} are passed to @var{method} as
1351arguments. They are converted into D-Bus types as described in 1361arguments. They are converted into D-Bus types as described in
1352@ref{Type Conversion}. 1362@ref{Type Conversion}.
@@ -2205,109 +2215,90 @@ switches to the monitor buffer.
2205@end deffn 2215@end deffn
2206 2216
2207 2217
2208@node Inhibitor Locks 2218@node File Descriptors
2209@chapter Inhibit system shutdowns and sleep states 2219@chapter Handle file descriptors
2210
2211@uref{https://systemd.io/INHIBITOR_LOCKS/, Systemd} includes a logic to
2212inhibit system shutdowns and sleep states. It can be controlled by a
2213D-Bus API@footnote{@uref{https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.login1.html}}.
2214Because this API includes handling of file descriptors, not all
2215functions can be implemented by simple D-Bus method calls. Therefore,
2216the following functions are provided.
2217
2218@defun dbus-make-inhibitor-lock what why &optional block
2219This function creates an inhibitor for system shutdowns and sleep states.
2220
2221@var{what} is a colon-separated string of lock types: @samp{shutdown},
2222@samp{sleep}, @samp{idle}, @samp{handle-power-key},
2223@samp{handle-suspend-key}, @samp{handle-hibernate-key},
2224@samp{handle-lid-switch}. Example: @samp{shutdown:idle}.
2225
2226@c@var{who} is a descriptive string of who is taking the lock. If it is
2227@c@code{nil}, it defaults to @samp{Emacs}.
2228 2220
2229@var{why} is a descriptive string of why the lock is taken. Example: 2221Methods offered by the D-Bus API could return a file descriptor, which
2230@samp{Package Update in Progress}. 2222must be handled further. This is indicated by the @code{:keep-fd}
2223parameter when calling the method (@pxref{dbus-call-method}).
2231 2224
2232The optional @var{block} is the mode of the inhibitor lock, either 2225For example, @uref{https://systemd.io/INHIBITOR_LOCKS/, Systemd}
2233@samp{block} (@var{block} is non-@code{nil}), or @samp{delay}. 2226includes a logic to inhibit system shutdowns and sleep states. It can
2234 2227be controlled by a the method @samp{Inhibit} of interface
2235Note, that the @code{who} argument of the inhibitor lock object of the 2228@samp{org.freedesktop.login1.Manager}@footnote{@uref{https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.login1.html}}.
2236systemd manager is always set to the string @samp{Emacs}. 2229This function returns a file descriptor, which must be used to unlock
2237 2230the locked resource, some of which lock the system. In order to keep
2238It returns a file descriptor or @code{nil}, if the lock cannot be 2231this file descriptor internally, the respective D-Bus method call looks
2239acquired. If there is already an inhibitor lock for the triple 2232like (@var{what}, @var{who}, @var{why} and @var{mode} are
2240@code{(WHAT WHY BLOCK)}, this lock is returned. Example: 2233method-specific string arguments)
2241 2234
2242@lisp 2235@lisp
2243(dbus-make-inhibitor-lock "sleep" "Test") 2236(dbus-call-method
2237 :system
2238 "org.freedesktop.login1" "/org/freedesktop/login1"
2239 "org.freedesktop.login1.Manager" "Inhibit"
2240 :keep-fd WHAT WHO WHY MODE)
2244 2241
2245@result{} 25 2242@result{} 25
2246@end lisp 2243@end lisp
2247@end defun
2248 2244
2249@defun dbus-registered-inhibitor-locks 2245The inhibition lock is unlocked, when the returned file descriptor is
2250Return registered inhibitor locks, an alist. 2246removed from the file system. This cannot be achieved on Lisp level.
2251This allows to check, whether other packages of the running Emacs 2247Therefore, there is the function @code{dbus--fd-close} to performs this
2252instance have acquired an inhibitor lock as well. 2248task (see below).
2249
2250@strong{Note}: When the Emacs process itself dies, all such locks are
2251released.
2253 2252
2254An entry in this list is a list @code{(@var{fd} @var{what} @var{why} 2253@strong{Note}: The following functions are internal to the D-Bus
2255@var{block})}. The car of the list is the file descriptor retrieved 2254implementation of Emacs. Use them with care.
2256from a @code{dbus-make-inhibitor-lock} call. The cdr of the list 2255
2257represents the three arguments @code{dbus-make-inhibitor-lock} was 2256@defun dbus--fd-open filename
2258called with. Example: 2257Open @var{filename} and return the respective read-only file descriptor.
2258This is another function to keep a file descriptor internally. The
2259returned file descriptor can be closed by @code{dbus--fd-close}.
2260Example:
2259 2261
2260@lisp 2262@lisp
2261(dbus-registered-inhibitor-locks) 2263(dbus--fd-open "~/.emacs")
2262 2264
2263@result{} ((25 "sleep" "Test" nil)) 2265@result{} 20
2264@end lisp 2266@end lisp
2265@end defun 2267@end defun
2266 2268
2267@defun dbus-close-inhibitor-lock lock 2269@defun dbus--fd-close fd
2268Close inhibitor lock file descriptor. 2270Close file descriptor @var{fd}.
2269 2271@var{fd} must be the result of a @code{dbus-call-method} or
2270@var{lock}, a file descriptor, must be the result of a 2272@code{dbus--fd-open} call, see @code{dbus--registered-fds}. It returns
2271@code{dbus-make-inhibitor-lock} call. It returns @code{t} in case of 2273@code{t} in case of success, or @code{nil} if it isn’t be possible to
2272success, or @code{nil} if it isn't be possible to close the lock, or if 2274close the file descriptor, or if the file descriptor is closed already.
2273the lock is closed already. Example: 2275Example:
2274 2276
2275@lisp 2277@lisp
2276(dbus-close-inhibitor-lock 25) 2278(dbus--fd-close 25)
2277 2279
2278@result{} t 2280@result{} t
2279
2280@end lisp 2281@end lisp
2281@end defun 2282@end defun
2282 2283
2283A typical scenario for these functions is to register for the 2284@defun dbus--registered-fds
2284D-Bus signal @samp{org.freedesktop.login1.Manager.PrepareForSleep}: 2285Return registered file descriptors, an alist.
2286The key is an open file descriptor, retrieved via
2287@code{dbus-call-method} or @code{dbus--open-fd}. The value is a string
2288@var{object-path} or @var{filename}, which represents the arguments the
2289function was called with. Those values are not needed for further
2290operations; they are just shown for information.
2285 2291
2286@lisp 2292This alist allows to check, whether other packages of the running Emacs
2287(defvar my-inhibitor-lock 2293instance have acquired a file descriptor as well. Example:
2288 (dbus-make-inhibitor-lock "sleep" "Test"))
2289 2294
2290(defun my-dbus-PrepareForSleep-handler (start) 2295@lisp
2291 (if start ;; The system goes down for sleep 2296(dbus--registered-fds)
2292 (progn
2293 @dots{}
2294 ;; Release inhibitor lock.
2295 (when (natnump my-inhibitor-lock)
2296 (dbus-close-inhibitor-lock my-inhibitor-lock)
2297 (setq my-inhibitor-lock nil)))
2298 ;; Reacquire inhibitor lock.
2299 (setq my-inhibitor-lock
2300 (dbus-make-inhibitor-lock "sleep" "Test"))))
2301
2302(dbus-register-signal
2303 :system "org.freedesktop.login1" "/org/freedesktop/login1"
2304 "org.freedesktop.login1.Manager" "PrepareForSleep"
2305 #'my-dbus-PrepareForSleep-handler)
2306 2297
2307@result{} ((:signal :system "org.freedesktop.login1.Manager" "PrepareForSleep") 2298@result{} ((20 . "/home/user/.emacs")
2308 ("org.freedesktop.login1" "/org/freedesktop/login1" 2299 (25 . "/org/freedesktop/login1"))
2309 my-dbus-PrepareForSleep-handler))
2310@end lisp 2300@end lisp
2301@end defun
2311 2302
2312 2303
2313@node Index 2304@node Index