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'] tht = props.get(CHANNEL_INTERFACE + '.TargetHandleType', HANDLE_TYPE_NONE) if tht == HANDLE_TYPE_NONE: self._handle = NoneHandle() else: self._handle = self._conn.handle( 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_immutable_properties({ 'ChannelType': CHANNEL_INTERFACE, 'TargetHandle': CHANNEL_INTERFACE, 'Interfaces': CHANNEL_INTERFACE, 'TargetHandleType': CHANNEL_INTERFACE, 'TargetID': CHANNEL_INTERFACE, 'Requested': CHANNEL_INTERFACE })
def __init__(self, proto, account, manager=None, protocol=None): """ Parameters: proto - the name of the protcol this conection should be handling. account - a protocol-specific account name manager - the name of the connection manager """ if manager is None: import warnings warnings.warn( 'The manager parameter to Connection.__init__ ' 'should be supplied', DeprecationWarning) manager = 'python' clean_account = _escape_as_identifier(account) bus_name = u'org.freedesktop.Telepathy.Connection.%s.%s.%s' % \ (manager, proto, clean_account) bus_name = dbus.service.BusName(bus_name, bus=dbus.SessionBus()) object_path = '/org/freedesktop/Telepathy/Connection/%s/%s/%s' % \ (manager, proto, clean_account) _Connection.__init__(self, bus_name, object_path) # monitor clients dying so we can release handles dbus.SessionBus().add_signal_receiver(self.name_owner_changed_callback, 'NameOwnerChanged', 'org.freedesktop.DBus', 'org.freedesktop.DBus', '/org/freedesktop/DBus') self._interfaces = set() DBusProperties.__init__(self) self._implement_property_get( CONN_INTERFACE, { 'SelfHandle': lambda: dbus.UInt32(self.GetSelfHandle()), 'Interfaces': lambda: dbus.Array(self.GetInterfaces(), signature='s'), 'Status': lambda: dbus.UInt32(self.GetStatus()) }) self._proto = proto # Protocol name self._protocol = protocol # Protocol object self._status = CONNECTION_STATUS_DISCONNECTED self._self_handle = NoneHandle() self._handles = weakref.WeakValueDictionary() self._next_handle_id = 1 self._client_handles = {} self._channels = set() self._next_channel_id = 0
def _get_type_requested_handle(self, props): """Return the type, request and target handle from the requested properties""" type = props[CHANNEL_INTERFACE + '.ChannelType'] requested = props[CHANNEL_INTERFACE + '.Requested'] target_handle_type = \ props.get(CHANNEL_INTERFACE + '.TargetHandleType', HANDLE_TYPE_NONE) if target_handle_type == HANDLE_TYPE_NONE: handle = NoneHandle() else: target_handle = props[CHANNEL_INTERFACE + '.TargetHandle'] handle = self._conn._handles[target_handle_type, target_handle] return (type, requested, handle)
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.get(CHANNEL_INTERFACE + '.Requested', True) tht = props.get(CHANNEL_INTERFACE + '.TargetHandleType', HANDLE_TYPE_NONE) if tht == HANDLE_TYPE_NONE: self._handle = NoneHandle() else: self._handle = self._conn.handle( 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_immutable_properties({ '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'] tht = props.get(CHANNEL_INTERFACE + '.TargetHandleType', HANDLE_TYPE_NONE) if tht == HANDLE_TYPE_NONE: self._handle = NoneHandle() else: self._handle = self._conn.handle( 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_immutable_properties({ 'ChannelType': CHANNEL_INTERFACE, 'TargetHandle': CHANNEL_INTERFACE, 'Interfaces': CHANNEL_INTERFACE, 'TargetHandleType': CHANNEL_INTERFACE, 'TargetID': CHANNEL_INTERFACE, 'Requested': CHANNEL_INTERFACE }) def _add_immutables(self, props): #backward compatibility self._add_immutable_properties(props) @dbus.service.method(CHANNEL_INTERFACE, in_signature='', out_signature='') def Close(self): self.Closed() # Do all these separately in case one works but another doesn't. try: self._chan_manager.remove_channel(self) except: pass try: self._conn.remove_channel(self) except: pass try: self.remove_from_connection() except: pass @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
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.get(CHANNEL_INTERFACE + '.Requested', True) tht = props.get(CHANNEL_INTERFACE + '.TargetHandleType', HANDLE_TYPE_NONE) if tht == HANDLE_TYPE_NONE: self._handle = NoneHandle() else: self._handle = self._conn.handle( 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_immutable_properties({ 'ChannelType': CHANNEL_INTERFACE, 'TargetHandle': CHANNEL_INTERFACE, 'Interfaces': CHANNEL_INTERFACE, 'TargetHandleType': CHANNEL_INTERFACE, 'TargetID': CHANNEL_INTERFACE, 'Requested': CHANNEL_INTERFACE }) def _add_immutables(self, props): #backward compatibility self._add_immutable_properties(props) @dbus.service.method(CHANNEL_INTERFACE, in_signature='', out_signature='') def Close(self): self.Closed() # Do all these separately in case one works but another doesn't. try: self._chan_manager.remove_channel(self) except: pass try: self._conn.remove_channel(self) except: pass try: self.remove_from_connection() except: pass @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