I have an API to subscribe a CAN signal as below :
bool subscribe(signal name);
SubscribeResponse(const CAN_DATA& data);
data.signal is the signal name
data.value is the signal value.
Now lets say client C1 and client C2 subscribe to different signal s1 and s2 respectively.
if any signal s1 or s2 changed response is received on SubscribeResponse(const CAN_DATA& data);
client c1 and c2 will will be added as obserber as below
AddObserver(CanClient* observer) {
observerlist.push_back(observer);
}
All the added observer will receive notification on change in the signal value as below :
void SubscribeResponse(const CAN_DATA& data){
std::vector<CanClient*>::iterator iter = observer_list_.begin();
for (; iter != observerlist.end(); ++iter)
(*iter)->NotifyEvent(data.signal,data.Value);
}
How can notification be send only to the actual subscriber ie if s1 changed notify to its subscriber c1 not c2 ?