Merge lp:~chipaca/ubuntu-push/notifications into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: no longer in the source branch.
Merged at revision: 18
Proposed branch: lp:~chipaca/ubuntu-push/notifications
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/multi-valued
Diff against target: 256 lines (+197/-8)
3 files modified
connectivity/connectivity_test.go (+6/-8)
notifications/raw.go (+97/-0)
notifications/raw_test.go (+94/-0)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/notifications
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+202477@code.launchpad.net

Commit message

notifications! first, a low-level api.

Description of the change

Implemented a low-level notifications API.

To post a comment you must log in.
Revision history for this message
Samuele Pedroni (pedronis) wrote :

we have a lot of things that are notifications, wondering if we need a more precise package name

// New returns a new Notifications that'll use the provided bus.Endpoint

it's called Raw and takes a bus.Bus

maybe the Raw* types need a short descr as well

of course this will need some integration testing involving qa

review: Approve
Revision history for this message
John Lenton (chipaca) wrote :

Fixed the comment, added a short desc to the Raw* types.
I'm all ears for suggestions for names...

Revision history for this message
Samuele Pedroni (pedronis) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

The attempt to merge lp:~chipaca/ubuntu-push/notifications into lp:ubuntu-push failed. Below is the output from the failed tests.

mkdir -p /mnt/tarmac/cache/ubuntu-push/go-ws/bin
mkdir -p /mnt/tarmac/cache/ubuntu-push/go-ws/pkg
go get -u launchpad.net/godeps
go get -d -u launchpad.net/gocheck launchpad.net/go-dbus/v1
/mnt/tarmac/cache/ubuntu-push/go-ws/bin/godeps -u dependencies.tsv
go install launchpad.net/gocheck launchpad.net/go-dbus/v1
go test launchpad.net/ubuntu-push/...
ok launchpad.net/ubuntu-push/bus 0.009s
ok launchpad.net/ubuntu-push/bus/testing 0.024s
ok launchpad.net/ubuntu-push/config 0.009s
ok launchpad.net/ubuntu-push/connectivity 0.102s
? launchpad.net/ubuntu-push/connectivity/example [no test files]
ok launchpad.net/ubuntu-push/connectivity/webchecker 0.018s
ok launchpad.net/ubuntu-push/logger 0.006s
ok launchpad.net/ubuntu-push/networkmanager 0.036s
ok launchpad.net/ubuntu-push/notifications 0.016s
ok launchpad.net/ubuntu-push/protocol 0.012s
ok launchpad.net/ubuntu-push/server/acceptance 0.006s
? launchpad.net/ubuntu-push/server/acceptance/cmd [no test files]
ok launchpad.net/ubuntu-push/server/api 0.015s
ok launchpad.net/ubuntu-push/server/broker 0.007s
ok launchpad.net/ubuntu-push/server/dev 0.027s
ok launchpad.net/ubuntu-push/server/listener 0.358s
ok launchpad.net/ubuntu-push/server/session 0.074s
ok launchpad.net/ubuntu-push/server/store 0.006s
? launchpad.net/ubuntu-push/testing [no test files]
ok launchpad.net/ubuntu-push/testing/condition 0.004s
ok launchpad.net/ubuntu-push/whoopsie/identifier 0.018s
ok launchpad.net/ubuntu-push/whoopsie/identifier/testing 0.018s
scripts/check_fmt launchpad.net/ubuntu-push
pkg launchpad.net/ubuntu-push/connectivity has some gofmt non-compliant files:
connectivity_test.go

make: *** [check-format] Error 1

18. By John Lenton

