This repository has been archived by the owner on Jan 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
connection_active.go
64 lines (50 loc) · 1.88 KB
/
connection_active.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
package netmgr
import (
"github.com/godbus/dbus/v5"
"github.com/nlepage/go-netmgr/internal/dbusext"
)
// ConnectionActiveIface is the Active Connection interface.
const ConnectionActiveIface = "org.freedesktop.NetworkManager.Connection.Active"
type (
// ConnectionActive represents an attempt to connect to a network using the details provided by a Connection object.
//
// See https://developer.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.Connection.Active.html for more information.
ConnectionActive interface {
dbus.BusObject
// Properties
// Vpn indicates whether this active connection is also a VPN connection.
//
// See https://developer.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.Connection.Active.html#gdbus-property-org-freedesktop-NetworkManager-Connection-Active.Vpn for more information.
Vpn() (bool, error)
}
connectionActive struct {
dbusext.BusObject
}
)
var _ ConnectionActive = (*connectionActive)(nil)
// NewConnectionActive returns the ConnectionActive from conn corresponding to path.
func NewConnectionActive(conn *dbus.Conn, path dbus.ObjectPath) (ConnectionActive, error) {
ca := connectionActive{dbusext.NewBusObject(conn, BusName, path)}
isVPN, err := ca.Vpn()
if err != nil {
return nil, err
}
if isVPN {
return &vpnConnection{ca}, nil
}
return &ca, nil
}
// NewConnectionActives returns the slice of ConnectionActive from conn corresponding to paths.
func NewConnectionActives(conn *dbus.Conn, paths []dbus.ObjectPath) ([]ConnectionActive, error) {
connectionActives := make([]ConnectionActive, len(paths))
var err error
for i, path := range paths {
if connectionActives[i], err = NewConnectionActive(conn, path); err != nil {
return nil, err
}
}
return connectionActives, nil
}
func (ca *connectionActive) Vpn() (bool, error) {
return ca.GetBProperty(ConnectionActiveIface + ".Vpn")
}