2
Copyright 2014 Canonical Ltd.
3
Authors: Sergio Schvezov <sergio.schvezov@canonical.com>
5
This program is free software: you can redistribute it and/or modify it
6
under the terms of the GNU General Public License version 3, as published
7
by the Free Software Foundation.
9
This program is distributed in the hope that it will be useful, but
10
WITHOUT ANY WARRANTY; without even the implied warranties of
11
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12
PURPOSE. See the GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License along
15
with this program. If not, see <http://www.gnu.org/licenses/>.
26
"launchpad.net/go-dbus/v1"
30
busInterface = "com.ubuntu.AccountPolld"
31
busPath = "/com/ubuntu/AccountPolld"
32
busName = "com.ubuntu.AccountPolld"
37
msgChan chan *dbus.Message
41
func New(conn *dbus.Connection) *PollBus {
44
msgChan: make(chan *dbus.Message),
45
PollChan: make(chan bool),
47
runtime.SetFinalizer(p, clean)
51
func clean(p *PollBus) {
52
p.conn.UnregisterObjectPath(busPath)
57
func (p *PollBus) Init() error {
58
name := p.conn.RequestName(busName, dbus.NameFlagDoNotQueue)
61
return fmt.Errorf("bus name could not be take: %s", err)
64
go p.watchMethodCalls()
65
p.conn.RegisterObjectPath(busPath, p.msgChan)
70
func (p *PollBus) SignalDone() error {
71
signal := dbus.NewSignalMessage(busPath, busInterface, "Done")
72
if err := p.conn.Send(signal); err != nil {
78
func (p *PollBus) watchMethodCalls() {
79
for msg := range p.msgChan {
80
var reply *dbus.Message
82
case msg.Interface == busInterface && msg.Member == "Poll":
83
log.Println("Received Poll()")
85
reply = dbus.NewMethodReturnMessage(msg)
87
log.Println("Received unkown method call on", msg.Interface, msg.Member)
88
reply = dbus.NewErrorMessage(msg, "org.freedesktop.DBus.Error.UnknownMethod", "Unknown method")
90
if err := p.conn.Send(reply); err != nil {
91
log.Println("Could not send reply:", err)