--bcaec54a32c0e41f9d04d7f3024a Content-Type: text/plain; charset=ISO-8859-1 On Fri, Mar 15, 2013 at 8:33 AM, Simeon Bird wrote: > Git commit cf6a1316df282c3c7e99d952e9fc351498d5f9a4 by Simeon Bird. > Committed on 12/03/2013 at 04:38. > Pushed by sbird into branch 'feature/resourcemanagercleanup'. > > ResourceManager/ResourceWatcher: Make removeResource and addResource > happen in the ResourceWatcher thread via a QAutoConnection, avoiding > the thread unsafety of QDBusConnection and thus the crash. > Add convenience functions to the ResourceWatcher that start and stop it > if necessary, so that we don't have to jump back and forth between > threads. > > BUG: 305024 > FIXED-IN: 4.10.2 > I'm not too sure if I like the idea of these added public functions. If they were just for this resource manager, then it would be okay. Can't we just call both the functions one after another via QMetaObject::invokeMethod? There is obviously the call of resourceCount, which we can just assume has been incremented on our own. > M +16 -0 libnepomukcore/datamanagement/resourcewatcher.cpp > M +20 -0 libnepomukcore/datamanagement/resourcewatcher.h > M +4 -14 libnepomukcore/resource/resourcemanager.cpp > > > http://commits.kde.org/nepomuk-core/cf6a1316df282c3c7e99d952e9fc351498d5f9a4 > > diff --git a/libnepomukcore/datamanagement/resourcewatcher.cpp > b/libnepomukcore/datamanagement/resourcewatcher.cpp > index f394ae8..d01b8a3 100644 > --- a/libnepomukcore/datamanagement/resourcewatcher.cpp > +++ b/libnepomukcore/datamanagement/resourcewatcher.cpp > @@ -169,6 +169,13 @@ void Nepomuk2::ResourceWatcher::addResource(const > QUrl& resUri) > } > } > > +void Nepomuk2::ResourceWatcher::addResourceStart(const QUrl& resUri) > +{ > + addResource(resUri); > + if(resourceCount() <=1){ > + start(); > + } > +} > > void Nepomuk2::ResourceWatcher::addType(const Nepomuk2::Types::Class& > type) > { > @@ -199,6 +206,15 @@ void Nepomuk2::ResourceWatcher::removeResource(const > QUrl& resUri) > } > } > > +void Nepomuk2::ResourceWatcher::removeResourceStop(const QUrl& resUri) > +{ > + removeResource(resUri); > + if(!resourceCount()){ > + stop(); > + } > +} > + > + > void Nepomuk2::ResourceWatcher::removeType(const Nepomuk2::Types::Class& > type) > { > d->m_types.removeAll(type.uri()); > diff --git a/libnepomukcore/datamanagement/resourcewatcher.h > b/libnepomukcore/datamanagement/resourcewatcher.h > index 05e3710..909fa0d 100644 > --- a/libnepomukcore/datamanagement/resourcewatcher.h > +++ b/libnepomukcore/datamanagement/resourcewatcher.h > @@ -126,6 +126,16 @@ namespace Nepomuk2 { > void addResource( const QUrl& resUri ); > > /** > + * \brief Add a resource to be watched and maybe stop. > + * > + * As addResource, but if the added resource is the last first > one, > + * (re)-start the watcher. > + * > + * \sa addResource() > + */ > + void addResourceStart(const QUrl& resUri); > + > + /** > * \brief Add a property to be watched. > * > * Every change to a value of this property > @@ -165,6 +175,16 @@ namespace Nepomuk2 { > void removeResource( const QUrl& resUri ); > > /** > + * \brief Remove a resource to be watched and maybe stop. > + * > + * As removeResource, but if the removed resource is the last one, > + * stop the watcher. > + * > + * \sa removeResource() > + */ > + void removeResourceStop(const QUrl& resUri); > + > + /** > * \brief Remove a property to be watched. > * > * Every change to a value of this property > diff --git a/libnepomukcore/resource/resourcemanager.cpp > b/libnepomukcore/resource/resourcemanager.cpp > index 2b32be0..03b7b58 100644 > --- a/libnepomukcore/resource/resourcemanager.cpp > +++ b/libnepomukcore/resource/resourcemanager.cpp > @@ -423,15 +423,9 @@ void Nepomuk2::ResourceManagerPrivate::addToWatcher( > const QUrl& uri ) > m_manager, > SLOT(slotPropertyAdded(Nepomuk2::Resource, Nepomuk2::Types::Property, > QVariant)) ); > QObject::connect( m_watcher, > SIGNAL(propertyRemoved(Nepomuk2::Resource, Nepomuk2::Types::Property, > QVariant)), > m_manager, > SLOT(slotPropertyRemoved(Nepomuk2::Resource, Nepomuk2::Types::Property, > QVariant)) ); > - m_watcher->addResource( uri ); > - } > - else { > - QMetaObject::invokeMethod( m_watcher, "addResource", > Qt::AutoConnection, Q_ARG(QUrl, uri) ); > - } > - // (re-)start the watcher in case this resource is the only one in > the list of watched > - if( m_watcher->resourceCount() <= 1 ) { > - QMetaObject::invokeMethod(m_watcher, "start", Qt::AutoConnection); > } > + // add a resource and (re-)start the watcher in case this resource is > the only one in the list of watched > + QMetaObject::invokeMethod( m_watcher, "addResourceStart", > Qt::AutoConnection, Q_ARG(QUrl, uri) ); > } > > void Nepomuk2::ResourceManagerPrivate::removeFromWatcher( const QUrl& uri > ) > @@ -439,12 +433,8 @@ void > Nepomuk2::ResourceManagerPrivate::removeFromWatcher( const QUrl& uri ) > if( uri.isEmpty() || !m_watcher ) > return; > > - m_watcher->removeResource( uri ); > - > - // stop the watcher since we do not want to watch all changes in case > there is no ResourceData left > - if( !m_watcher->resourceCount() ) { > - QMetaObject::invokeMethod(m_watcher, "stop", Qt::AutoConnection); > - } > + // remove a resource and stop the watcher since we do not want to > watch all changes in case there is no ResourceData left > + QMetaObject::invokeMethod( m_watcher, "removeResourceStop", > Qt::AutoConnection, Q_ARG(QUrl, uri) ); > } > > #include "resourcemanager.moc" > > --bcaec54a32c0e41f9d04d7f3024a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Fri, Mar 15, 2013 at 8:33 AM, Simeon = Bird <bladud@gmail.com> wrote:
Git commit cf6a1316df282c3c7e99d952e9fc351498d5f9a4 by Simeon Bird.
Committed on 12/03/2013 at 04:38.
Pushed by sbird into branch 'feature/resourcemanagercleanup'.

