I need to pass exactly event (not a lasting state) over communication connection that can provide boolean or integer value, possible to set, clear and observe by both sides. It is OPC UA framework but I do not have access to OPC UA "methods", only to variables.
It initially looks simple: we can have the boolean that is initially false, the calling side sets it to true, the receiving side reacts. But to pass the signal again, something needs to set this boolean back to false. If the sending side does this immediately or after the short delay, the receiving side may fail observe the transient up/down change. If the receiving side does, the only place to do seems right after the value has been picked, because the response to this flip up may end up in various ways (including error cases), so there is no single place where the flip down can be implemented. I would like a well looking solution about that some independent reviewer would say it is done reasonably right. I have the following ideas so far:
- The receiving side clears the boolean bit back to false immediately after it picks the value true. This makes both sender and receiver relatively simple, but the bit on the communication gateway only has true value for some very short time, this may be difficult to observe and debug with the third tool from the side. Still let me known if this is the most obvious way to do.
- Not a boolean, but an integer is communicated, and the sending side increments this integer by one. The receiving side responds to the change of the value. This results more complex code on the both sides (the sender must read the value first, then increment, while the receiver must remember the current value and watch for the change). It is difficult to foresee what may go wrong here but the changed value stays as is for much longer intervals, so should be easier to work and manipulate with debugger.
- Single boolean is communicated, but both flipping up or down is the signal. This is somewhat reduction of the previous case with less context.
- We can have more complex protocol with more than one boolean flags ("I am sending now", "I confirm ready", "Here are the data", "I confirm received", "I finished sending"), but now we need all separate thread (or cyclic) to handle this protocol. Neither sender nor receiver can do from the single place of code where they pass through and do no return.
I think any of the four solutions listed above would generally work for me, but it would be valuable to know what solution would be seen as the most mainstream, and maybe some others are used. If there is something more commonly done in my situation, I would prefer a solution that does not look very unusual.