Merge lp:~sergiusens/usensord/interface_unknown into lp:usensord

Proposed by Sergio Schvezov
Status: Merged
Approved by: Michael Frey
Approved revision: 22
Merged at revision: 22
Proposed branch: lp:~sergiusens/usensord/interface_unknown
Merge into: lp:usensord
Diff against target: 81 lines (+38/-25)
1 file modified
haptic/haptic.go (+38/-25)
To merge this branch: bzr merge lp:~sergiusens/usensord/interface_unknown
Reviewer Review Type Date Requested Status
Michael Frey (community) Approve
Review via email: mp+224892@code.launchpad.net

Commit message

Returning a UnknownInterface dbus error when recving a message not on the haptic interface.

Description of the change

You can quickly test like this:

$ dbus-send --session --type=method_call --print-reply --dest=com.canonical.usensord /com/canonical/usensord/haptic com.canonical.usensord.haptic.Vibrate int32:10
Error com.canonical.usensord.Error: open /sys/class/timed_output/vibrator/enable: no such file or directory
$ dbus-send --session --type=method_call --print-reply --dest=com.canonical.usensord /com/canonical/usensord/haptic org.freedesktop.DBus.Introspectable.Introspect
Error org.freedesktop.DBus.Error.UnknownInterface: No such interface 'org.freedesktop.DBus.Introspectable' at object path '/com/canonical/usensord/haptic'

To post a comment you must log in.
Revision history for this message
Michael Frey (mfrey) wrote :

works.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'haptic/haptic.go'
2--- haptic/haptic.go 2014-05-28 08:27:55 +0000
3+++ haptic/haptic.go 2014-06-27 19:34:15 +0000
4@@ -43,39 +43,52 @@
5 )
6
7 func watchDBusMethodCalls(msgChan <-chan *dbus.Message) {
8- var reply *dbus.Message
9-
10 for msg := range msgChan {
11- switch {
12- case msg.Interface == HAPTIC_DBUS_IFACE && msg.Member == "Vibrate":
13- var duration uint32
14- msg.Args(&duration)
15- logger.Printf("Received Vibrate() method call %d", duration)
16- if err := Vibrate(duration); err != nil {
17- reply = dbus.NewErrorMessage(msg, "com.canonical.usensord.Error", err.Error())
18- } else {
19- reply = dbus.NewMethodReturnMessage(msg)
20- }
21- case msg.Interface == HAPTIC_DBUS_IFACE && msg.Member == "VibratePattern":
22- var pattern []uint32
23- var repeat uint32
24- msg.Args(&pattern, &repeat)
25- logger.Print("Received VibratePattern() method call ", pattern, " ", repeat)
26- if err := VibratePattern(pattern, repeat); err != nil {
27- reply = dbus.NewErrorMessage(msg, "com.canonical.usensord.Error", err.Error())
28- } else {
29- reply = dbus.NewMethodReturnMessage(msg)
30- }
31- default:
32- logger.Println("Received unkown method call on", msg.Interface, msg.Member)
33- reply = dbus.NewErrorMessage(msg, "org.freedesktop.DBus.Error.UnknownMethod", "Unknown method")
34+ var reply *dbus.Message
35+
36+ if msg.Interface == HAPTIC_DBUS_IFACE {
37+ reply = handleHapticInterface(msg)
38+ } else {
39+ reply = dbus.NewErrorMessage(
40+ msg,
41+ "org.freedesktop.DBus.Error.UnknownInterface",
42+ fmt.Sprintf("No such interface '%s' at object path '%s'", msg.Interface, msg.Path))
43 }
44+
45 if err := conn.Send(reply); err != nil {
46 logger.Println("Could not send reply:", err)
47 }
48 }
49 }
50
51+func handleHapticInterface(msg *dbus.Message) (reply *dbus.Message) {
52+ switch msg.Member {
53+ case "Vibrate":
54+ var duration uint32
55+ msg.Args(&duration)
56+ logger.Printf("Received Vibrate() method call %d", duration)
57+ if err := Vibrate(duration); err != nil {
58+ reply = dbus.NewErrorMessage(msg, "com.canonical.usensord.Error", err.Error())
59+ } else {
60+ reply = dbus.NewMethodReturnMessage(msg)
61+ }
62+ case "VibratePattern":
63+ var pattern []uint32
64+ var repeat uint32
65+ msg.Args(&pattern, &repeat)
66+ logger.Print("Received VibratePattern() method call ", pattern, " ", repeat)
67+ if err := VibratePattern(pattern, repeat); err != nil {
68+ reply = dbus.NewErrorMessage(msg, "com.canonical.usensord.Error", err.Error())
69+ } else {
70+ reply = dbus.NewMethodReturnMessage(msg)
71+ }
72+ default:
73+ logger.Println("Received unkown method call on", msg.Interface, msg.Member)
74+ reply = dbus.NewErrorMessage(msg, "org.freedesktop.DBus.Error.UnknownMethod", "Unknown method")
75+ }
76+ return reply
77+}
78+
79 // Vibrate generates a vibration with the specified duration
80 // If the haptic device used to generate the vibration cannot be opened
81 // an error is returned in err.

Subscribers

People subscribed via source and target branches