alex wrote:If I understand your requirements properly, except for multiple arguments, delegates should do what you want.
pjwhite wrote:1) - auto disconnect on delete of class slot is in ( extend the slot class from Poco::Expire? )
See
Ping example:
- Code: Select all
void initialize(Application& self) {
_icmpClient.pingBegin += Delegate<Ping, ICMPEventArgs>(this, &Ping::onBegin);
// ...
}
void uninitialize() {
_icmpClient.pingBegin -= Delegate<Ping, ICMPEventArgs>(this, &Ping::onBegin);
// ...
}
While looking through samples, I noticed there's a simpler syntax to add/remove delegates, see
EchoServer example:
- Code: Select all
EchoServiceHandler(StreamSocket& socket, SocketReactor& reactor):
// ...
{
// ...
_fifoOut.readable += delegate(this, &EchoServiceHandler::onFIFOOutReadable);
_fifoIn.writable += delegate(this, &EchoServiceHandler::onFIFOInWritable);
}
~EchoServiceHandler()
{
//...
_fifoOut.readable -= delegate(this, &EchoServiceHandler::onFIFOOutReadable);
_fifoIn.writable -= delegate(this, &EchoServiceHandler::onFIFOInWritable);
}
This isn't what I meant by auto-disconnect. I figure that the Ping class could implement a Poco::EventHandler interface, which would actually disconnect (-=) for you in it's destructor. This would essentially remove all delegates with the specific pointer.
alex wrote:pjwhite wrote:2) - run the handler in a separate thread ( haven't seen which class would do this? )
See
AbstractEvent::notifyAsync()
Thanks, This is what I am looking for, but it's hard to tell what threads run. Is it a newly spun up thread for each delegate, a thread pool, or a single thread for each event?
alex wrote:pjwhite wrote:3) I would LOVE to be able to pass more than one arg, so was thinking of adding more template implementations ( ie. one for 2 and 3 args, anything higher and I would think a class/struct would be acceptable ).
I'm not sure explicitly adding more arguments would be the best approach. I did not think about it at all but C++11 variadic templates come in mind first.
I mean something like boost::signal2 where the BasicEvent could be defined like BasicEvent<float, int, std::string> s; This would be very nice for many events.
I guess what I am looking for is closer to boost::signals2 but with option asynchronous signal passing... Hmmm