Пример #1
0
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
Пример #2
0
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