[Codebase] Refactoring with smart pointers and changed implementation of Message Broker
Major Changes and Additions
-
Modules are now instanciated as shared pointers and so have to be stored somewhere in order to keep the module active. This explicity requires the user to keep track of the module (ie. save it locally) otherwise it will be deleted preventing the module to be shown.
-
I've also implemented a responsibility delegation pattern from
MessageBroker
to the subscriber. What I mean with this is that the subscriber will be responsible by maintaining active the subscription by preventing the deletition of the object returned when subscribing.
This object, that is aunique_ptr<Subscription>
, will unsubscribe automatically from the message broker preventing the program to crash when a module is deleted, since the subscription will also be invalidated (this is achieved by callingMessageBroker::unsubscribe
when the subscription is deleted, that is when theunique_ptr
will fall out of scope).
In past implementation it was common to forget to unsubscribe from the broker when the module was deleted. This would lead to memory leakage since a pointer to the deleted module would remain in theMessageBroker
and when a filter matched the subscription it would try to call a method on the deleted object, causing a sigfault.
Minor Changes
- Using smart pointers when possible.
- Using std algorithms and data structures when possible
Additional Information
- Some features are left as plain pointers, this is due to the fact that Qt libraries do not support at all smart pointers
- Some data structures are changed to std from qt in order to use smart pointers
- Others were changed to match the new Subscription system
Related Issues
Solves Refactoring MessageBroker
Solves Using Smart Pointers
It doesn't break Crash when deleting tab