z25 / pyZOCP

Python ZOCP implementation (Z25 Orchestration Control Protocol)
GNU Lesser General Public License v3.0
32 stars 5 forks source link

How to handle receiving a signal on a sensor? #69

Open sphaero opened 9 years ago

sphaero commented 9 years ago

What's the best approach to handling a received signal on a sensor? It seems emit_signal is called? However no signal will be emitted?

              for receiver in receivers:
                    # propagate the signal if it changes the value of this node
                    if receiver is not None and self.capability[receiver]['value'] != value:
                        self.emit_signal(receiver, value)

I could check the value of the sensor everytime I receive a message but this is inefficient...

fieldOfView commented 9 years ago

A capability that wants to send ("emit") a signal (ie: tell subscribed nodes that its value has changed) calls emit_signal.

A node that receives a signal from another node implements on_peer_signaled to act on the received signal. See the definition of on_peer_signaled: https://github.com/z25/pyZOCP/blob/master/src/zocp.py#L499

Note: nodes would not normally override emit_signal. Emit_signal is the method for sending, on_peer_signaled is the callback for receiving.