Merge lp:~ricmm/usensord/vibrate-no-sleep into lp:usensord

Proposed by Ricardo Mendoza
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 32
Merged at revision: 24
Proposed branch: lp:~ricmm/usensord/vibrate-no-sleep
Merge into: lp:usensord
Diff against target: 73 lines (+37/-0)
1 file modified
haptic/haptic.go (+37/-0)
To merge this branch: bzr merge lp:~ricmm/usensord/vibrate-no-sleep
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Charles Kerr (community) Approve
Review via email: mp+256612@code.launchpad.net

Commit message

Take a powerd state while theres an active vibration request, also give a grace period after vibration ended before suspending, so as to not peg the hardware actuator if the cpu goes offline before the end timer has expired.

To post a comment you must log in.
lp:~ricmm/usensord/vibrate-no-sleep updated
25. By Ricardo Mendoza

Fix indentation

26. By Ricardo Mendoza

Reduce timeout to 1.5s

27. By Ricardo Mendoza

Make sure cookie is not null before attempting to clear

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~ricmm/usensord/vibrate-no-sleep updated
28. By Ricardo Mendoza

Dont stack locks

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~ricmm/usensord/vibrate-no-sleep updated
29. By Ricardo Mendoza

Only remove the old lock after the new one has been taken, to prevent a few ticks of lock-less processing where we could suspend

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Comments inline

review: Needs Information
lp:~ricmm/usensord/vibrate-no-sleep updated
30. By Ricardo Mendoza

Use global timer instead and keep a mutex-protected single cookie instance

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Some minor comments made to ricmm in irc, but otherwise this LGTM.

review: Approve
lp:~ricmm/usensord/vibrate-no-sleep updated
31. By Ricardo Mendoza

Move into individual vibration block

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~ricmm/usensord/vibrate-no-sleep updated
32. By Ricardo Mendoza

Reduce mutex scope and make sure lock also takes into consideration the sleep time

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Looking good, working as expected.

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-06-27 19:31:59 +0000
3+++ haptic/haptic.go 2015-04-22 23:10:57 +0000
4@@ -33,8 +33,13 @@
5
6 var (
7 conn *dbus.Connection
8+ sysbus *dbus.Connection
9 logger *log.Logger
10 wg sync.WaitGroup
11+ powerd *dbus.ObjectProxy
12+ mutex *sync.Mutex
13+ cookie string
14+ timer *time.Timer
15 )
16
17 const (
18@@ -118,6 +123,29 @@
19 x := true
20 for _, t := range duration {
21 if x {
22+ mutex.Lock();
23+ if (cookie == "") {
24+ reply, err := powerd.Call("com.canonical.powerd", "requestSysState", "usensord", int32(1))
25+ if err != nil {
26+ logger.Println("Cannot request Powerd system power state: ", err)
27+ } else {
28+ if err := reply.Args(&cookie); err == nil {
29+ logger.Println("Suspend blocker cookie: ", cookie)
30+ timer = time.NewTimer(time.Duration(t + 1500) * time.Millisecond)
31+ go func() {
32+ <-timer.C
33+ logger.Println("Clearing suspend blocker")
34+ if cookie != "" {
35+ powerd.Call("com.canonical.powerd", "clearSysState", string(cookie))
36+ cookie = ""
37+ }
38+ }()
39+ }
40+ }
41+ } else {
42+ timer.Reset(time.Duration(t + 1500) * time.Millisecond)
43+ }
44+ mutex.Unlock()
45 if _, err := fi.WriteString(fmt.Sprintf("%d", t)); err != nil {
46 logger.Println(err)
47 }
48@@ -129,6 +157,7 @@
49 }
50 }
51 }()
52+
53 return nil
54 }
55
56@@ -141,9 +170,17 @@
57 return err
58 }
59
60+ if sysbus, err = dbus.Connect(dbus.SystemBus); err != nil {
61+ logger.Fatal("Connection error:", err)
62+ return err
63+ }
64+
65 name := conn.RequestName("com.canonical.usensord", dbus.NameFlagDoNotQueue)
66 logger.Printf("Successfully registered %s on the bus", name.Name)
67
68+ powerd = sysbus.Object("com.canonical.powerd", "/com/canonical/powerd")
69+ mutex = &sync.Mutex{}
70+
71 ch := make(chan *dbus.Message)
72 go watchDBusMethodCalls(ch)
73 conn.RegisterObjectPath("/com/canonical/usensord/haptic", ch)

Subscribers

People subscribed via source and target branches