24 #ifndef RESOURCESUSER_H
25 #define RESOURCESUSER_H
27 #include "parametersettable.h"
29 #include "configurationexceptions.h"
33 #include <QStringList>
34 #include <QMutexLocker>
42 class SimpleResourcesUser;
43 class ConcurrentResourcesUser;
44 class ResourcesLocker;
281 void declareResource(QString name, T* resource)
302 T* getResource(QString name)
307 if ((h == NULL) || (!h->
exists())){
311 T* resource = h->
get<T>();
312 if (resource == NULL) {
325 void deleteResource(QString name);
334 bool hasResource(QString name)
const
336 return m_resources->hasResource(name);
351 virtual void resourceChanged(QString name, ResourceChangeType changeType);
368 if (!m_beingNotified) {
372 if (!m_notifiedResourceHandler->exists()) {
376 T* resource = m_notifiedResourceHandler->get<T>();
377 if (resource == NULL) {
394 virtual void notifyResourceChange(
ResourceHandler* resource, ResourceChangeType changeType);
400 void removeAllNotifications();
405 void forceBeingNotified();
413 bool m_beingNotified;
426 QSet<ResourceHandler*> m_observedResources;
631 void usableResources(QStringList resources);
646 void addUsableResource(QString resource);
663 void addUsableResources(QStringList resources);
675 void removeUsableResource(QString resource);
687 void removeUsableResources(QStringList resources);
696 void removeAllUsableResources();
727 void declareResource(QString name, T* resource, QString lockBuddy =
"")
729 if ((m_lockAcquired > 0) || m_beingNotified) {
734 QMutexLocker collectionLocker(&(m_resources->getLock()));
738 if (!lockBuddy.isEmpty()) {
739 ResourceHandler* lockBuddyHandler = m_resources->getResource(lockBuddy,
false);
740 if ((lockBuddyHandler == NULL) || (!lockBuddyHandler->
exists())) {
745 ResourcesMutexesLocker resourceLocker(
this, h);
748 collectionLocker.unlock();
777 T* getResource(QString name,
bool* resourceExists = NULL)
779 if ((m_lockAcquired == 0) && ((!m_beingNotified) || (m_notifiedResourceHandler->name() != name))) {
783 if (!m_usableResources.contains(name)) {
788 if (resourceExists != NULL) {
790 *resourceExists =
true;
794 if (resourceExists != NULL) {
795 *resourceExists =
false;
801 T* resource = h->
get<T>();
802 if (resource == NULL) {
817 void deleteResource(QString name);
829 bool hasResource(QString name)
const;
839 bool usedResourcesExist(QStringList* nonExistingResources = NULL)
const;
859 virtual void resourceChanged(QString name, ResourceChangeType changeType);
875 if (!m_beingNotified) {
876 if (m_lockAcquired > 0) {
883 if (!m_notifiedResourceHandler->exists()) {
887 T* resource = m_notifiedResourceHandler->get<T>();
888 if (resource == NULL) {
921 virtual void notifyResourceChange(
ResourceHandler* resource, ResourceChangeType changeType);
927 void removeAllNotifications();
932 void forceBeingNotified();
942 void lockResources(
const QList<ResourceHandler*>& resources);
952 void unlockResources(
const QList<ResourceHandler*>& resources);
963 class ResourcesMutexesLocker
974 m_resourcesUser(resourcesUser),
975 m_resources(resources)
977 m_resourcesUser->lockResources(m_resources);
987 ResourcesMutexesLocker(ConcurrentResourcesUser *resourcesUser, ResourceHandler* resource) :
988 m_resourcesUser(resourcesUser),
989 m_resources(QList<ResourceHandler *>() << resource)
991 m_resourcesUser->lockResources(m_resources);
1000 ~ResourcesMutexesLocker()
1002 m_resourcesUser->unlockResources(m_resources);
1009 ConcurrentResourcesUser *
const m_resourcesUser;
1014 QList<ResourceHandler *> m_resources;
1024 unsigned int m_lockAcquired;
1032 bool m_beingNotified;
1040 ResourceHandler* m_notifiedResourceHandler;
1045 QMap<QString, ResourceHandler*> m_usableResources;
1050 ConcurrentResourcesUser(
const ConcurrentResourcesUser& other);
1055 ConcurrentResourcesUser& operator=(
const ConcurrentResourcesUser& other);