ResourceManager/ResourceWatcher: Make removeResource and addResource
happen in the ResourceWatcher thread via a QAutoConnection, avoiding
the thread unsafety of QDBusConnection and thus the crash.
Add convenience functions to the ResourceWatcher that start and stop it
if necessary, so that we don't have to jump back and forth between
threads.

BUG: 305024
FIXED-IN: 4.10.2

I'm not too sure if I like th= e idea of these added public functions. If they were just for this resource= manager, then it would be okay.

Can't we just call both the fun= ctions one after another via QMetaObject::invokeMethod? There is obviously = the call of resourceCount, which we can just assume has been incremented on= our own.


M =A0+16 =A0 -0 =A0 =A0libnepomukcore/datamanagement/resourcewatcher.cpp M =A0+20 =A0 -0 =A0 =A0libnepomukcore/datamanagement/resourcewatcher.h
M =A0+4 =A0 =A0-14 =A0 libnepomukcore/resource/resourcemanager.cpp

http://commits.kde.org/nepomuk-core/cf6a131= 6df282c3c7e99d952e9fc351498d5f9a4

diff --git a/libnepomukcore/datamanagement/resourcewatcher.cpp b/libnepomuk= core/datamanagement/resourcewatcher.cpp
index f394ae8..d01b8a3 100644
--- a/libnepomukcore/datamanagement/resourcewatcher.cpp
+++ b/libnepomukcore/datamanagement/resourcewatcher.cpp
@@ -169,6 +169,13 @@ void Nepomuk2::ResourceWatcher::addResource(const QUrl= & resUri)
=A0 =A0 =A0}
=A0}

+void Nepomuk2::ResourceWatcher::addResourceStart(const QUrl& resUri) +{
+ =A0 =A0addResource(resUri);
+ =A0 =A0if(resourceCount() <=3D1){
+ =A0 =A0 =A0 =A0start();
+ =A0 =A0}
+}

=A0void Nepomuk2::ResourceWatcher::addType(const Nepomuk2::Types::Class&= ; type)
=A0{
@@ -199,6 +206,15 @@ void Nepomuk2::ResourceWatcher::removeResource(const Q= Url& resUri)
=A0 =A0 =A0}
=A0}

