diff options
author | Michael Olbrich <m.olbrich@pengutronix.de> | 2010-06-03 12:49:08 +0200 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2010-06-03 12:49:08 +0200 |
commit | 00596b2ccc97fc4864202ff0efb546f937c0aa6b (patch) | |
tree | a880cfd56b8c97de7ebe9729c5bafae20060f19e | |
parent | c60d54e06ed08498e9a50ea2aaff68a0646544bc (diff) | |
download | json-dbus-bridge-examples-00596b2ccc97fc4864202ff0efb546f937c0aa6b.tar.gz json-dbus-bridge-examples-00596b2ccc97fc4864202ff0efb546f937c0aa6b.tar.xz |
[service] Calculator: handle division by zero
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rwxr-xr-x | services/python/calculator.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/services/python/calculator.py b/services/python/calculator.py index 50674d9..cebcee4 100755 --- a/services/python/calculator.py +++ b/services/python/calculator.py @@ -38,9 +38,13 @@ class Service(dbus.service.Object): return a * b @dbus.service.method("com.pengutronix.jdb.Calculator", - in_signature='ii', out_signature='i') - def Divide(self, a, b): - return a / b + in_signature='ii', out_signature='i', + async_callbacks = ("value", "error")) + def Divide(self, a, b, value, error): + if b == 0: + error("division by zero") + else: + value(a/b) dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |