qt: use one "callbacks" instance per listener
For each model (NetworkDeviceModel and NetworkMediaModel), every NetworkSourceListener instance were created with the same SourceListenercb instance: +------------------+ | SourceListenerCb |-----------------------------. +------------------+ | ^ | | implements | +--------------------+ | | NetworkDeviceModel | | +--------------------+ | | m_listeners | +---+ +-----------------------+ | | ---------------| NetworkSourceListener |-| +---+ +-----------------------+ | | ---------- +-----------------------+ | +---+ `----| NetworkSourceListener |-| | -------... +-----------------------+ . +---+ . | | . +---+ To prepare storing additional data for each registration, use one SourceListenerCb instance per listener: +------------------+ | SourceListenerCb | +------------------+ ^ implements | +--------------------+ | | NetworkDeviceModel | | +--------------------+ | | m_listeners | +---+ +-----------------------+ +--------------+ | | ------------| NetworkSourceListener |--| MyListenerCb |-| +---+ +-----------------------+ +--------------+ | | ---------- +-----------------------+ +--------------+ | +---+ `-| NetworkSourceListener |--| MyListenerCb |-| | -------... +-----------------------+ +--------------+ . +---+ . | | . +---+ In practice, this will allow the SourceListenerCb (to be renamed to MediaTreeListenerCb) to only use a media tree (not a media source), and let the caller store an additional associated media source usable from the callbacks implementation. As a drawback, the MyListenerCb instance must be owned by the listener (to avoid additional complexity on the client side), but then this forces the client to always create a separate class for the listener callbacks, even when not necessary (i.e. making NetworkMediaModel "implement" SourceListenerCb is not possible anymore). Alternatives considered: 1. keep SourceListenerCb as is, but make NetworkSourceListener virtual (inheritable), so that the additional media source could be stored there. As a drawback, the SourceListenerCb methods would need to get the NetworkSourceListener instance as parameter (so yet another indirection). And having both the listener and the callbacks virtual seems odd. 2. merge SourceListenerCb into NetworkSourceListener, so that the client can just inherit and store additional private data in the same class. But this requires more changes from the existing code base.
parent
1a9ab8b5
No related branches found
No related tags found
Showing
- modules/gui/qt/network/networkdevicemodel.cpp 18 additions, 18 deletionsmodules/gui/qt/network/networkdevicemodel.cpp
- modules/gui/qt/network/networkdevicemodel.hpp 12 additions, 5 deletionsmodules/gui/qt/network/networkdevicemodel.hpp
- modules/gui/qt/network/networkmediamodel.cpp 32 additions, 32 deletionsmodules/gui/qt/network/networkmediamodel.cpp
- modules/gui/qt/network/networkmediamodel.hpp 12 additions, 5 deletionsmodules/gui/qt/network/networkmediamodel.hpp
- modules/gui/qt/network/networksourcelistener.cpp 2 additions, 2 deletionsmodules/gui/qt/network/networksourcelistener.cpp
- modules/gui/qt/network/networksourcelistener.hpp 3 additions, 2 deletionsmodules/gui/qt/network/networksourcelistener.hpp
Loading
Please register or sign in to comment