Merge lp:~chipaca/ubuntu-push/new-nm-api into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 20
Merged at revision: 13
Proposed branch: lp:~chipaca/ubuntu-push/new-nm-api
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/connectivity
Diff against target: 94 lines (+38/-2)
4 files modified
bus/endpoint.go (+23/-0)
bus/testing/testing_endpoint.go (+5/-0)
bus/testing/testing_endpoint_test.go (+9/-0)
networkmanager/networkmanager.go (+1/-2)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/new-nm-api
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+202359@code.launchpad.net

Commit message

Switched networkmanager to use the non-deprecated api for
state.

Description of the change

Switched networkmanager to use the non-deprecated api for
state. Needed adding GetProperty for that...

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bus/endpoint.go'
2--- bus/endpoint.go 2014-01-20 13:45:30 +0000
3+++ bus/endpoint.go 2014-01-20 18:16:27 +0000
4@@ -19,6 +19,7 @@
5 // Here we define the Endpoint, which represents the DBus connection itself.
6
7 import (
8+ "errors"
9 "launchpad.net/go-dbus/v1"
10 "launchpad.net/ubuntu-push/logger"
11 )
12@@ -31,6 +32,7 @@
13 type Endpoint interface {
14 WatchSignal(member string, f func(interface{}), d func()) error
15 Call(member string, args ...interface{}) (interface{}, error)
16+ GetProperty(property string) (interface{}, error)
17 Close()
18 }
19
20@@ -84,6 +86,27 @@
21 }
22 }
23
24+// GetProperty uses the org.freedesktop.DBus.Properties interface's Get method
25+// to read a given property on the name, path and interface provided when
26+// creating the endpoint. The return value is unpacked into a dbus.Variant,
27+// and its value returned.
28+func (endp endpoint) GetProperty(property string) (interface{}, error) {
29+ proxy := endp.bus.Object(endp.name, dbus.ObjectPath(endp.path))
30+ msg, err := proxy.Call("org.freedesktop.DBus.Properties", "Get", endp.iface, property)
31+ if err != nil {
32+ return nil, err
33+ }
34+ variantv, err := endp.unpackOneMsg(msg, property)
35+ if err != nil {
36+ return nil, err
37+ }
38+ variant, ok := variantv.(*dbus.Variant)
39+ if !ok {
40+ return nil, errors.New("Response from Properties.Get wasn't a *dbus.Variant")
41+ }
42+ return variant.Value, nil
43+}
44+
45 // Close the connection to dbus.
46 func (endp endpoint) Close() {
47 endp.bus.Close()
48
49=== modified file 'bus/testing/testing_endpoint.go'
50--- bus/testing/testing_endpoint.go 2014-01-20 13:45:30 +0000
51+++ bus/testing/testing_endpoint.go 2014-01-20 18:16:27 +0000
52@@ -69,6 +69,11 @@
53 }
54 }
55
56+// See Endpoint's GetProperty. This one is just another name for Call.
57+func (tc *testingEndpoint) GetProperty(property string) (interface{}, error) {
58+ return tc.Call(property)
59+}
60+
61 // see Endpoint's Close. This one does nothing.
62 func (tc *testingEndpoint) Close() {}
63
64
65=== modified file 'bus/testing/testing_endpoint_test.go'
66--- bus/testing/testing_endpoint_test.go 2014-01-20 12:36:21 +0000
67+++ bus/testing/testing_endpoint_test.go 2014-01-20 18:16:27 +0000
68@@ -71,3 +71,12 @@
69 e := endp.WatchSignal("what", func(u interface{}) {}, func() {})
70 c.Check(e, NotNil)
71 }
72+
73+// Tests that GetProperty() works
74+func (s *TestingEndpointSuite) TestGetProperty(c *C) {
75+ var m uint32 = 42
76+ endp := NewTestingEndpoint(condition.Work(true), m)
77+ v, e := endp.GetProperty("what")
78+ c.Check(e, IsNil)
79+ c.Check(v, Equals, m)
80+}
81
82=== modified file 'networkmanager/networkmanager.go'
83--- networkmanager/networkmanager.go 2014-01-20 18:16:27 +0000
84+++ networkmanager/networkmanager.go 2014-01-20 18:16:27 +0000
85@@ -61,8 +61,7 @@
86 */
87
88 func (nm *networkManager) GetState() State {
89- s, err := nm.bus.Call("state")
90-
91+ s, err := nm.bus.GetProperty("state")
92 if err != nil {
93 nm.log.Errorf("Failed gettting current state: %s", err)
94 nm.log.Debugf("Defaulting state to Unknown")

Subscribers

People subscribed via source and target branches