Ejemplo n.º 1
0
    def unregister_listener(self, listener):
        """Remove a listener callback added with register_listener().

        Parameters
        ----------
        listener : function
            Reference to the callback function that should be removed

        """
        listener_id = hashable_identity(listener)
        self._listeners.pop(listener_id, None)
Ejemplo n.º 2
0
    def unregister_listener(self, listener):
        """Remove a listener callback added with register_listener().

        Parameters
        ----------
        listener : function
            Reference to the callback function that should be removed

        """
        listener_id = hashable_identity(listener)
        self._listeners.pop(listener_id, None)
Ejemplo n.º 3
0
    def register_listener(self, listener, reading=False):
        """Add a callback function that is called when sensor value is updated.
        The callback footprint is received_timestamp, timestamp, status, value.

        Parameters
        ----------
        listener : function
            Callback signature: if reading
            listener(katcp_sensor, reading) where
                `katcp_sensor` is this KATCPSensor instance
                `reading` is an instance of :class:`KATCPSensorReading`
            Callback signature: default, if not reading
                listener(received_timestamp, timestamp, status, value)
        """
        listener_id = hashable_identity(listener)
        self._listeners[listener_id] = (listener, reading)
Ejemplo n.º 4
0
    def register_listener(self, listener, reading=False):
        """Add a callback function that is called when sensor value is updated.
        The callback footprint is received_timestamp, timestamp, status, value.

        Parameters
        ----------
        listener : function
            Callback signature: if reading
            listener(katcp_sensor, reading) where
                `katcp_sensor` is this KATCPSensor instance
                `reading` is an instance of :class:`KATCPSensorReading`
            Callback signature: default, if not reading
                listener(received_timestamp, timestamp, status, value)
        """
        listener_id = hashable_identity(listener)
        self._listeners[listener_id] = (listener, reading)
        logger.debug('Register listener for {}'.format(self.name))
Ejemplo n.º 5
0
    def test_hashable_identity(self):
        class MyObject(object):
            def my_method(self):
                pass

        def my_func1():
            pass

        def my_func2():
            pass

        obj1 = MyObject()
        obj2 = MyObject()

        hash1 = hashable_identity(obj1)
        hash1_again = hashable_identity(obj1)
        hash2 = hashable_identity(obj2)
        self.assertEqual(hash1, hash1_again)
        self.assertNotEqual(hash1, hash2)

        hash1 = hashable_identity(obj1.my_method)
        hash1_again = hashable_identity(obj1.my_method)
        hash2 = hashable_identity(obj2.my_method)
        self.assertEqual(hash1, hash1_again)
        self.assertNotEqual(hash1, hash2)

        hash1 = hashable_identity(my_func1)
        hash1_again = hashable_identity(my_func1)
        hash2 = hashable_identity(my_func2)
        self.assertEqual(hash1, hash1_again)
        self.assertNotEqual(hash1, hash2)

        hash1 = hashable_identity('baz')
        hash1_again = hashable_identity('baz')
        hash2 = hashable_identity('foo')
        self.assertEqual(hash1, hash1_again)
        self.assertNotEqual(hash1, hash2)
Ejemplo n.º 6
0
 def is_listener(self, listener):
     listener_id = hashable_identity(listener)
     return listener_id in self._listeners
Ejemplo n.º 7
0
 def is_listener(self, listener):
     listener_id = hashable_identity(listener)
     return listener_id in self._listeners