Skip to content
Snippets Groups Projects
Commit eae4b0c0 authored by Romain Vimont's avatar Romain Vimont Committed by Steve Lhomme
Browse files

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
1 merge request!2623qt: refactor media tree/source models
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment