Open-Agriculture / AgIsoStack-plus-plus

AgIsoStack++ is the completely free open-source C++ ISOBUS library for everyone
https://agisostack.com/
MIT License
167 stars 40 forks source link

[Core]: Detached message handling #462

Open GwnDaan opened 2 months ago

GwnDaan commented 2 months ago

Describe your changes

Introduced 3 classes that will remove the the dependency on the CANNetworkManager for all classes that want to receive / send messages. namely:

I think this will be a better alternative than passing the network manager around everywhere when we are refactoring away from the singleton. And it might especially be useful for unit testing, where we can isolate a class we wish to test and thereby remove interference from others. Though I'd like to hear any thoughts on this, as it does surely add an extra layer off complexity to the stack.

I see 3 ways a consumer can be set-up;

I think I prefer the last one. To start off, I switched over the ShortcutButtonInterface and HeartbeatInterface to this messaging system so we can see what it's like.

What's next

Once we find and agree on an approach, all the other classes that send/receive messages have to be adopted to this method. Furthermore, I'd like some unit-tests that will be run first in line to make sure the system remains correctly in place and it doesn't cause other tests to fail.

GwnDaan commented 1 month ago

I think we do keep getting further from the ability to ever really make the stack static allocation friendly, which is maybe fine? I know some levels of functional safety forbid any dynamic memory - which would be pretty painful for us to deal with, so maybe it's not worth worrying about especially with nobody explicitly asking for it or sponsoring that kind of thing?

Yeah I know... Even though it would have been super nice to also be able to support those kind of strict rule sets, I think static allocation is out of our scope at the moment. Especially since we have always worked with the dynamic allocation and expanded on that. The shared pointers already help a lot to manage the lifecycle of those dynamically allocated objects. Converting the whole stack to be static allocation friendly I imagine will complicate so many things, it would be almost a rewrite...

Edit: hmm, it might be doable with some clever bit of macro usage to replace all shared pointers with raw pointers, similar to what we do with the threaded stuff, but it will still definitely complicate things. I don't think this PR will make it any harder than it was before, instead it might even make it easier as we abstract things, it can be easier to (progressively) refactor things later on.

ad3154 commented 1 month ago

Yeah... but I do think we should worry about our current stuff and releasing 1.0 before we think too hard about it the static allocation stuff I think (if ever) I was mostly just thinking out loud 😊

sonarcloud[bot] commented 1 week ago

Quality Gate Passed Quality Gate passed

Issues
16 New issues
0 Accepted issues

Measures
0 Security Hotspots
77.2% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud