This repository has been archived on 2025-03-19. You can view files and clone it, but cannot push or open issues or pull requests.
gonetworkmanager/Settings.go
2018-12-07 14:54:35 -05:00

58 lines
1.3 KiB
Go

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
// AddConnection call new connection and save it to disk.
AddConnection(settings ConnectionSettings) Connection
}
func NewSettings() (Settings, error) {
var s settings
return &s, s.init(NetworkManagerInterface, SettingsObjectPath)
}
type settings struct {
dbusBase
}
func (s *settings) ListConnections() []Connection {
var connectionPaths []dbus.ObjectPath
s.call(&connectionPaths, SettingsListConnections)
connections := make([]Connection, len(connectionPaths))
var err error
for i, path := range connectionPaths {
connections[i], err = NewConnection(path)
if err != nil {
panic(err)
}
}
return connections
}
func (s *settings) AddConnection(settings ConnectionSettings) Connection {
var path dbus.ObjectPath
s.call(&path, SettingsAddConnection, settings)
con, err := NewConnection(path)
if err != nil {
panic(err)
}
return con
}