This repository was archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathSettings.go
More file actions
63 lines (50 loc) · 1.43 KB
/
Settings.go
File metadata and controls
63 lines (50 loc) · 1.43 KB
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
package gonetworkmanager
import (
"github.com/godbus/dbus"
)
const (
SettingsInterface = NetworkManagerInterface + ".Settings"
SettingsObjectPath = NetworkManagerObjectPath + "/Settings"
SettingsListConnections = SettingsInterface + ".ListConnections"
SettingsAddConnection = SettingsInterface + ".AddConnection"
)
type Settings interface {
// ListConnections gets list the saved network connections known to NetworkManager
ListConnections() ([]Connection, error)
// AddConnection call new connection and save it to disk.
AddConnection(settings ConnectionSettings) (Connection, error)
}
func NewSettings() (Settings, error) {
var s settings
return &s, s.init(NetworkManagerInterface, SettingsObjectPath)
}
type settings struct {
dbusBase
}
func (s *settings) ListConnections() ([]Connection, error) {
var connectionPaths []dbus.ObjectPath
err := s.call(&connectionPaths, SettingsListConnections)
if err != nil {
return nil, err
}
connections := make([]Connection, len(connectionPaths))
for i, path := range connectionPaths {
connections[i], err = NewConnection(path)
if err != nil {
return nil, err
}
}
return connections, nil
}
func (s *settings) AddConnection(settings ConnectionSettings) (Connection, error) {
var path dbus.ObjectPath
err := s.call(&path, SettingsAddConnection, settings)
if err != nil {
return nil, err
}
con, err := NewConnection(path)
if err != nil {
return nil, err
}
return con, nil
}