- Code: Select all
class MainClass{
public:
method1(){//postNotification so that only handleMethod1 of ShapeClass is called}
method2(){//postNotification so that only handleMethod2 of ShapeClass is called}
private:
NotificationCenter nCenter;
};
//passed a reference of the notification center
class ShapeClass1{
ShapeClass1(NotificationCenter* nc){
Observer<ShapeClass, Notification> o(*this, &ShapeClass::handleNotificationfromMainClassMethod1);
Observer<ShapeClass, Notification> o1(*this, &ShapeClass::handleNotificationfromMainClassMethod2);
}
handleNotificationfromMainClassMethod1(Notification* nf1){...}
handleNotificationfromMainClassMethod2(Notificatino* nf2){...}
method3(); // post notification
};
//passed a reference of the notification center
class SystemClass1{
SystemClass1(NotificationCenter* nc){
}
handleNotificationfromShapeClass1()
};
I have to make the observers in ShapeClass1 to subscribe to the notifications frmo MainClass. In additon the main concern here is how to post notifications so that only observers fitting a certain condition are called. For eg: from main class 1, when I post notification from method1(), I want only the observer o to call the handler methods and o1 should ignore the notification. How do I post notification to matching observers only? And how do I register observers to listen to notifications from classes other than themselves?
Poco Notification Center [url="http://www.appinf.com/docs/poco/Poco.NotificationCenter.html"]example here[/url]





