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;
803 T* resource = h->
get<T>();
804 if (resource == NULL) {
819 void deleteResource(QString name);
831 bool hasResource(QString name)
const;
841 bool usedResourcesExist(QStringList* nonExistingResources = NULL)
const;
861 virtual void resourceChanged(QString name, ResourceChangeType changeType);
877 if (!m_beingNotified) {
878 if (m_lockAcquired > 0) {
885 if (!m_notifiedResourceHandler->exists()) {
889 T* resource = m_notifiedResourceHandler->get<T>();
890 if (resource == NULL) {
923 virtual void notifyResourceChange(
ResourceHandler* resource, ResourceChangeType changeType);
929 void removeAllNotifications();
934 void forceBeingNotified();
944 void lockResources(
const QList<ResourceHandler*>& resources);
954 void unlockResources(
const QList<ResourceHandler*>& resources);
965 class ResourcesMutexesLocker
976 m_resourcesUser(resourcesUser),
977 m_resources(resources)
979 m_resourcesUser->lockResources(m_resources);
989 ResourcesMutexesLocker(ConcurrentResourcesUser *resourcesUser, ResourceHandler* resource) :
990 m_resourcesUser(resourcesUser),
991 m_resources(QList<ResourceHandler *>() << resource)
993 m_resourcesUser->lockResources(m_resources);
1002 ~ResourcesMutexesLocker()
1004 m_resourcesUser->unlockResources(m_resources);
1011 ConcurrentResourcesUser *
const m_resourcesUser;
1016 QList<ResourceHandler *> m_resources;
1026 unsigned int m_lockAcquired;
1034 bool m_beingNotified;
1042 ResourceHandler* m_notifiedResourceHandler;
1047 QMap<QString, ResourceHandler*> m_usableResources;
1052 ConcurrentResourcesUser(
const ConcurrentResourcesUser& other);
1057 ConcurrentResourcesUser& operator=(
const ConcurrentResourcesUser& other);