2
Copyright 2013-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/>.
17
// Package urldispatcher wraps the url dispatcher's dbus api point
21
"launchpad.net/ubuntu-push/bus"
22
"launchpad.net/ubuntu-push/click"
23
"launchpad.net/ubuntu-push/logger"
26
// UrlDispatcher lives on a well-known bus.Address
27
var BusAddress bus.Address = bus.Address{
28
Interface: "com.canonical.URLDispatcher",
29
Path: "/com/canonical/URLDispatcher",
30
Name: "com.canonical.URLDispatcher",
33
// A URLDispatcher is a simple beast, with a single method that does what it
35
type URLDispatcher interface {
36
DispatchURL(string, *click.AppId) error
37
TestURL(*click.AppId, []string) bool
40
type urlDispatcher struct {
45
// New builds a new URL dispatcher that uses the provided bus.Endpoint
46
func New(endp bus.Endpoint, log logger.Logger) URLDispatcher {
47
return &urlDispatcher{endp, log}
50
var _ URLDispatcher = &urlDispatcher{} // ensures it conforms
52
func (ud *urlDispatcher) DispatchURL(url string, app *click.AppId) error {
53
ud.log.Debugf("Dispatching %s", url)
54
err := ud.endp.Call("DispatchURL", bus.Args(url, app.DispatchPackage()))
56
ud.log.Errorf("Dispatch to %s failed with %s", url, err)
61
func (ud *urlDispatcher) TestURL(app *click.AppId, urls []string) bool {
62
ud.log.Debugf("TestURL: %s", urls)
64
err := ud.endp.Call("TestURL", bus.Args(urls), &appIds)
66
ud.log.Errorf("TestURL for %s failed with %s", urls, err)
69
for _, appId := range appIds {
70
if appId != app.Versioned() {
71
ud.log.Debugf("Notification skipped because of different appid for actions: %v - %s != %s", urls, appId, app.Versioned())