File: activeconnection.py

package info (click to toggle)
cnetworkmanager 0.21.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 220 kB
  • ctags: 442
  • sloc: python: 1,252; makefile: 29
file content (56 lines) | stat: -rw-r--r-- 1,601 bytes parent folder | download
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
# -*- coding: utf-8 -*-

import dbus
from dbusclient import DBusClient, object_path
from dbusclient.func import *
from applet import Connection
from device import Device
from accesspoint import AccessPoint
from util import Enum

class ActiveConnection(DBusClient):
    """
     Signals:
    PropertiesChanged ( a{sv}: properties )
    
     Properties:
    ServiceName - s - (read)
    Connection - o - (read)
    SpecificObject - o - (read)
    Devices - ao - (read)
    State - u - (read) (NM_ACTIVE_CONNECTION_STATE)
    Default - b - (read)
    
     Enumerated types:
    NM_ACTIVE_CONNECTION_STATE
    """

    SERVICE = "org.freedesktop.NetworkManager"
    IFACE = "org.freedesktop.NetworkManager.Connection.Active"

    def __init__(self, opath):
        super(ActiveConnection, self).__init__(dbus.SystemBus(), self.SERVICE, opath, default_interface=self.IFACE)

    class State(Enum):
        UNKNOWN = 0
        ACTIVATING = 1
        ACTIVATED = 2

    def __getitem__(self, key):
        "Implement Connection by adding the required ServiceName"

        v = super(ActiveConnection, self).__getitem__(key)
        if key == "Connection":
            sn = self.__getitem__("ServiceName")
            v = Connection(sn, v)
        return v

ActiveConnection._add_adaptors(
    PropertiesChanged = SA(identity),
#    ServiceName = PA(identity),
#    Connection = PA(Connection), # implemented in __getitem__
    SpecificObject = PA(AccessPoint), #in most cases. figure out.
    Devices = PA(seq_adaptor(Device._create)),
    State = PA(ActiveConnection.State),
    Default = PA(bool),
    )