[r=pedronis] notifications! first, a low-level api.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'connectivity/connectivity_test.go'
--- connectivity/connectivity_test.go 2014-01-20 17:37:55 +0000
+++ connectivity/connectivity_test.go 2014-01-22 12:27:44 +0000
@@ -128,11 +128,11 @@
128*/128*/
129129
130func (s *ConnSuite) TestSteps(c *C) {130func (s *ConnSuite) TestSteps(c *C) {
131 webget_works := func(ch chan<- bool) { ch <- true }131 var webget_p condition.Interface = condition.Work(true)
132 webget_fails := func(ch chan<- bool) { ch <- false }132 recheck_timeout := 50 * time.Millisecond
133133
134 cfg := Config{134 cfg := Config{
135 RecheckTimeout: config.ConfigTimeDuration{10 * time.Millisecond},135 RecheckTimeout: config.ConfigTimeDuration{recheck_timeout},
136 }136 }
137 ch := make(chan networkmanager.State, 10)137 ch := make(chan networkmanager.State, 10)
138 cs := &connectedState{138 cs := &connectedState{
@@ -140,7 +140,7 @@
140 networkStateCh: ch,140 networkStateCh: ch,
141 timer: time.NewTimer(time.Second),141 timer: time.NewTimer(time.Second),
142 log: nullog,142 log: nullog,
143 webget: webget_works,143 webget: func(ch chan<- bool) { ch <- webget_p.OK() },
144 lastSent: false,144 lastSent: false,
145 }145 }
146 ch <- networkmanager.ConnectedGlobal146 ch <- networkmanager.ConnectedGlobal
@@ -156,7 +156,7 @@
156 c.Check(f, Equals, true) // and if the web check works, go back to connected156 c.Check(f, Equals, true) // and if the web check works, go back to connected
157157
158 // same scenario, but with failing web check158 // same scenario, but with failing web check
159 cs.webget = webget_fails159 webget_p = condition.Fail2Work(1)
160 ch <- networkmanager.ConnectedGlobal160 ch <- networkmanager.ConnectedGlobal
161 f, e = cs.connectedStateStep()161 f, e = cs.connectedStateStep()
162 c.Check(e, IsNil)162 c.Check(e, IsNil)
@@ -164,7 +164,7 @@
164164
165 // the next call to Step will time out165 // the next call to Step will time out
166 _ch := make(chan bool, 1)166 _ch := make(chan bool, 1)
167 _t := time.NewTimer(10 * time.Millisecond)167 _t := time.NewTimer(recheck_timeout / 2)
168168
169 go func() {169 go func() {
170 f, e := cs.connectedStateStep()170 f, e := cs.connectedStateStep()
@@ -178,8 +178,6 @@
178 case <-_t.C:178 case <-_t.C:
179 }179 }
180180
181 // put it back together again
182 cs.webget = webget_works
183 // now an recheckTimeout later, we'll get true181 // now an recheckTimeout later, we'll get true
184 c.Check(<-_ch, Equals, true)182 c.Check(<-_ch, Equals, true)
185183
186184
=== added directory 'notifications'
=== added file 'notifications/raw.go'
--- notifications/raw.go 1970-01-01 00:00:00 +0000
+++ notifications/raw.go 2014-01-22 12:27:44 +0000
@@ -0,0 +1,97 @@
1/*
2 Copyright 2013-2014 Canonical Ltd.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published
6 by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranties of
10 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program. If not, see <http://www.gnu.org/licenses/>.
15*/
16
17// Package notifications wraps a couple of Notifications's DBus API points:
18// the org.freedesktop.Notifications.Notify call, and listening for the
19// ActionInvoked signal.
20package notifications
21
22// this is the lower-level api
23
24import (
25 "launchpad.net/go-dbus/v1"
26 "launchpad.net/ubuntu-push/bus"
27 "launchpad.net/ubuntu-push/logger"
28)
29
30// Notifications lives on a well-knwon bus.Address
31var BusAddress bus.Address = bus.Address{
32 Interface: "org.freedesktop.Notifications",
33 Path: "/org/freedesktop/Notifications",
34 Name: "org.freedesktop.Notifications",
35}
36
37/*****************************************************************
38 * RawNotifications
39 */
40
41// convenience type for the (uint32, string) ActionInvoked signal data
42type RawActionReply struct {
43 NotificationId uint32
44 ActionId string
45}
46
47// a raw notification provides a low-level interface to the f.d.o. dbus
48// notifications api
49type RawNotifications struct {
50 bus bus.Endpoint
51 log logger.Logger
52}
53
54// Raw returns a new RawNotifications connected to the provided bus.Bus
55func Raw(bt bus.Bus, log logger.Logger) (*RawNotifications, error) {
56 endp, err := bt.Connect(BusAddress, log)
57 if err != nil {
58 return nil, err
59 }
60
61 return &RawNotifications{endp, log}, nil
62}
63
64/*
65 public methods
66*/
67
68// Notify fires a notification
69func (raw *RawNotifications) Notify(
70 app_name string, reuse_id uint32,
71 icon, summary, body string,
72 actions []string, hints map[string]*dbus.Variant,
73 timeout int32) (uint32, error) {
74 // that's a long argument list! Take a breather.
75 //
76 rv, err := raw.bus.Call("Notify", app_name, reuse_id, icon,
77 summary, body, actions, hints, timeout)
78 if err != nil {
79 return 0, err
80 }
81 return rv.(uint32), nil
82}
83
84// WatchActions listens for ActionInvoked signals from the notification daemon
85// and sends them over the channel provided
86func (raw *RawNotifications) WatchActions() (<-chan RawActionReply, error) {
87 ch := make(chan RawActionReply)
88 err := raw.bus.WatchSignal("ActionInvoked",
89 func(ns ...interface{}) {
90 ch <- RawActionReply{ns[0].(uint32), ns[1].(string)}
91 }, func() { close(ch) })
92 if err != nil {
93 raw.log.Debugf("Failed to set up the watch: %s", err)
94 return nil, err
95 }
96 return ch, nil
97}
098
=== added file 'notifications/raw_test.go'
--- notifications/raw_test.go 1970-01-01 00:00:00 +0000
+++ notifications/raw_test.go 2014-01-22 12:27:44 +0000
@@ -0,0 +1,94 @@
1/*
2 Copyright 2013-2014 Canonical Ltd.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published
6 by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranties of
10 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program. If not, see <http://www.gnu.org/licenses/>.
15*/
16
17// Package notifications wraps a couple of Notifications's DBus API points:
18// the org.freedesktop.Notifications.Notify call, and listening for the
19// ActionInvoked signal.
20package notifications
21
22import (
23 "io/ioutil"
24 . "launchpad.net/gocheck"
25 testibus "launchpad.net/ubuntu-push/bus/testing"
26 "launchpad.net/ubuntu-push/logger"
27 "launchpad.net/ubuntu-push/testing/condition"
28 "testing"
29 "time"
30)
31
32// hook up gocheck
33func TestRaw(t *testing.T) { TestingT(t) }
34
35type RawSuite struct{}
36
37var _ = Suite(&RawSuite{})
38
39var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
40
41func (s *RawSuite) TestConnects(c *C) {
42 bus := testibus.NewTestingBus(condition.Work(false), condition.Work(false))
43 _, err := Raw(bus, nullog)
44 c.Check(err, NotNil)
45 bus = testibus.NewTestingBus(condition.Work(true), condition.Work(false))
46 _, err = Raw(bus, nullog)
47 c.Check(err, IsNil)
48}
49
50func (s *RawSuite) TestNotifies(c *C) {
51 bus := testibus.NewTestingBus(condition.Work(true), condition.Work(true),
52 uint32(1))
53 raw, err := Raw(bus, nullog)
54 c.Assert(err, IsNil)
55 nid, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
56 c.Check(err, IsNil)
57 c.Check(nid, Equals, uint32(1))
58}
59
60func (s *RawSuite) TestNotifiesFails(c *C) {
61 bus := testibus.NewTestingBus(condition.Work(true), condition.Work(false))
62 raw, err := Raw(bus, nullog)
63 c.Assert(err, IsNil)
64 _, err = raw.Notify("", 0, "", "", "", nil, nil, 0)
65 c.Check(err, NotNil)
66}
67
68func (s *RawSuite) TestWatchActions(c *C) {
69 bus := testibus.NewMultiValuedTestingBus(condition.Work(true), condition.Work(true),
70 []interface{}{uint32(1), "hello"})
71 raw, err := Raw(bus, nullog)
72 c.Assert(err, IsNil)
73 ch, err := raw.WatchActions()
74 c.Assert(err, IsNil)
75 // check we get the right action reply
76 select {
77 case p := <-ch:
78 c.Check(p.NotificationId, Equals, uint32(1))
79 c.Check(p.ActionId, Equals, "hello")
80 case <-time.NewTimer(time.Second / 10).C:
81 c.Error("timed out?")
82 }
83 // and that the channel is closed if/when the watch fails
84 _, ok := <-ch
85 c.Check(ok, Equals, false)
86}
87
88func (s *RawSuite) TestWatchActionsFails(c *C) {
89 bus := testibus.NewTestingBus(condition.Work(true), condition.Work(false))
90 raw, err := Raw(bus, nullog)
91 c.Assert(err, IsNil)
92 _, err = raw.WatchActions()
93 c.Check(err, NotNil)
94}

Subscribers

People subscribed via source and target branches