45
45
func watchDBusMethodCalls(msgChan <-chan *dbus.Message) {
46
var reply *dbus.Message
48
46
for msg := range msgChan {
50
case msg.Interface == HAPTIC_DBUS_IFACE && msg.Member == "Vibrate":
53
logger.Printf("Received Vibrate() method call %d", duration)
54
if err := Vibrate(duration); err != nil {
55
reply = dbus.NewErrorMessage(msg, "com.canonical.usensord.Error", err.Error())
57
reply = dbus.NewMethodReturnMessage(msg)
59
case msg.Interface == HAPTIC_DBUS_IFACE && msg.Member == "VibratePattern":
62
msg.Args(&pattern, &repeat)
63
logger.Print("Received VibratePattern() method call ", pattern, " ", repeat)
64
if err := VibratePattern(pattern, repeat); err != nil {
65
reply = dbus.NewErrorMessage(msg, "com.canonical.usensord.Error", err.Error())
67
reply = dbus.NewMethodReturnMessage(msg)
70
logger.Println("Received unkown method call on", msg.Interface, msg.Member)
71
reply = dbus.NewErrorMessage(msg, "org.freedesktop.DBus.Error.UnknownMethod", "Unknown method")
47
var reply *dbus.Message
49
if msg.Interface == HAPTIC_DBUS_IFACE {
50
reply = handleHapticInterface(msg)
52
reply = dbus.NewErrorMessage(
54
"org.freedesktop.DBus.Error.UnknownInterface",
55
fmt.Sprintf("No such interface '%s' at object path '%s'", msg.Interface, msg.Path))
73
58
if err := conn.Send(reply); err != nil {
74
59
logger.Println("Could not send reply:", err)
64
func handleHapticInterface(msg *dbus.Message) (reply *dbus.Message) {
69
logger.Printf("Received Vibrate() method call %d", duration)
70
if err := Vibrate(duration); err != nil {
71
reply = dbus.NewErrorMessage(msg, "com.canonical.usensord.Error", err.Error())
73
reply = dbus.NewMethodReturnMessage(msg)
75
case "VibratePattern":
78
msg.Args(&pattern, &repeat)
79
logger.Print("Received VibratePattern() method call ", pattern, " ", repeat)
80
if err := VibratePattern(pattern, repeat); err != nil {
81
reply = dbus.NewErrorMessage(msg, "com.canonical.usensord.Error", err.Error())
83
reply = dbus.NewMethodReturnMessage(msg)
86
logger.Println("Received unkown method call on", msg.Interface, msg.Member)
87
reply = dbus.NewErrorMessage(msg, "org.freedesktop.DBus.Error.UnknownMethod", "Unknown method")
79
92
// Vibrate generates a vibration with the specified duration
80
93
// If the haptic device used to generate the vibration cannot be opened
81
94
// an error is returned in err.