ctkBasicLocation_p.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 CTKBASICLOCATION_H
  16. #define CTKBASICLOCATION_H
  17. #include <service/datalocation/ctkLocation.h>
  18. #include <QUrl>
  19. #include <QString>
  20. #include <QFileInfo>
  21. #include <QReadWriteLock>
  22. class ctkBasicLocation : public QObject, public ctkLocation
  23. {
  24. Q_OBJECT
  25. Q_INTERFACES(ctkLocation)
  26. public:
  27. ctkBasicLocation(const QString& property, const QUrl& defaultValue,
  28. bool isReadOnly, const QString& dataAreaPrefix);
  29. ~ctkBasicLocation();
  30. bool allowsDefault() const;
  31. QUrl getDefault() const;
  32. ctkLocation* getParentLocation() const;
  33. QUrl getUrl() const;
  34. bool isSet() const;
  35. bool isReadOnly() const;
  36. bool set(const QUrl& value, bool lock);
  37. bool set(const QUrl& value, bool lock, const QString& lockFilePath);
  38. bool lock();
  39. void release();
  40. bool isLocked() const;
  41. ctkLocation* createLocation(ctkLocation* parent, const QUrl& defaultValue, bool readonly);
  42. QUrl getDataArea(const QString& path) const;
  43. void setParent(ctkLocation* parent);
  44. struct Locker;
  45. private:
  46. struct MockLocker;
  47. class FileLocker;
  48. bool m_isReadOnly;
  49. QUrl m_location;
  50. QScopedPointer<ctkLocation> m_parent;
  51. QUrl m_defaultValue;
  52. QString m_property;
  53. QString m_dataAreaPrefix;
  54. // locking related fields
  55. QFileInfo m_lockFile;
  56. Locker* m_locker;
  57. mutable QReadWriteLock m_sync;
  58. bool isSet_unlocked() const;
  59. bool set_unlocked(const QUrl& value, bool lock);
  60. bool set_unlocked(const QUrl& value, bool lock, const QString& lockFilePath);
  61. bool lock_unlocked(const QFileInfo& lock, const QUrl& locationValue);
  62. void setLocker_unlocked(const QFileInfo& lock);
  63. Locker* createLocker_unlocked(const QFileInfo& lock, const QString& lockMode);
  64. bool isLocked_unlocked(const QFileInfo& lock) const;
  65. };
  66. #endif // CTKBASICLOCATION_H