This is an extension of CustomNotification.
TValueReceiver is defined in ValueReceiver.h and ValueReceiver.C. It is a new sample receiver that registers for interest in a specific value using the new protocol defined by TSender. It shows how you can add and remove interests while a connection is connected.
TLongInterest is defined in LongInterest.h and LongInterest.C. It derives from TInterest, providing state and protocol to include a long value with the interest. It implements streaming operators, Hash, and IsEqual so that the Notification framework can use it properly.
TLongNotification and TReceiver are the same as in the CustomNotification sample.
When this technique is used, the sender can issue notifications several times with different interests. While it is tempting to try to use HasConnectionFor to reduce the need for this, it is possible that one receiver might handle notification in such a way that it or other receivers add or remove interests that would be affected. The safest option for the sender is to notify with all relevant interests and let the notifier determine whether any receivers are interested.
It is possible to respond to a notification by adding and removing interests. The Notification framework handles the concurrency issues. This sample does not illustrate this, but it can easily be modified to do so. For example, TValueReceiver could report when the value changed either to or away from its special value. To do this, it could implement HandleValueNotification to unregister interest in the value and register interest in any change. Then when the sender's value changed again, TValueReceiver could reregister for interest in its special value.
Unfortunately, the use of IsEqual to determine whether interests match (and therefore that notifications should be sent) makes it difficult to implement interest in values that meet other criteria, for instance, those over a particular threshold. Such an interest would have to be "equal" to a range of other interests in a way that was not bidirectional. In such cases the receiver would have to receive all value notifictions and filter out the ones it wished to respond to.