-
Notifications
You must be signed in to change notification settings - Fork 224
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
Use C++ style callback interfaces as a variant of existing C function callbacks #404
base: master
Are you sure you want to change the base?
Conversation
If byte 'StartOfText' is received when an escape character was not received previously, the method 'GetMessageFromStream' could end up in an endless loop. This shouldn't happen when correct data is received, but since it's data received on the UART, there are no guarantees that the data is not corrupt.
Add an alternative callback method instead of using a C-style function pointer when a new message is received. This callback is based on a C++ interface which allows for handling a callback within a C++ class context instead of a C function.
Add an alternative callback method instead of using a C-style function pointer for various callbacks. This callback is based on a C++ interface which allows for handling a callback within a C++ class context instead of a C function.
Please check first void AttachMsgHandler(tMsgHandler *_MsgHandler); and tMsgHandler class. Not sure if I want third callback handler for tNMEA2000. |
Hi. Yes, I've seen that already, and that would solve the message callback handler, but it would not solve the callbacks for OnOpen and OnIsoRequest. Currently there is no (easy) way of handling these callbacks within a C++ class context, without declaring global variables etc. |
Please let me know if there are any changes you want me to do, or if you want to close the pull-request again. |
I am bit busy and had not yet time to think it carefully. But there is some clear problems.
I understand your point, but have to think it more. |
No worries - take your time :) Some comments on your thoughts:
Regards, Peter Olsson |
It's been a while since I looked at this project but I would solve it in one of 3 ways depending on std and C compatibility requirements:
The cleanest would probably be |
At the time I started library I had to keep std:: away, since it did not compile for some MCUs. Not sure is it limitation anymore. One problem is that change to core requires me to run tests for several different environments and MCU:s. |
Yes, there are of course several ways to achieve similar results. The main reason for choosing a simple callback interface with an abstract class like I did, was to keep the implementation similar to the existing one, with low risk of compatibility issues (e.g. std::function requires C++11). I'm open to any suggestions though, so please let me know if you want me to consider any changes to this. |
Without breaking any compatibility, these changes extends tActisenseReader and tNMEA2000 classes to allow C++ interface style callbacks. This makes it easier to integrate with other C++ classes, instead of using simple C function pointers. This also fixes a bug in tActisenseReader that could end up in an endless loop.