Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced function pointer with function object #59

Merged
merged 1 commit into from
Apr 9, 2016

Conversation

rschaten
Copy link
Contributor

@rschaten rschaten commented Apr 9, 2016

I'm working on a sensor network projekt, using your excellent Homie framework. I have different sensors (light, temperature), and some actors (led, relay). I modularized my code, so I have a class for every kind of device. And I'm unable to subscribe my HomieNodes to topics when I'm inside of a method.

The problem is, that HomieNode.subscribe() only takes a function pointer as a second parameter, which I'm unable to provide. I'd rather give a function object.

With this change I'm able to subscribe my method ledOnHandler() in one of these two ways:

ledNode.subscribe("on", [this](String value) { return ledOnHandler(value); });
ledNode.subscribe("on", std::bind(&DeviceLed::ledOnHandler, this, std::placeholders::_1));

I successfully tested that the old way of doing this still works:

ledNode.subscribe("on", ledOnHandler);

So I don't think that this change breaks anything.

To be honest, I didn't make this change myself. I had a friend helping me, who is far more used to write code in C++. To me, this looks even stranger than usual... ;-)

I'd be happy to learn that there is another way to register, so that this change is obsolete. Please tell me if you know something. Thanks in advance!

@marvinroger
Copy link
Member

I knew this would be requested. Thanks for the PR. :)

@marvinroger marvinroger merged commit d93c4a7 into homieiot:master Apr 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants