forked from BellerophonMobile/gonetworkmanager
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathSettings.go
129 lines (99 loc) · 4.38 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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)
// ReloadConnections tells NetworkManager to reload all connection files from disk, including noticing any added or deleted connection files.
ReloadConnections() error
// GetConnectionByUUID gets the connection, given that connection's UUID.
GetConnectionByUUID(uuid string) (Connection, error)
// AddConnection adds new connection and save it to disk.
AddConnection(settings ConnectionSettings) (Connection, error)
// AddConnectionUnsaved 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)
// SaveHostname Save the hostname to persistent configuration.
SaveHostname(hostname string) error
// GetPropertyCanModify If true, adding and modifying connections is supported.
GetPropertyCanModify() (bool, error)
// GetPropertyHostname 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
}
// ReloadConnections tells NetworkManager to reload (and apply) configuration files
// from disk taking notice of any added or removed connections.
func (s *settings) ReloadConnections() error {
return s.call(SettingsReloadConnections)
}
// GetConnectionByUUID gets the connection, given that connection's UUID.
func (s *settings) GetConnectionByUUID(uuid string) (Connection, error) {
var path dbus.ObjectPath
err := s.callWithReturn(&path, SettingsGetConnectionByUUID, uuid)
if err != nil {
return nil, err
}
return NewConnection(path)
}
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)
}