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
|
# -*- coding: utf-8 -*-
import dbus
from dbusclient import DBusClient, object_path
from dbusclient.func import *
from device import Device
from activeconnection import ActiveConnection
from util import Enum
# gratuitous convertor to test writable properties
def english_to_bool(v):
if v == "yes":
return True
elif v == "no":
return False
return v
class NetworkManager(DBusClient):
"""networkmanager
The NM client library
Methods:
GetDevices ( ) → ao
ActivateConnection ( s: service_name, o: connection, o: device, o: specific_object ) → o
DeactivateConnection ( o: active_connection ) → nothing
Sleep ( b: sleep ) → nothing
Signals:
StateChanged ( u: state )
PropertiesChanged ( a{sv}: properties )
DeviceAdded ( o: device_path )
DeviceRemoved ( o: device_path )
Properties:
WirelessEnabled - b - (readwrite)
WirelessHardwareEnabled - b - (read)
ActiveConnections - ao - (read)
State - u - (read) (NM_STATE)
Enumerated types:
NM_STATE
"""
SERVICE = "org.freedesktop.NetworkManager"
OPATH = "/org/freedesktop/NetworkManager"
IFACE = "org.freedesktop.NetworkManager"
def __init__(self):
super(NetworkManager, self).__init__(dbus.SystemBus(), self.SERVICE, self.OPATH, default_interface=self.IFACE)
class State(Enum):
UNKNOWN = 0
ASLEEP = 1
CONNECTING = 2
CONNECTED = 3
DISCONNECTED = 4
"TODO find a good term for 'adaptor'"
#from dbusclient.adaptors import *
NetworkManager._add_adaptors(
GetDevices = MA(seq_adaptor(Device._create)),
ActivateConnection = MA(ActiveConnection, identity, object_path, object_path, object_path),
DeactivateConnection = MA(void, object_path),
State = PA(NetworkManager.State),
WirelessEnabled = PA(bool, english_to_bool),
WirelessHardwareEnabled = PA(bool),
ActiveConnections = PA(seq_adaptor(ActiveConnection)),
StateChanged = SA(NetworkManager.State),
)
|