zeromq / zmqpp

0mq 'highlevel' C++ bindings
http://zeromq.github.io/zmqpp
Mozilla Public License 2.0
438 stars 195 forks source link

zmqpp::actor doesn't bind the callback #185

Open keith-dev opened 7 years ago

keith-dev commented 7 years ago

With zactor, you can bind your callback to an object pointer, so the callback can use methods on that object (if an object was passed), or reference data in that structure (if the address of a struct was passed).

You cannot do this with zmqpp::actor because the callback is defined as: typedef std::function<bool(socket *pipe)> ActorStartRoutine;

It should be defined as: typedef std::function<bool(socket pipe, void owner)> ActorStartRoutine;

This would allow you to inherit from zmqpp::actor and further specialize it. For example, implement remote instantiation, for example.

bluca commented 7 years ago

That's a good suggestion, unfortunately it would be a backward-incompatible change. What about adding a new typedef and API? Would you be able to send a PR implementing it?

xaqq commented 7 years ago

Hello @keith-dev,

If I understand you correctly, what you want to do is this:

void my_routine_invoked_by_the_actor(zmqpp::socket *, int my_additional_param, std::string another_custom_param) { }

This is possible because of how std::bind works. See https://github.com/leosac/leosac/blob/develop/src/core/module_manager.cpp#L111-L114 for example. The function that end up being called look like this: https://github.com/leosac/leosac/blob/develop/src/modules/doorman/init.cpp#L37-L38

On Sun, Mar 19, 2017 at 7:58 PM, Luca Boccassi notifications@github.com wrote:

That's a good suggestion, unfortunately it would be a backward-incompatible change. What about adding a new typedef and API? Would you be able to send a PR implementing it?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/zeromq/zmqpp/issues/185#issuecomment-287638449, or mute the thread https://github.com/notifications/unsubscribe-auth/AA33l7ua4sdD_0A3mIMGVTC97He5HmUPks5rnXq4gaJpZM4MgzOV .

-- Kapp Arnaud - Xaqq

keith-dev commented 7 years ago

Ok, it never occurred to me to use bind. I'll take another look. Thanks.

I was kinda floored when I realized zmqpp wasn't simply a thin wrapper on czmq and lost heart.

xaqq commented 7 years ago

Yes bind should work for your case. However, if you're looking at a wrapper around czmq there is https://github.com/zeromq/czmqpp. I've never used it so I don't know how complete it is etc.