Reputation: 173
I have worked on an application which is depend on publisher subscriber (using boost.signalsv2)
here is controller;
#include "view.hpp"
class Controller
{
boost::signals2::signal<void ()> sig;
public:
Controller() {
}
void subscribe(listener& listener) {
// Signal with no arguments and a void return value
sig.connect(boost::bind(&listener::OnUpdate, &listener));
}
void DoWork() const {
// Call all of the slots
sig();
}
void Update();
};
doWork function call all subscring slots.
int main() {
Controller c;
View l1, l2;
c.subscribe(l1);
std::cout << "One subscribed:\n";
c.DoWork();
c.subscribe(l2);
c.subscribe(l3);
std::cout << "\nBoth subscribed:\n";
c.DoWork();
}
There are more than one subscriber systems.(l1 ,l2 and l3) I want to publish specific one (l2) How can i check and do this?
Upvotes: 1
Views: 36
Reputation: 393114
That's not how it's intended. If you want to distinguish, either have different signals OR pass a token to the handlers that makes it possible for them to know whether they're interested in that particular event.
If you want to have a specific /position/ in the list of connected handlers to take the event, then you may be able to use an alternative/custom combiners: https://www.boost.org/doc/libs/1_73_0/doc/html/signals2/thread-safety.html#id-1.3.36.7.3
Upvotes: 2