Debian Codegraph @

bus/bus.go

raw
1 /*
2 Copyright 2013-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 bus provides a simplified (and more testable?) interface to DBus.
18 package bus
19
20 // Here we define the Bus itself
21
22 import (
23 "gitlab.com/ubports/development/core/lomiri-push-service/logger"
24 )
25
26 /*****************************************************************
27 * Bus (and its implementation)
28 */
29
30 // This is the Bus itself.
31 type Bus interface {
32 String() string
33 Endpoint(Address, logger.Logger) Endpoint
34 }
35
36 type concreteBus int
37
38 const (
39 typeSystemBus concreteBus = iota
40 typeSessionBus
41 )
42
43 // ensure concreteBus implements Bus
44 var _ Bus = new(concreteBus)
45
46 // no bus.Bus constructor, just two standard, constant, busses
47 var (
48 SystemBus Bus = concreteBus(typeSystemBus)
49 SessionBus Bus = concreteBus(typeSessionBus)
50 )
51
52 /*
53 public methods
54 */
55
56 func (bus concreteBus) String() string {
57 if bus == typeSystemBus {
58 return "SystemBus"
59 } else {
60 return "SessionBus"
61 }
62 }
63
64 // Endpoint returns a bus endpoint.
65 func (bus concreteBus) Endpoint(addr Address, log logger.Logger) Endpoint {
66 return newEndpoint(bus, addr, log)
67 }
68
69 // Args helps build arguments for endpoint Call().
70 func Args(args ...interface{}) []interface{} {
71 return args
72 }
73
74 /*****************************************************************
75 * Address
76 */
77
78 // bus.Address is just a bag of configuration
79 type Address struct {
80 Name string
81 Path string
82 Interface string
83 }
84
85 var BusDaemonAddress = Address{
86 "org.freedesktop.DBus",
87 "/org/freedesktop/DBus",
88 "org.freedesktop.DBus",
89 }