resourcesuser.cpp
27 // This class is needed so that the status of m_beingNotified is exception safe (i.e. it is reset
28 // to false if an exception gets thrown inside the handler for resource change). This is used both
100 // This is not exception safe. It is difficult to make this exception safe because QT aren't (and here we
109 // This is not exception safe. It is difficult to make this exception safe because QT aren't (and here we
165 void SimpleResourcesUser::notifyResourceChange(ResourceHandler* resource, ResourceChangeType changeType)
219 // parts of the if are similar but trying to merge them creates quite some problems (with locks and
222 // Acquiring the lock on old resources to remove notifications, then we can release it. I'm doing
224 // ok (even if the mutex is unlocked). The mutex could be destroyed together with the corresponding
225 // ResourceCollection in ResourcesUser::shareResourcesWith(). Here we also get the list of name of
234 for (QMap<QString, ResourceHandler*>::const_iterator it = m_usableResources.constBegin(); it != m_usableResources.constEnd(); ++it) {
247 // Now we have to update the m_usableResources map to point the the new resource handlers. No resource
249 for (QMap<QString, ResourceHandler*>::iterator it = m_usableResources.begin(); it != m_usableResources.end(); ++it) {
254 // Before sending notifications, we have to get the lock on all resources and to release the lock on the
269 // Acquiring the lock on old resources to remove notifications, then we can release it. I'm doing
271 // ok (even if the mutex is unlocked). The mutex could be destroyed together with the corresponding
272 // ResourceCollection in ResourcesUser::shareResourcesWith(). Here we also get the list of name of
281 for (QMap<QString, ResourceHandler*>::const_iterator it = m_usableResources.constBegin(); it != m_usableResources.constEnd(); ++it) {
288 // Calling parent function to actually share resources. Here the lock on new resources would be taken
289 // again (but the mutex is not recursive), so we have to temporarly prevent m_resources from locking
294 // Now we have to update the m_usableResources map to point the the new resource handlers. We also create
297 for (QMap<QString, ResourceHandler*>::iterator it = m_usableResources.begin(); it != m_usableResources.end(); ++it) {
306 // Before sending notifications, we have to get the lock on all resources and to release the lock on the
313 // Now we can send all notifications. The changeType to use depends on the status of the resource with a given
314 // name in the new and old set: if a resource existed in the old set and not in the new one, changeType will be
315 // Deleted, if it existed in the old set and is also present in the new one, changeType will be Modified, if it
317 const QSet<QString> deletedResources = m_existingResourcesInOldCollection - m_existingResourcesInNewCollection;
318 const QSet<QString> modifiedResources = m_existingResourcesInOldCollection & m_existingResourcesInNewCollection;
319 const QSet<QString> createdResources = m_existingResourcesInNewCollection - m_existingResourcesInOldCollection;
340 // First of all we have to acquire the lock on the Resource Manager (because we need to call getResource)
354 // Getting the lock on all new resources to send notifications. There is a little overhead, here,
375 // First of all we have to acquire the lock on the Resource Manager (because we need to call getResource)
403 // First of all we have to acquire the lock on the Resource Manager (because we need to call getResource)
419 // Getting the lock on all new resources to send notifications. There is a little overhead, here,
441 // First of all we have to acquire the lock on the Resource Manager (because we need to call getResource)
467 // First of all we have to acquire the lock on the Resource Manager (because we need to call getResource)
477 // Taking the resource handler and then removing the resource (the resource must exist, otherwise there is a
488 // Getting the lock on all deleted resources to send notifications. There is a little overhead, here,
509 // First of all we have to acquire the lock on the Resource Manager (because we need to call getResource)
521 // Getting the lock on all deleted resources to send notifications. There is a little overhead, here,
603 // Locking all resources. To avoid deadlocks here we first acquire the lock on the Resource Manager
614 // Unlocking all resources. Here we have to take the mutex because the unlock of resources must be
615 // atomic (otherwise a lockAll() call can find a resource locked even if we are here because we haven't
627 void ConcurrentResourcesUser::notifyResourceChange(ResourceHandler* resource, ResourceChangeType changeType)
661 // Now locking all our resources. The mutexes for resources are recursive, so they will not fail
662 // if this function is called recursively. Here I assume that locking a mutex never throws... If
void usableResources(QStringList resources)
Defines the list of resources that will be used.
Definition: resourcesuser.cpp:334
A simple class to access/declare resources (not thread-safe)
Definition: resourcesuser.h:227
A class to access/declare resources in a thread-safe way.
Definition: resourcesuser.h:592
void removeUsableResources(QStringList resources)
Removes resources from the list of resources that will be used.
Definition: resourcesuser.cpp:461
virtual void shareResourcesWith(ResourcesUser *other)
The function to share resources.
Definition: resourcesuser.cpp:49
void addUsableResource(QString resource)
Adds a new resource to the list of resources that will be used.
Definition: resourcesuser.cpp:369
virtual void resourceChanged(QString name, ResourceChangeType changeType)
The function called when a resource you use is changed.
Definition: resourcesuser.cpp:160
Definition: configurationhelper.cpp:24
void deleteResource(QString name)
Deletes the resource with the specified name.
Definition: resourcesuser.cpp:147
ResourceCollectionHolder m_resources
The object holding the shared resources.
Definition: resourcesuser.h:143
virtual void shareResourcesWith(ResourcesUser *buddy)
Shares resources with the provided instance of ResourcesUser.
Definition: resourcesuser.cpp:212
virtual void resourceChanged(QString name, ResourceChangeType changeType)
The function called when a resource you use is changed.
Definition: resourcesuser.cpp:596
QWaitCondition & getWaitCondition()
Returns the wait condition on the global resource lock.
Definition: resource.h:501
bool hasResource(QString name) const
Returns true if a resource with name specified has been declared.
Definition: resource.h:555
The exception thrown when requesting a resource never declared.
Definition: configurationexceptions.h:1268
void addUsableResources(QStringList resources)
Adds new resources to the list of resources that will be used.
Definition: resourcesuser.cpp:397
bool hasResource(QString name) const
Returns true if a resource with name specified has been declared.
Definition: resourcesuser.cpp:559
bool usedResourcesExist(QStringList *nonExistingResources=NULL) const
Returns true if all the resources we use exist.
Definition: resourcesuser.cpp:570
The exception thrown when an operation is performed on a ConcurrentResourcesUser object but the lock ...
Definition: configurationexceptions.h:1733
SimpleResourcesUser & operator=(const SimpleResourcesUser &other)
Copy operator.
Definition: resourcesuser.cpp:107
ResourcesLocker(ConcurrentResourcesUser *resourcesUser, bool acquireLock=true)
Constructor.
Definition: resourcesuser.cpp:702
ResourcesUser & operator=(const ResourcesUser &other)
Copy operator.
Definition: resourcesuser.cpp:70
friend class ResourceHandler
The ResourceHandler class is friend to access the notifyResourceChange() function.
Definition: resourcesuser.h:149
virtual void shareResourcesWith(ResourcesUser *other)
The function to share resources.
Definition: resourcesuser.cpp:138
ResourceHandler * getResource(QString name, bool create=false)
Returns a pointer to the resource handler for the resource with the specified name.
Definition: resource.cpp:185
void deleteResource(QString name)
Deletes the resource with the specified name.
Definition: resourcesuser.cpp:536
void removeUsableResource(QString resource)
Removes the resource from the list of resources that will be used.
Definition: resourcesuser.cpp:434
This keeps an instance of ResourceCollection eventually sharing it.
Definition: resource.h:612
void removeAllUsableResources()
Removes all resources from the list of resources that will be used.
Definition: resourcesuser.cpp:503