On 3/20/19 1:40 AM, Eric Blake wrote: > Upcoming patches want to add virDomainCheckpoint that behaves very > similarly to virDomainSnapshot; the easiest way to share common code > is to give both classes a common base class. Thanks to the accessor > functions in the previous patch, we have very few changes required > outside of datatypes.[ch]. The subclass does have to use a dummy > field, though, to satisfy virobject's insistence on size > differentiation for type safety. > > Note that virClassNew() supports a NULL dispose method for a class > that has nothing to clean up, but VIR_CLASS_NEW has no easy way to > register such a class without a #define hack. > > I promised my teenage daughter Evelyn that I'd give her credit for her > contribution to this commit. I asked her "What would be a good name > for a base class for DomainSnapshot and DomainCheckpoint". After > explaining what a base class was (using the classic OOB Square and > Circle inherit from Shape), she came up with "DomainMoment", which is > way better than my initial thought of "DomainPointInTime" or > "DomainPIT". Maybe it was her way to ensure some sort of "mom" 'ent'ry got included into libvirt ;-} > > Signed-off-by: Eric Blake <eblake@xxxxxxxxxx> > --- > src/datatypes.h | 26 ++++++-- > src/datatypes.c | 110 ++++++++++++++++++++-------------- > src/libvirt-domain-snapshot.c | 2 +- > 3 files changed, 88 insertions(+), 50 deletions(-) > [...] > > > +/** > + * virGetDomainMoment: > + * @domain: the domain involved in a point-in-time moment > + * @name: pointer to the domain moment name * @subclass: Either virDomainSnapshotClass or virDomainCheckpointClass [ok that second one is eventually.... and it's only internal so validation is left to the developer ;-}] > + * > + * Allocates a new concrete subclass of a domain moment object. When > + * the object is no longer needed, virObjectUnref() must be called in > + * order to not leak data. > + * > + * Returns a pointer to the domain moment object, or NULL on error. > + */ > +static virDomainMomentPtr > +virGetDomainMoment(virDomainPtr domain, const char *name, virClassPtr subclass) > +{ > + virDomainMomentPtr ret = NULL; > + > + if (virDataTypesInitialize() < 0) > + return NULL; > + > + virCheckDomainGoto(domain, error); > + virCheckNonNullArgGoto(name, error); > + > + if (!(ret = virObjectNew(subclass))) > + goto error; > + if (VIR_STRDUP(ret->name, name) < 0) > + goto error; > + > + ret->domain = virObjectRef(domain); > + > + return ret; > + > + error: > + virObjectUnref(ret); > + return NULL; > +} > + > + Reviewed-by: John Ferlan <jferlan@xxxxxxxxxx> John I have to say I did pause to stop and think about the Dispose thing... Especially with the "parent" class having a NULL ->dispose, but also having a klass->parent which would have the MomentDispose. [...] -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list