• Thomas Haller's avatar
    settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection · 38273a88
    Thomas Haller authored
    NMConnection is an interface, which is implemented by the types
    NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
    NMRemoteConnection (libnm).
    
    NMSettingsConnection does a lot of things already:
    
      1) it "is-a" NMDBusObject and exports the API of a connection profile
         on D-Bus
      2) it interacts with NMSettings and contains functionality
         for tracking the profiles.
      3) it is the base-class of types like NMSKeyfileConnection and
         NMIfcfgConnection. These handle how the profile is persisted
         on disk.
      4) it implements NMConnection interface, to itself track the
         settings of the profile.
    
    3) and 4) would be better implemented via delegation than inheritance.
    
    Address 4) and don't let NMSettingsConnection implemente the NMConnection
    interface. Instead, a settings-connection references now a NMSimpleConnection
    instance, to which it delegates for keeping the actual profiles.
    
    Advantages:
    
      - by delegating, there is a clearer separation of what
        NMSettingsConnection does. For example, in C we often required
        casts from NMSettingsConnection to NMConnection. NMConnection
        is a very trivial object with very little logic. When we have
        a NMConnection instance at hand, it's good to know that it is
        *only* that simple instead of also being an entire
        NMSettingsConnection instance.
    
        The main purpose of this patch is to simplify the code by separating
        the NMConnection from the NMSettingsConnection. We should generally
        be aware whether we handle a NMSettingsConnection or a trivial
        NMConnection instance. Now, because NMSettingsConnection no longer
        "is-a" NMConnection, this distinction is apparent.
    
      - NMConnection is implemented as an interface and we create
        NMSimpleConnection instances whenever we need a real instance.
        In GLib, interfaces have a performance overhead, that we needlessly
        pay all the time. With this change, we no longer require
        NMConnection to be an interface. Thus, in the future we could compile
        a version of libnm-core for the daemon, where NMConnection is not an
        interface but a GObject implementation akin to NMSimpleConnection.
    
      - In the previous implementation, we cannot treat NMConnection immutable
        and copy-on-write.
        For example, when NMDevice needs a snapshot of the activated
        profile as applied-connection, all it can do is clone the entire
        NMSettingsConnection as a NMSimpleConnection.
        Likewise, when we get a NMConnection instance and want to keep
        a reference to it, we cannot do that, because we never know
        who also references and modifies the instance.
        By separating NMSettingsConnection we could in the future have
        NMConnection immutable and copy-on-write, to avoid all unnecessary
        clones.
    38273a88
nm-settings-connection.h 14.4 KB