~chipaca/ubuntu-push/gsettings

« back to all changes in this revision

Viewing changes to bus/polld/polld.go

  • Committer: Tarmac
  • Author(s): John R. Lenton
  • Date: 2014-08-22 01:34:00 UTC
  • mfrom: (306.4.4 polld)
  • Revision ID: tarmac-20140822013400-67iekxu7d52bh314
[r=sergiusens] Interface with account-polld's dbus api.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright 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 polld wraps the account-polld dbus interface
 
18
package polld
 
19
 
 
20
import (
 
21
        "errors"
 
22
 
 
23
        "launchpad.net/ubuntu-push/bus"
 
24
        "launchpad.net/ubuntu-push/logger"
 
25
)
 
26
 
 
27
var (
 
28
        ErrUnconfigured = errors.New("unconfigured.")
 
29
)
 
30
 
 
31
// polld lives on a well-known bus.Address
 
32
var BusAddress bus.Address = bus.Address{
 
33
        Interface: "com.ubuntu.AccountPolld",
 
34
        Path:      "/com/ubuntu/AccountPolld",
 
35
        Name:      "com.ubuntu.AccountPolld",
 
36
}
 
37
 
 
38
type Polld interface {
 
39
        Poll() error
 
40
        WatchDones() (<-chan bool, error)
 
41
}
 
42
 
 
43
type polld struct {
 
44
        endp bus.Endpoint
 
45
        log  logger.Logger
 
46
}
 
47
 
 
48
func New(endp bus.Endpoint, log logger.Logger) Polld {
 
49
        return &polld{endp, log}
 
50
}
 
51
 
 
52
func (p *polld) Poll() error {
 
53
        if p.endp == nil {
 
54
                return ErrUnconfigured
 
55
        }
 
56
        return p.endp.Call("Poll", nil)
 
57
}
 
58
 
 
59
func (p *polld) WatchDones() (<-chan bool, error) {
 
60
        if p.endp == nil {
 
61
                return nil, ErrUnconfigured
 
62
        }
 
63
        ch := make(chan bool)
 
64
        p.endp.WatchSignal("Done", func(...interface{}) {
 
65
                ch <- true
 
66
        }, func() { close(ch) })
 
67
        return ch, nil
 
68
}