The proton::container is single threaded, once you call run() you can't
interact with it from other threads.
I'd like to propose a "function injection" interface. I think the
analogous thing could be done for all the languages. The Go binding
already has this mechanism.
The idea is to provide a thread safe call that injects a simple
"callable" object with no parameters and no return value.
In C++11 this is easy to do:
class container {
void inject(std::function<void()>)
}
Semantics: calling inject() will queue the injected function to be
called as soon as is reasonable in the run() thread.
Context: depending on what you are doing the injected function might
need a little or a lot of context, so the signature is deliberately
empty. For example, you want to open a new connection:
c.inject(std::bind(container::connect, c, my_url))
OR if you want to call a user method on one of your own handlers:
c.inject(std::bind(my_handler_type::myfunc, myhandler, args...))
OR if you want to send a message safely on a sender belonging to the
container:
c.inject(std::bind(proton::sender::send, mysender, mymessage))
In C++03 we can support the functionality in a clunky way that is not
very efficient or easy to use, but works:
container {
/// For older C++ only
struct injected_function {
virtual
~injected_function() {}
virtual void operator() = 0;
}
///
Create a new injected_function instance for each call,
/// it will
be deleted in the run() thread after it is called.
void
inject(injected_function*);
}
Cheers,
Alan.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]