| 89 | # The Session object represents a single OpenVPN VPN session as |
| 90 | # presented via the OpenVPN 3 session manager D-Bus service. |
| 91 | class Session(object): |
| 92 | ## |
| 93 | # Initialize the Session object. It requires a D-Bus connection |
| 94 | # object and the D-Bus object path to the VPN session |
| 95 | # |
| 96 | # @param dbuscon D-Bus connection object |
| 97 | # @param objpath D-Bus object path to the VPN session |
| 98 | # |
| 99 | def __init__(self, dbuscon, objpath): |
| 100 | self.__dbuscon = dbuscon |
| 101 | |
| 102 | # Retrieve access to the session object |
| 103 | self.__session = self.__dbuscon.get_object('net.openvpn.v3.sessions', |
| 104 | objpath) |
| 105 | |
| 106 | # Retrive access to the session interface in the object |
| 107 | self.__session_intf = dbus.Interface(self.__session, |
| 108 | dbus_interface="net.openvpn.v3.sessions") |
| 109 | |
| 110 | # Retrive access to the property interface in the object |
| 111 | self.__prop_intf = dbus.Interface(self.__session, |
| 112 | dbus_interface="org.freedesktop.DBus.Properties") |
| 113 | |
| 114 | self.__session_path = objpath |
| 115 | self.__log_callback = None |
| 116 | self.__status_callback = None |
| 117 | self.__deleted = False |
| 118 | self.__log_forward_enabled = False |
| 119 | |
| 120 | |
| 121 | def __del__(self): |
| 122 | try: |
| 123 | if self.__log_callback is not None: |
| 124 | self.LogCallback(None) |
| 125 | if self.__status_callback is not None: |
| 126 | self.StatusChangeCallback(None) |
| 127 | except ImportError: |
| 128 | # This happens if Python is already shutting down |
| 129 | # no chance to properly clean up at this point. |
| 130 | pass |
| 131 | |
| 132 | |
| 133 | ## |
| 134 | # Internal decorator, checkes whether the object has been deleted or not. |
| 135 | # If the object has been deleted, throw an exception instead. |
| 136 | # |
| 137 | # For details, lookup how Python decorators work |
| 138 | # |
| 139 | def __delete_check(func): |
| 140 | @wraps(func) |
| 141 | def __delete_checker(self, *args, **kwargs): |
| 142 | if self.__deleted is True: |
| 143 | raise RuntimeError("This session object is unavailable") |
| 144 | return func(self, *args, **kwargs) |
| 145 | return __delete_checker |
| 146 | |
| 147 | ## |
| 148 | # Returns the D-Bus configuration object path |
no outgoing calls
no test coverage detected