Solid DevicePrivate object ownership
Kevin Ottens
ervin at kde.org
Tue Nov 24 20:24:39 GMT 2009
Hello,
On Thursday 5 November 2009 11:49:36 Jiří Paleček wrote:
> 1) A DevicePrivate for a specific device exists at most once in the
> program, and is always cached in the DeviceManager, is that right?
Yes, that's the intent.
> 2) By whom is the m_backendObject of the DevicePrivate owned (and should
> be deleted)?
By the DeviceManager (as in some cases the DevicePrivate backend counterpart
should disappear and only the manager knows when that's supposed to happen).
> 3)
>
> void Solid::DevicePrivate::setInterface(const DeviceInterface::Type &type,
> DeviceInterface *interface)
> {
> ref.ref();
> m_ifaces[type] = interface;
> }
>
> Why is the reference count raised every time we add an interface?
We want to prevent DevicePrivate to be destroyed even if there's no Device
instance pointing to it as soon as the client code accessed an interface (use
case here is that some interfaces have signals, if the DevicePrivate object
would be destroyed, connecting to those interface signals would be useless as
the emitter would disappear when no corresponding Device instance is left in
the client code).
> 4)
>
> void Solid::DevicePrivate::setBackendObject(Ifaces::Device *object)
> {
> m_backendObject = object;
>
> if (m_backendObject) {
> connect(m_backendObject, SIGNAL(destroyed(QObject *)),
> this, SLOT(_k_destroyed(QObject *)));
> }
>
> if (!m_ifaces.isEmpty()) {
> foreach (DeviceInterface *iface, m_ifaces) {
> delete iface->d_ptr->backendObject();
> delete iface;
> }
>
> m_ifaces.clear();
>
> if (!ref.deref()) deleteLater();
> }
> }
>
> And why is it decreased once we reset the backend object?
It's a mistake, should obviously be decreased for each instance in m_ifaces,
not simply once (as we increased for each call to setInterface()). Committed
the change in trunk just now.
> 5)
>
> void Solid::DevicePrivate::setBackendObject(Ifaces::Device *object)
> {
> ...
> foreach (DeviceInterface *iface, m_ifaces) {
> delete iface->d_ptr->backendObject();
> delete iface;
> }
>
> Why do we delete iface->d_ptr->backendObject() here ...
>
> Solid::DevicePrivate::~DevicePrivate()
> {
> qDeleteAll(m_ifaces);
> }
>
> ... and not here?
Obviously missing. Committed the change in trunk just now.
Regards.
--
Kévin Ottens, http://ervin.ipsquad.net
KDAB - proud patron of KDE, http://www.kdab.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20091124/0f56f405/attachment.sig>
More information about the kde-core-devel
mailing list