ctkConfigurationImpl_p.h 3.5 KB

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