forked from BellerophonMobile/gonetworkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActiveConnection.go
161 lines (131 loc) · 4.53 KB
/
ActiveConnection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package gonetworkmanager
import (
"github.com/godbus/dbus"
)
const (
ActiveConnectionInterface = NetworkManagerInterface + ".Connection.Active"
ActiveConnectionProperyConnection = ActiveConnectionInterface + ".Connection"
ActiveConnectionProperySpecificObject = ActiveConnectionInterface + ".SpecificObject"
ActiveConnectionProperyID = ActiveConnectionInterface + ".Id"
ActiveConnectionProperyUUID = ActiveConnectionInterface + ".Uuid"
ActiveConnectionProperyType = ActiveConnectionInterface + ".Type"
ActiveConnectionProperyDevices = ActiveConnectionInterface + ".Devices"
ActiveConnectionProperyState = ActiveConnectionInterface + ".State"
ActiveConnectionProperyStateFlags = ActiveConnectionInterface + ".StateFlags"
ActiveConnectionProperyDefault = ActiveConnectionInterface + ".Default"
ActiveConnectionProperyIP4Config = ActiveConnectionInterface + ".Ip4Config"
ActiveConnectionProperyDHCP4Config = ActiveConnectionInterface + ".Dhcp4Config"
ActiveConnectionProperyDefault6 = ActiveConnectionInterface + ".Default6"
ActiveConnectionProperyVPN = ActiveConnectionInterface + ".Vpn"
ActiveConnectionProperyMaster = ActiveConnectionInterface + ".Master"
)
type ActiveConnection interface {
// GetConnection gets connection object of the connection.
GetConnection() Connection
// GetSpecificObject gets a specific object associated with the active connection.
GetSpecificObject() AccessPoint
// GetID gets the ID of the connection.
GetID() string
// GetUUID gets the UUID of the connection.
GetUUID() string
// GetType gets the type of the connection.
GetType() string
// GetDevices gets array of device objects which are part of this active connection.
GetDevices() []Device
// GetState gets the state of the connection.
GetState() uint32
// GetStateFlags gets the state flags of the connection.
GetStateFlags() uint32
// GetDefault gets the default IPv4 flag of the connection.
GetDefault() bool
// GetIP4Config gets the IP4Config of the connection.
GetIP4Config() IP4Config
// GetDHCP4Config gets the DHCP4Config of the connection.
GetDHCP4Config() DHCP4Config
// GetVPN gets the VPN flag of the connection.
GetVPN() bool
// GetMaster gets the master device of the connection.
GetMaster() Device
}
func NewActiveConnection(objectPath dbus.ObjectPath) (ActiveConnection, error) {
var a activeConnection
return &a, a.init(NetworkManagerInterface, objectPath)
}
type activeConnection struct {
dbusBase
}
func (a *activeConnection) GetConnection() Connection {
path := a.getObjectProperty(ActiveConnectionProperyConnection)
con, err := NewConnection(path)
if err != nil {
panic(err)
}
return con
}
func (a *activeConnection) GetSpecificObject() AccessPoint {
path := a.getObjectProperty(ActiveConnectionProperySpecificObject)
ap, err := NewAccessPoint(path)
if err != nil {
panic(err)
}
return ap
}
func (a *activeConnection) GetID() string {
return a.getStringProperty(ActiveConnectionProperyID)
}
func (a *activeConnection) GetUUID() string {
return a.getStringProperty(ActiveConnectionProperyUUID)
}
func (a *activeConnection) GetType() string {
return a.getStringProperty(ActiveConnectionProperyType)
}
func (a *activeConnection) GetDevices() []Device {
paths := a.getSliceObjectProperty(ActiveConnectionProperyDevices)
devices := make([]Device, len(paths))
var err error
for i, path := range paths {
devices[i], err = DeviceFactory(path)
if err != nil {
panic(err)
}
}
return devices
}
func (a *activeConnection) GetState() uint32 {
return a.getUint32Property(ActiveConnectionProperyState)
}
func (a *activeConnection) GetStateFlags() uint32 {
return a.getUint32Property(ActiveConnectionProperyStateFlags)
}
func (a *activeConnection) GetDefault() bool {
b := a.getProperty(ActiveConnectionProperyDefault)
return b.(bool)
}
func (a *activeConnection) GetIP4Config() IP4Config {
path := a.getObjectProperty(ActiveConnectionProperyIP4Config)
r, err := NewIP4Config(path)
if err != nil {
panic(err)
}
return r
}
func (a *activeConnection) GetDHCP4Config() DHCP4Config {
path := a.getObjectProperty(ActiveConnectionProperyDHCP4Config)
r, err := NewDHCP4Config(path)
if err != nil {
panic(err)
}
return r
}
func (a *activeConnection) GetVPN() bool {
ret := a.getProperty(ActiveConnectionProperyVPN)
return ret.(bool)
}
func (a *activeConnection) GetMaster() Device {
path := a.getObjectProperty(ActiveConnectionProperyMaster)
r, err := DeviceFactory(path)
if err != nil {
panic(err)
}
return r
}