Merge lp:~chipaca/ubuntu-push/move-proxy-into-endpoint into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 23
Merged at revision: 14
Proposed branch: lp:~chipaca/ubuntu-push/move-proxy-into-endpoint
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/new-nm-api
Diff against target: 112 lines (+23/-21)
2 files modified
bus/bus.go (+1/-1)
bus/endpoint.go (+22/-20)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/move-proxy-into-endpoint
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+202361@code.launchpad.net

Commit message

moved the object proxy into the endpoint

Description of the change

Moved endpoint's proxy into the object itself, getting rid of some code duplication and such.

To post a comment you must log in.
22. By John Lenton

oops, published a private constructor

Revision history for this message
Samuele Pedroni (pedronis) :
review: Approve
23. By John Lenton

simplified the (private) constructor to not return an interface type

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bus/bus.go'
2--- bus/bus.go 2014-01-20 13:45:30 +0000
3+++ bus/bus.go 2014-01-20 19:10:30 +0000
4@@ -63,7 +63,7 @@
5 if err != nil {
6 return nil, err
7 } else {
8- return &endpoint{conn, addr.Name, addr.Path, addr.Interface, log}, nil
9+ return newEndpoint(conn, addr, log), nil
10 }
11 }
12
13
14=== modified file 'bus/endpoint.go'
15--- bus/endpoint.go 2014-01-20 18:09:57 +0000
16+++ bus/endpoint.go 2014-01-20 19:10:30 +0000
17@@ -38,14 +38,24 @@
18
19 type endpoint struct {
20 bus *dbus.Connection
21- name string
22- path string
23+ proxy *dbus.ObjectProxy
24 iface string
25 log logger.Logger
26 }
27
28+// constructor
29+func newEndpoint(bus *dbus.Connection, addr Address, log logger.Logger) *endpoint {
30+ endp := new(endpoint)
31+ endp.bus = bus
32+ endp.proxy = bus.Object(addr.Name, dbus.ObjectPath(addr.Path))
33+ endp.iface = addr.Interface
34+ endp.log = log
35+
36+ return endp
37+}
38+
39 // ensure endpoint implements Endpoint
40-var _ Endpoint = endpoint{}
41+var _ Endpoint = &endpoint{}
42
43 /*
44 public methods
45@@ -56,14 +66,8 @@
46 // with the unpacked value. If it's unable to set up the watch it'll return an
47 // error. If the watch fails once established, d() is called. Typically f()
48 // sends the values over a channel, and d() would close the channel.
49-func (endp endpoint) WatchSignal(member string, f func(interface{}), d func()) error {
50- watch, err := endp.bus.WatchSignal(&dbus.MatchRule{
51- Type: dbus.TypeSignal,
52- Sender: endp.name,
53- Path: dbus.ObjectPath(endp.path),
54- Interface: endp.iface,
55- Member: member,
56- })
57+func (endp *endpoint) WatchSignal(member string, f func(interface{}), d func()) error {
58+ watch, err := endp.proxy.WatchSignal(endp.iface, member)
59 if err != nil {
60 endp.log.Debugf("Failed to set up the watch: %s", err)
61 return err
62@@ -77,9 +81,8 @@
63 // Call() invokes the provided member method (on the name, path and interface
64 // provided when creating the endpoint). The return value is unpacked before
65 // being returned.
66-func (endp endpoint) Call(member string, args ...interface{}) (interface{}, error) {
67- proxy := endp.bus.Object(endp.name, dbus.ObjectPath(endp.path))
68- if msg, err := proxy.Call(endp.iface, member, args...); err == nil {
69+func (endp *endpoint) Call(member string, args ...interface{}) (interface{}, error) {
70+ if msg, err := endp.proxy.Call(endp.iface, member, args...); err == nil {
71 return endp.unpackOneMsg(msg, member)
72 } else {
73 return 0, err
74@@ -90,9 +93,8 @@
75 // to read a given property on the name, path and interface provided when
76 // creating the endpoint. The return value is unpacked into a dbus.Variant,
77 // and its value returned.
78-func (endp endpoint) GetProperty(property string) (interface{}, error) {
79- proxy := endp.bus.Object(endp.name, dbus.ObjectPath(endp.path))
80- msg, err := proxy.Call("org.freedesktop.DBus.Properties", "Get", endp.iface, property)
81+func (endp *endpoint) GetProperty(property string) (interface{}, error) {
82+ msg, err := endp.proxy.Call("org.freedesktop.DBus.Properties", "Get", endp.iface, property)
83 if err != nil {
84 return nil, err
85 }
86@@ -108,7 +110,7 @@
87 }
88
89 // Close the connection to dbus.
90-func (endp endpoint) Close() {
91+func (endp *endpoint) Close() {
92 endp.bus.Close()
93 }
94
95@@ -117,7 +119,7 @@
96 */
97
98 // unpackOneMsg unpacks the value from the response msg
99-func (endp endpoint) unpackOneMsg(msg *dbus.Message, member string) (interface{}, error) {
100+func (endp *endpoint) unpackOneMsg(msg *dbus.Message, member string) (interface{}, error) {
101 var v interface{}
102 if err := msg.Args(&v); err != nil {
103 endp.log.Errorf("Decoding %s: %s", member, err)
104@@ -128,7 +130,7 @@
105 }
106
107 // unpackMessages unpacks the value from the watch
108-func (endp endpoint) unpackMessages(watch *dbus.SignalWatch, f func(interface{}), d func(), member string) {
109+func (endp *endpoint) unpackMessages(watch *dbus.SignalWatch, f func(interface{}), d func(), member string) {
110 for {
111 msg, ok := <-watch.C
112 if !ok {

Subscribers

People subscribed via source and target branches