Classes | |
| struct | ReportBase |
| struct | ReceiveReport |
| struct | DistributeReport |
| struct | SendReport |
| struct | TempConnect |
| Temporarily connect a ReceiveReport then restore the previous one. More... | |
These are the functions the sender invokes, and which will be forwarded to some receiver. If no receiver is present, the defined default implementations are invoked.
For methods returning non-void, define a reasonable return value, because this is what you get back in case no receiver is listening.
That way the sending side does not need to know whether some receiver is listening. And it enables the receiver to return a reasonable value, in case he's got no idea, what else to return.
struct Foo : public callback::ReportBase { virtual void ping( int i ) {} virtual int pong() { return -1; } };
{
callback::SendReport<Foo> report;
report->ping( 13 );
int response = report->pong();
}
Foo the recipient class derives from callback::ReceiveReport<Foo>. callback::ReceiveReport inherits Foo and provides two additional virtual methods:
virtual void reportbegin() {} virtual void reportend() {}
These two are automatically invoked, whenever the sender creates a callback::SendReport instance, and when it gets destructed. So even if the sending task is aborted without sending an explicit notification, the reciever may notice it, by overloading reportend.
Overload the methods you're interested in.
int somefunction() { ...// don't know what to return? return Foo::somefunction(); }
void connect(); void disconnect(); bool connected() const; ReceiveReport * whoIsConnected() const;
connect Connect this ReceiveReport (in case some other ReceiveReport is connected, it get disconnected. Remember its a Callback light). disconnect Disconnect this ReceiveReport in case it is connected. If not connected nothing happens. connected Test wheter this ReceiveReport is currently connected. whoIsConnected Return a 'ReceiveReport*' to the currently connected ReceiveReport, or NULL if none is connected.
1.5.3