def __init__(self, connection, manager, props, object_path=None): """ Initialise the base channel object. Parameters: connection - the parent Connection object props - initial channel properties """ self._conn = connection self._chan_manager = manager object_path = self._conn.get_channel_path(object_path) _Channel.__init__(self, self._conn._name, object_path) self._type = props[CHANNEL_INTERFACE + '.ChannelType'] self._requested = props[CHANNEL_INTERFACE + '.Requested'] self._immutable_properties = dict() tht = props.get(CHANNEL_INTERFACE + '.TargetHandleType', HANDLE_TYPE_NONE) if tht == HANDLE_TYPE_NONE: self._handle = NoneHandle() else: self._handle = self._conn.get_handle_by_id( props[CHANNEL_INTERFACE + '.TargetHandleType'], props[CHANNEL_INTERFACE + '.TargetHandle']) self._interfaces = set() DBusProperties.__init__(self) self._implement_property_get(CHANNEL_INTERFACE, {'ChannelType': lambda: dbus.String(self.GetChannelType()), 'Interfaces': lambda: dbus.Array(self.GetInterfaces(), signature='s'), 'TargetHandle': lambda: dbus.UInt32(self._handle.get_id()), 'TargetHandleType': lambda: dbus.UInt32(self._handle.get_type()), 'TargetID': lambda: dbus.String(self._handle.get_name()), 'Requested': lambda: self._requested}) self._add_immutables({ 'ChannelType': CHANNEL_INTERFACE, 'TargetHandle': CHANNEL_INTERFACE, 'Interfaces': CHANNEL_INTERFACE, 'TargetHandleType': CHANNEL_INTERFACE, 'TargetID': CHANNEL_INTERFACE, 'Requested': CHANNEL_INTERFACE })
class Channel(_Channel, DBusProperties): def __init__(self, connection, manager, props, object_path=None): """ Initialise the base channel object. Parameters: connection - the parent Connection object props - initial channel properties """ self._conn = connection self._chan_manager = manager object_path = self._conn.get_channel_path(object_path) _Channel.__init__(self, self._conn._name, object_path) self._type = props[CHANNEL_INTERFACE + '.ChannelType'] self._requested = props[CHANNEL_INTERFACE + '.Requested'] self._immutable_properties = dict() tht = props.get(CHANNEL_INTERFACE + '.TargetHandleType', HANDLE_TYPE_NONE) if tht == HANDLE_TYPE_NONE: self._handle = NoneHandle() else: self._handle = self._conn.get_handle_by_id( props[CHANNEL_INTERFACE + '.TargetHandleType'], props[CHANNEL_INTERFACE + '.TargetHandle']) self._interfaces = set() DBusProperties.__init__(self) self._implement_property_get(CHANNEL_INTERFACE, {'ChannelType': lambda: dbus.String(self.GetChannelType()), 'Interfaces': lambda: dbus.Array(self.GetInterfaces(), signature='s'), 'TargetHandle': lambda: dbus.UInt32(self._handle.get_id()), 'TargetHandleType': lambda: dbus.UInt32(self._handle.get_type()), 'TargetID': lambda: dbus.String(self._handle.get_name()), 'Requested': lambda: self._requested}) self._add_immutables({ 'ChannelType': CHANNEL_INTERFACE, 'TargetHandle': CHANNEL_INTERFACE, 'Interfaces': CHANNEL_INTERFACE, 'TargetHandleType': CHANNEL_INTERFACE, 'TargetID': CHANNEL_INTERFACE, 'Requested': CHANNEL_INTERFACE }) def _add_immutables(self, props): self._immutable_properties.update(props) def get_props(self): """Despite its name, this function actually only returns immutable channel properties.""" props = dict() for prop, iface in self._immutable_properties.items(): props[iface + '.' + prop] = \ self._prop_getters[iface][prop]() return props @dbus.service.method(CHANNEL_INTERFACE, in_signature='', out_signature='') def Close(self): self.Closed() self._chan_manager.remove_channel(self) self._conn.remove_channel(self) @dbus.service.method(CHANNEL_INTERFACE, in_signature='', out_signature='s') def GetChannelType(self): """ Returns the interface name for the type of this channel. """ return self._type @dbus.service.method(CHANNEL_INTERFACE, in_signature='', out_signature='uu') def GetHandle(self): """ Returns the handle type and number if this channel represents a communication with a particular contact, room or server-stored list, or zero if it is transient and defined only by its contents. """ return (self._handle.get_type(), self._handle.get_id()) @dbus.service.method(CHANNEL_INTERFACE, in_signature='', out_signature='as') def GetInterfaces(self): """ Get the optional interfaces implemented by the channel. Returns: an array of the D-Bus interface names """ return self._interfaces