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
=== modified file 'bus/endpoint.go'
--- bus/endpoint.go 2014-01-20 13:45:30 +0000
+++ bus/endpoint.go 2014-01-20 18:16:27 +0000
@@ -19,6 +19,7 @@
19// Here we define the Endpoint, which represents the DBus connection itself.19// Here we define the Endpoint, which represents the DBus connection itself.
2020
21import (21import (
22 "errors"
22 "launchpad.net/go-dbus/v1"23 "launchpad.net/go-dbus/v1"
23 "launchpad.net/ubuntu-push/logger"24 "launchpad.net/ubuntu-push/logger"
24)25)
@@ -31,6 +32,7 @@
31type Endpoint interface {32type Endpoint interface {
32 WatchSignal(member string, f func(interface{}), d func()) error33 WatchSignal(member string, f func(interface{}), d func()) error
33 Call(member string, args ...interface{}) (interface{}, error)34 Call(member string, args ...interface{}) (interface{}, error)
35 GetProperty(property string) (interface{}, error)
34 Close()36 Close()
35}37}
3638
@@ -84,6 +86,27 @@
84 }86 }
85}87}
8688
89// GetProperty uses the org.freedesktop.DBus.Properties interface's Get method
90// to read a given property on the name, path and interface provided when
91// creating the endpoint. The return value is unpacked into a dbus.Variant,
92// and its value returned.
93func (endp endpoint) GetProperty(property string) (interface{}, error) {
94 proxy := endp.bus.Object(endp.name, dbus.ObjectPath(endp.path))
95 msg, err := proxy.Call("org.freedesktop.DBus.Properties", "Get", endp.iface, property)
96 if err != nil {
97 return nil, err
98 }
99 variantv, err := endp.unpackOneMsg(msg, property)
100 if err != nil {
101 return nil, err
102 }
103 variant, ok := variantv.(*dbus.Variant)
104 if !ok {
105 return nil, errors.New("Response from Properties.Get wasn't a *dbus.Variant")
106 }
107 return variant.Value, nil
108}
109
87// Close the connection to dbus.110// Close the connection to dbus.
88func (endp endpoint) Close() {111func (endp endpoint) Close() {
89 endp.bus.Close()112 endp.bus.Close()
90113
=== modified file 'bus/testing/testing_endpoint.go'
--- bus/testing/testing_endpoint.go 2014-01-20 13:45:30 +0000
+++ bus/testing/testing_endpoint.go 2014-01-20 18:16:27 +0000
@@ -69,6 +69,11 @@
69 }69 }
70}70}
7171
72// See Endpoint's GetProperty. This one is just another name for Call.
73func (tc *testingEndpoint) GetProperty(property string) (interface{}, error) {
74 return tc.Call(property)
75}
76
72// see Endpoint's Close. This one does nothing.77// see Endpoint's Close. This one does nothing.
73func (tc *testingEndpoint) Close() {}78func (tc *testingEndpoint) Close() {}
7479
7580
=== modified file 'bus/testing/testing_endpoint_test.go'
--- bus/testing/testing_endpoint_test.go 2014-01-20 12:36:21 +0000
+++ bus/testing/testing_endpoint_test.go 2014-01-20 18:16:27 +0000
@@ -71,3 +71,12 @@
71 e := endp.WatchSignal("what", func(u interface{}) {}, func() {})71 e := endp.WatchSignal("what", func(u interface{}) {}, func() {})
72 c.Check(e, NotNil)72 c.Check(e, NotNil)
73}73}
74
75// Tests that GetProperty() works
76func (s *TestingEndpointSuite) TestGetProperty(c *C) {
77 var m uint32 = 42
78 endp := NewTestingEndpoint(condition.Work(true), m)
79 v, e := endp.GetProperty("what")
80 c.Check(e, IsNil)
81 c.Check(v, Equals, m)
82}
7483
=== modified file 'networkmanager/networkmanager.go'
--- networkmanager/networkmanager.go 2014-01-20 18:16:27 +0000
+++ networkmanager/networkmanager.go 2014-01-20 18:16:27 +0000
@@ -61,8 +61,7 @@
61*/61*/
6262
63func (nm *networkManager) GetState() State {63func (nm *networkManager) GetState() State {
64 s, err := nm.bus.Call("state")64 s, err := nm.bus.GetProperty("state")
65
66 if err != nil {65 if err != nil {
67 nm.log.Errorf("Failed gettting current state: %s", err)66 nm.log.Errorf("Failed gettting current state: %s", err)
68 nm.log.Debugf("Defaulting state to Unknown")67 nm.log.Debugf("Defaulting state to Unknown")

Subscribers

People subscribed via source and target branches