+void Nepomuk2::ResourceWatcher::removeResourceStop(const QUrl& resUri)=
+{
+ =A0 =A0removeResource(resUri);
+ =A0 =A0if(!resourceCount()){
+ =A0 =A0 =A0 =A0stop();
+ =A0 =A0}
+}
+
+
=A0void Nepomuk2::ResourceWatcher::removeType(const Nepomuk2::Types::Class&= amp; type)
=A0{
=A0 =A0 =A0d->m_types.removeAll(type.uri());
diff --git a/libnepomukcore/datamanagement/resourcewatcher.h b/libnepomukco= re/datamanagement/resourcewatcher.h
index 05e3710..909fa0d 100644
--- a/libnepomukcore/datamanagement/resourcewatcher.h
+++ b/libnepomukcore/datamanagement/resourcewatcher.h
@@ -126,6 +126,16 @@ namespace Nepomuk2 {
=A0 =A0 =A0 =A0 =A0void addResource( const QUrl& resUri );

=A0 =A0 =A0 =A0 =A0/**
+ =A0 =A0 =A0 =A0 * \brief Add a resource to be watched and maybe stop.
+ =A0 =A0 =A0 =A0 *
+ =A0 =A0 =A0 =A0 * As addResource, but if the added resource is the last f= irst one,
+ =A0 =A0 =A0 =A0 * (re)-start the watcher.
+ =A0 =A0 =A0 =A0 *
+ =A0 =A0 =A0 =A0 * \sa addResource()
+ =A0 =A0 =A0 =A0 */
+ =A0 =A0 =A0 =A0void addResourceStart(const QUrl& resUri);
+
+ =A0 =A0 =A0 =A0/**
=A0 =A0 =A0 =A0 =A0 * \brief Add a property to be watched.
=A0 =A0 =A0 =A0 =A0 *
=A0 =A0 =A0 =A0 =A0 * Every change to a value of this property
@@ -165,6 +175,16 @@ namespace Nepomuk2 {
=A0 =A0 =A0 =A0 =A0void removeResource( const QUrl& resUri );

=A0 =A0 =A0 =A0 =A0/**
+ =A0 =A0 =A0 =A0 * \brief Remove a resource to be watched and maybe stop.<= br> + =A0 =A0 =A0 =A0 *
+ =A0 =A0 =A0 =A0 * As removeResource, but if the removed resource is the l= ast one,
+ =A0 =A0 =A0 =A0 * stop the watcher.
+ =A0 =A0 =A0 =A0 *
+ =A0 =A0 =A0 =A0 * \sa removeResource()
+ =A0 =A0 =A0 =A0 */
+ =A0 =A0 =A0 =A0void removeResourceStop(const QUrl& resUri);
+
+ =A0 =A0 =A0 =A0/**
=A0 =A0 =A0 =A0 =A0 * \brief Remove a property to be watched.
=A0 =A0 =A0 =A0 =A0 *
=A0 =A0 =A0 =A0 =A0 * Every change to a value of this property
diff --git a/libnepomukcore/resource/resourcemanager.cpp b/libnepomukcore/r= esource/resourcemanager.cpp
index 2b32be0..03b7b58 100644
--- a/libnepomukcore/resource/resourcemanager.cpp
+++ b/libnepomukcore/resource/resourcemanager.cpp
@@ -423,15 +423,9 @@ void Nepomuk2::ResourceManagerPrivate::addToWatcher( c= onst QUrl& uri )
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0m_manager, SLOT(slot= PropertyAdded(Nepomuk2::Resource, Nepomuk2::Types::Property, QVariant)) );<= br> =A0 =A0 =A0 =A0 =A0QObject::connect( m_watcher, SIGNAL(propertyRemoved(Nepo= muk2::Resource, Nepomuk2::Types::Property, QVariant)),
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0m_manager, SLOT(slot= PropertyRemoved(Nepomuk2::Resource, Nepomuk2::Types::Property, QVariant)) )= ;
- =A0 =A0 =A0 =A0m_watcher->addResource( uri );
- =A0 =A0}
- =A0 =A0else {
- =A0 =A0 =A0 =A0QMetaObject::invokeMethod( m_watcher, "addResource&qu= ot;, Qt::AutoConnection, Q_ARG(QUrl, uri) );
- =A0 =A0}
- =A0 =A0// (re-)start the watcher in case this resource is the only one in= the list of watched
- =A0 =A0if( m_watcher->resourceCount() <=3D 1 ) {
- =A0 =A0 =A0 =A0QMetaObject::invokeMethod(m_watcher, "start", Qt= ::AutoConnection);
=A0 =A0 =A0}
+ =A0 =A0// add a resource and (re-)start the watcher in case this resource= is the only one in the list of watched
+ =A0 =A0QMetaObject::invokeMethod( m_watcher, "addResourceStart"= , Qt::AutoConnection, Q_ARG(QUrl, uri) );
=A0}

=A0void Nepomuk2::ResourceManagerPrivate::removeFromWatcher( const QUrl&= ; uri )
@@ -439,12 +433,8 @@ void Nepomuk2::ResourceManagerPrivate::removeFromWatch= er( const QUrl& uri )
=A0 =A0 =A0if( uri.isEmpty() || !m_watcher )
=A0 =A0 =A0 =A0 =A0return;

- =A0 =A0m_watcher->removeResource( uri );
-
- =A0 =A0// stop the watcher since we do not want to watch all changes in c= ase there is no ResourceData left
- =A0 =A0if( !m_watcher->resourceCount() ) {
- =A0 =A0 =A0 =A0QMetaObject::invokeMethod(m_watcher, "stop", Qt:= :AutoConnection);
- =A0 =A0}
+ =A0 =A0// remove a resource and stop the watcher since we do not want to = watch all changes in case there is no ResourceData left
+ =A0 =A0QMetaObject::invokeMethod( m_watcher, "removeResourceStop&quo= t;, Qt::AutoConnection, Q_ARG(QUrl, uri) );
=A0}

=A0#include "resourcemanager.moc"


--bcaec54a32c0e41f9d04d7f3024a--