1 /*============================================================================= 2 3 Library: CTK 4 5 Copyright (c) German Cancer Research Center, 6 Division of Medical and Biological Informatics 7 8 Licensed under the Apache License, Version 2.0 (the "License"); 9 you may not use this file except in compliance with the License. 10 You may obtain a copy of the License at 11 12 http://www.apache.org/licenses/LICENSE-2.0 13 14 Unless required by applicable law or agreed to in writing, software 15 distributed under the License is distributed on an "AS IS" BASIS, 16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 See the License for the specific language governing permissions and 18 limitations under the License. 19 20 =============================================================================*/ 21 22 23 #ifndef CTKCONFIGURATIONIMPL_P_H 24 #define CTKCONFIGURATIONIMPL_P_H 25 26 #include <service/cm/ctkConfiguration.h> 27 28 #include <QMutex> 29 #include <QWaitCondition> 30 31 class ctkConfigurationAdminFactory; 32 class ctkConfigurationStore; 33 class ctkPlugin; 34 35 /** 36 * ctkConfigurationImpl provides the ctkConfiguration implementation. 37 * The lock and unlock methods are used for synchronization. Operations outside of 38 * ConfigurationImpl that expect to have control of the lock should call checkLocked 39 */ 40 class ctkConfigurationImpl : public ctkConfiguration 41 { 42 43 public: 44 45 ctkConfigurationImpl(ctkConfigurationAdminFactory* configurationAdminFactory, 46 ctkConfigurationStore* configurationStore, 47 const QString& factoryPid, const QString& pid, 48 const QString& pluginLocation); 49 50 ctkConfigurationImpl(ctkConfigurationAdminFactory* configurationAdminFactory, 51 ctkConfigurationStore* configurationStore, 52 const ctkDictionary& dictionary); 53 54 void remove(); 55 56 QString getPluginLocation() const; 57 QString getFactoryPid() const; 58 QString getPid() const; 59 ctkDictionary getProperties() const; 60 61 void setPluginLocation(const QString& pluginLocation); 62 63 void update(); 64 void update(const ctkDictionary& properties); 65 66 void checkLocked() const; 67 68 bool bind(QSharedPointer<ctkPlugin> plugin); 69 void unbind(QSharedPointer<ctkPlugin> plugin); 70 71 QString getPluginLocation(bool checkPermission) const; 72 QString getFactoryPid(bool checkDeleted) const; 73 QString getPid(bool checkDeleted) const; 74 ctkDictionary getAllProperties() const; 75 76 void lock() const; 77 void unlock() const; 78 79 bool isDeleted() const; 80 81 private: 82 83 typedef ctkDictionary ctkConfigurationDictionary; 84 85 mutable QMutex mutex; 86 mutable QWaitCondition waitCond; 87 88 ctkConfigurationAdminFactory* configurationAdminFactory; 89 ctkConfigurationStore* configurationStore; 90 /** @GuardedBy mutex*/ 91 QString pluginLocation; 92 QString factoryPid; 93 QString pid; 94 ctkConfigurationDictionary dictionary; 95 /** @GuardedBy mutex*/ 96 bool deleted; 97 /** @GuardedBy mutex*/ 98 QSharedPointer<ctkPlugin> boundPlugin; 99 /** @GuardedBy mutex*/ 100 mutable int lockedCount; 101 /** @GuardedBy mutex*/ 102 mutable QThread* lockHolder; 103 104 void checkDeleted() const; 105 106 void updateDictionary(const ctkDictionary& properties); 107 108 }; 109 110 typedef QSharedPointer<ctkConfigurationImpl> ctkConfigurationImplPtr; 111 112 class ctkConfigurationImplLocker 113 { 114 public: 115 116 ctkConfigurationImplLocker(const ctkConfigurationImpl* impl); 117 ctkConfigurationImplLocker(const QList<ctkConfigurationImplPtr>& implList); 118 ~ctkConfigurationImplLocker(); 119 120 private: 121 122 const ctkConfigurationImpl* impl; 123 QList<ctkConfigurationImplPtr> implList; 124 }; 125 126 #endif // CTKCONFIGURATIONIMPL_P_H 127