1. 18 Apr, 2018 1 commit
  2. 05 Jul, 2017 1 commit
    • Thomas Haller's avatar
      all: add base object type in "nm-obj.h" · b8bc80bc
      Thomas Haller authored
      Platform has it's own, simple implementation of object types:
      NMPObject. Extract a base type and move it to "shared/nm-utils/nm-obj.h"
      so it can be reused.
      
      The base type is trival, but it allows us to implement other objects
      which are compatible with NMPObjects. Currently there is no API for generic
      NMObjBaseInst type, so compatible in this case only means, that they
      can be used in the same context (see example below).
      The only thing that you can do with a NMObjBaseInst is check it's
      NMObjBaseClass.
      
      Incidentally, NMObjBaseInst is also made compatible to GTypeInstance.
      It means, an NMObjBaseInst is not necessarily a valid GTypeInstance (like NMPObject
      is not), but it could be implemented as such.
      
      For example, you could do:
      
          if (NMP_CLASS_IS_VALID ((NMPClass *) obj->klass)) {
              /* is an NMPObject */
          } else if (G_TYPE_CHECK_INSTANCE_TYPE (obj, NM_TYPE_SOMETHING)) {
              /* it a NMSometing GType */
          } else {
              /* something else? */
          }
      
      The reason why NMPObject is not implemented as proper GTypeInstance is
      because it would require us to register a GType (like
      g_type_register_fundamental). However, then the NMPClass struct can
      no longer be const and immutable memory. But we could.
      
      NMObjBaseInst may or may not be a GTypeInstance. In a sense, it's
      a base type of GTypeInstance and all our objects should be based
      on it (optionally, they we may make them valid GTypes too).
      b8bc80bc