2
Copyright 2014 Canonical Ltd.
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.
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.
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/>.
25
"launchpad.net/go-dbus/v1"
29
busInterface = "com.ubuntu.AccountPolld"
30
busPath = "/com/ubuntu/AccountPolld"
31
busName = "com.ubuntu.AccountPolld"
36
msgChan chan *dbus.Message
40
func New(conn *dbus.Connection) *PollBus {
43
msgChan: make(chan *dbus.Message),
44
PollChan: make(chan bool),
46
runtime.SetFinalizer(p, clean)
50
func clean(p *PollBus) {
51
p.conn.UnregisterObjectPath(busPath)
56
func (p *PollBus) Init() error {
57
name := p.conn.RequestName(busName, dbus.NameFlagDoNotQueue)
60
return fmt.Errorf("bus name could not be take: %s", err)
63
go p.watchMethodCalls()
64
p.conn.RegisterObjectPath(busPath, p.msgChan)
69
func (p *PollBus) SignalDone() error {
70
signal := dbus.NewSignalMessage(busPath, busInterface, "Done")
71
if err := p.conn.Send(signal); err != nil {
77
func (p *PollBus) watchMethodCalls() {
78
for msg := range p.msgChan {
79
var reply *dbus.Message
81
case msg.Interface == busInterface && msg.Member == "Poll":
82
log.Println("Received Poll()")
84
reply = dbus.NewMethodReturnMessage(msg)
86
log.Println("Received unkown method call on", msg.Interface, msg.Member)
87
reply = dbus.NewErrorMessage(msg, "org.freedesktop.DBus.Error.UnknownMethod", "Unknown method")
89
if err := p.conn.Send(reply); err != nil {
90
log.Println("Could not send reply:", err)