forked from Wifx/gonetworkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.go
106 lines (81 loc) · 3.48 KB
/
Settings.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
package gonetworkmanager
import (
"github.com/godbus/dbus/v5"
)
const (
SettingsInterface = NetworkManagerInterface ".Settings"
SettingsObjectPath = NetworkManagerObjectPath "/Settings"
/* Methods */
SettingsListConnections = SettingsInterface ".ListConnections"
SettingsGetConnectionByUuid = SettingsInterface ".GetConnectionByUuid"
SettingsAddConnection = SettingsInterface ".AddConnection"
SettingsAddConnectionUnsaved = SettingsInterface ".AddConnectionUnsaved"
SettingsLoadConnections = SettingsInterface ".LoadConnections"
SettingsReloadConnections = SettingsInterface ".ReloadConnections"
SettingsSaveHostname = SettingsInterface ".SaveHostname"
/* Properties */
SettingsPropertyConnections = SettingsInterface ".Connections" // readable ao
SettingsPropertyHostname = SettingsInterface ".Hostname" // readable s
SettingsPropertyCanModify = SettingsInterface ".CanModify" // readable b
)
type Settings interface {
// ListConnections gets list the saved network connections known to NetworkManager
ListConnections() ([]Connection, error)
// AddConnection adds new connection and save it to disk.
AddConnection(settings ConnectionSettings) (Connection, error)
// Add new connection but do not save it to disk immediately. This operation does not start the network connection unless (1) device is idle and able to connect to the network described by the new connection, and (2) the connection is allowed to be started automatically. Use the 'Save' method on the connection to save these changes to disk. Note that unsaved changes will be lost if the connection is reloaded from disk (either automatically on file change or due to an explicit ReloadConnections call).
AddConnectionUnsaved(settings ConnectionSettings) (Connection, error)
// Save the hostname to persistent configuration.
SaveHostname(hostname string) error
// If true, adding and modifying connections is supported.
GetPropertyCanModify() (bool, error)
// The machine hostname stored in persistent configuration.
GetPropertyHostname() (string, 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.callWithReturn(&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 connections, err
}
}
return connections, nil
}
func (s *settings) AddConnection(settings ConnectionSettings) (Connection, error) {
var path dbus.ObjectPath
err := s.callWithReturn(&path, SettingsAddConnection, settings)
if err != nil {
return nil, err
}
return NewConnection(path)
}
func (s *settings) AddConnectionUnsaved(settings ConnectionSettings) (Connection, error) {
var path dbus.ObjectPath
err := s.callWithReturn(&path, SettingsAddConnectionUnsaved, settings)
if err != nil {
return nil, err
}
return NewConnection(path)
}
func (s *settings) SaveHostname(hostname string) error {
return s.call(SettingsSaveHostname, hostname)
}
func (s *settings) GetPropertyHostname() (string, error) {
return s.getStringProperty(SettingsPropertyHostname)
}
func (s *settings) GetPropertyCanModify() (bool, error) {
return s.getBoolProperty(SettingsPropertyCanModify)
}