Mercurial > emacs
comparison doc/misc/dbus.texi @ 97253:cd0a7b292982
* dbus.texi (Receiving Method Calls): Document error handling of own
D-Bus methods.
author | Michael Albinus <michael.albinus@gmx.de> |
---|---|
date | Sun, 03 Aug 2008 17:14:14 +0000 |
parents | 48b3629e41d1 |
children | 6de181810d0f |
comparison
equal
deleted
inserted
replaced
97252:c2be97b488c4 | 97253:cd0a7b292982 |
---|---|
1217 (dbus-register-method | 1217 (dbus-register-method |
1218 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor" | 1218 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor" |
1219 "org.freedesktop.TextEditor" "OpenFile" | 1219 "org.freedesktop.TextEditor" "OpenFile" |
1220 'my-dbus-method-handler) | 1220 'my-dbus-method-handler) |
1221 | 1221 |
1222 @result{} ((:system "org.freedesktop.TextEditor" "OpenFile") | 1222 @result{} ((:session "org.freedesktop.TextEditor" "OpenFile") |
1223 ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor" | 1223 ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor" |
1224 my-method-handler)) | 1224 my-dbus-method-handler)) |
1225 @end lisp | 1225 @end lisp |
1226 | 1226 |
1227 If you invoke the method @samp{org.freedesktop.TextEditor.OpenFile} | 1227 If you invoke the method @samp{org.freedesktop.TextEditor.OpenFile} |
1228 from another D-Bus application with a filename as parameter, the file | 1228 from another D-Bus application with a filename as parameter, the file |
1229 is opened in Emacs, and the method returns either @var{true} or | 1229 is opened in Emacs, and the method returns either @var{true} or |
1235 --dest="org.freedesktop.TextEditor" \ | 1235 --dest="org.freedesktop.TextEditor" \ |
1236 "/org/freedesktop/TextEditor" \ | 1236 "/org/freedesktop/TextEditor" \ |
1237 "org.freedesktop.TextEditor.OpenFile" string:"/etc/hosts" | 1237 "org.freedesktop.TextEditor.OpenFile" string:"/etc/hosts" |
1238 | 1238 |
1239 @print{} method return sender=:1.22 -> dest=:1.23 reply_serial=2 | 1239 @print{} method return sender=:1.22 -> dest=:1.23 reply_serial=2 |
1240 boolean true | 1240 boolean true |
1241 @end example | |
1242 | |
1243 You can indicate an error by raising the Emacs signal | |
1244 @code{dbus-error}. The handler above could be changed like this: | |
1245 | |
1246 @lisp | |
1247 (defun my-dbus-method-handler (&rest args) | |
1248 (unless (and (= (length args) 1) (stringp (car args))) | |
1249 (signal 'dbus-error (list (format "Wrong argument list: %S" args)))) | |
1250 (condition-case err | |
1251 (find-file (car args)) | |
1252 (error (signal 'dbus-error (cdr err)))) | |
1253 t) | |
1254 | |
1255 @result{} my-dbus-method-handler | |
1256 @end lisp | |
1257 | |
1258 The test runs then | |
1259 | |
1260 @example | |
1261 # dbus-send --session --print-reply \ | |
1262 --dest="org.freedesktop.TextEditor" \ | |
1263 "/org/freedesktop/TextEditor" \ | |
1264 "org.freedesktop.TextEditor.OpenFile" \ | |
1265 string:"/etc/hosts" string:"/etc/passwd" | |
1266 | |
1267 @print{} Error org.freedesktop.DBus.Error.Failed: | |
1268 Wrong argument list: ("/etc/hosts" "/etc/passwd") | |
1241 @end example | 1269 @end example |
1242 @end defun | 1270 @end defun |
1243 | 1271 |
1244 | 1272 |
1245 @node Signals | 1273 @node Signals |