I have request objects with corresponding response objects. Sender object makes a request and then listens for response. One sender/listener object may send different requests. Every request goes into a global queue and after it was processed, corresponding response is sent to every listener object.
I have request objects with corresponding response objects. Sender object makes a request and
Share
There are several solutions to your problem. One would be, that the transceiver informs all
Requestobject about its destruction. For this, you would need a method likeTransceiver::addRequest()which aRequestobject uses to register itself. In thedestructor of
Transceiveryou have to inform all registeredRequest‘s. For example:A second approach would of course be to prevent the destruction of a
Transceiveraslong as it is in use. You could use a
std::shared_ptr<Transceiver> m_targetin theRequestclass, which means the transceiver lives at least as long as the associated request.For a bit more flexibility, there is also the possibility of an
std::weak_ptr<Transceiver>. Then the transceiver could be destroyed when the requestis still alive. However, when you try a
std::weak_ptr<Transceiver>::lock()and itfails, you know that the
Transceiveris dead.Edit: Added a method to remove a
Requestif it is destroyed before itsTransceiver.