ctkLocation.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 CTKLOCATION_H
  16. #define CTKLOCATION_H
  17. #include <ctkPluginFrameworkExport.h>
  18. #include <QObject>
  19. class QUrl;
  20. /**
  21. * A ctkLocation represents a QUrl which may have a default value, may be read only, may
  22. * or may not have a current value and may be cascaded on to a parent location.
  23. */
  24. struct CTK_PLUGINFW_EXPORT ctkLocation
  25. {
  26. /**
  27. * Constant which defines the filter string for acquiring the service which
  28. * specifies the instance location.
  29. */
  30. static const QString INSTANCE_FILTER;
  31. /**
  32. * Constant which defines the filter string for acquiring the service which
  33. * specifies the install location.
  34. */
  35. static const QString INSTALL_FILTER;
  36. /**
  37. * Constant which defines the filter string for acquiring the service which
  38. * specifies the configuration location.
  39. */
  40. static const QString CONFIGURATION_FILTER;
  41. /**
  42. * Constant which defines the filter string for acquiring the service which
  43. * specifies the user location.
  44. */
  45. static const QString USER_FILTER;
  46. /**
  47. * Constant which defines the filter string for acquiring the service which
  48. * specifies the eclipse home location.
  49. */
  50. static const QString CTK_HOME_FILTER;
  51. virtual ~ctkLocation() {}
  52. /**
  53. * Returns <code>true</code> if this location allows a default value to be assigned
  54. * and <code>false</code> otherwise.
  55. *
  56. * @return whether or not this location can have a default value assigned
  57. */
  58. virtual bool allowsDefault() const = 0;
  59. /**
  60. * Returns the default value of this location if any. If no default is available then
  61. * <code>null</code> is returned. Note that even locations which allow defaults may still
  62. * return <code>null</code>.
  63. *
  64. * @return the default value for this location or <code>null</code>
  65. */
  66. virtual QUrl getDefault() const = 0;
  67. /**
  68. * Returns the parent of this location or <code>null</code> if none is available.
  69. *
  70. * @return the parent of this location or <code>null</code>
  71. */
  72. virtual ctkLocation* getParentLocation() const = 0;
  73. /**
  74. * Returns the actual QUrl of this location. If the location's value has been set,
  75. * that value is returned. If the value is not set and the location allows defaults,
  76. * the value is set to the default and returned. In all other cases <code>null</code>
  77. * is returned.
  78. *
  79. * @return the URL for this location or <code>null</code> if none
  80. */
  81. virtual QUrl getUrl() const = 0;
  82. /**
  83. * Returns <code>true</code> if this location has a value and <code>false</code>
  84. * otherwise.
  85. *
  86. * @return boolean value indicating whether or not the value is set
  87. */
  88. virtual bool isSet() const = 0;
  89. /**
  90. * Returns <code>true</code> if this location represents a read only location and
  91. * <code>false</code> otherwise. The read only character
  92. * of a location is not in enforced in any way but rather expresses the intention of the
  93. * location's creator.
  94. *
  95. * @return boolean value indicating whether the location is read only
  96. */
  97. virtual bool isReadOnly() const = 0;
  98. /**
  99. * Sets and optionally locks the location's value to the given QUrl. If the location
  100. * already has a value an exception is thrown. If locking is requested and fails, <code>false</code>
  101. * is returned and the QUrl of this location is not set.
  102. *
  103. * @param value the value of this location
  104. * @param lock whether or not to lock this location
  105. * @return whether or not the location was successfully set and, if requested, locked.
  106. * @throws ctkIllegalStateException if the location's value is already set
  107. * @throws ctkRuntimeException if there was an unexpected problem while acquiring the lock
  108. */
  109. virtual bool set(const QUrl& value, bool lock) = 0;
  110. /**
  111. * Sets and optionally locks the location's value to the given QUrl using the given lock file. If the location
  112. * already has a value an exception is thrown. If locking is requested and fails, <code>false</code>
  113. * is returned and the QUrl of this location is not set.
  114. *
  115. * @param value the value of this location
  116. * @param lock whether or not to lock this location
  117. * @param lockFilePath the path to the lock file. This path will be used to establish locks on this location.
  118. * The path may be an absolute path or it may be relative to the given URL. If a <code>null</code>
  119. * value is used then a default lock path will be used for this location.
  120. * @return whether or not the location was successfully set and, if requested, locked.
  121. * @throws ctkIllegalStateException if the location's value is already set
  122. * @throws ctkRuntimeException if there was an unexpected problem while acquiring the lock
  123. */
  124. virtual bool set(const QUrl& value, bool lock, const QString& lockFilePath) = 0;
  125. /**
  126. * Attempts to lock this location with a canonical locking mechanism and return
  127. * <code>true</code> if the lock could be acquired. Not all locations can be
  128. * locked.
  129. * <p>
  130. * Locking a location is advisory only. That is, it does not prevent other applications from
  131. * modifying the same location
  132. * </p>
  133. * @return true if the lock could be acquired; otherwise false is returned
  134. *
  135. * @exception ctkRuntimeException if there was an unexpected problem while acquiring the lock
  136. */
  137. virtual bool lock() = 0;
  138. /**
  139. * Releases the lock on this location. If the location is not already locked, no action
  140. * is taken.
  141. */
  142. virtual void release() = 0;
  143. /**
  144. * Returns <code>true</code> if this location is locked and <code>false</code>
  145. * otherwise.
  146. * @return boolean value indicating whether or not this location is locked
  147. * @throws ctkRuntimeException if there was an unexpected problem reading the lock
  148. */
  149. virtual bool isLocked() const = 0;
  150. /**
  151. * Constructs a new location.
  152. * @param parent the parent location. A <code>null</code> value is allowed.
  153. * @param defaultValue the default value of the location. A <code>null</code> value is allowed.
  154. * @param readonly true if the location is read-only.
  155. * @return a new location.
  156. */
  157. virtual ctkLocation* createLocation(ctkLocation* parent, const QUrl& defaultValue, bool readonly) = 0;
  158. /**
  159. * Returns a URL to the specified path within this location. The path
  160. * of the returned URL may not exist yet. It is the responsibility of the
  161. * client to create the content of the data area returned if it does not exist.
  162. * <p>
  163. * This method can be used to obtain a private area within the given location.
  164. * For example use the symbolic name of a plugin to obtain a data area specific
  165. * to that plugin.
  166. * </p>
  167. * <p>
  168. * Clients should check if the location is read only before writing anything
  169. * to the returned data area. An <code>ctkRuntimeException</code> will be thrown if
  170. * this method is called and the location URL has not been set and there is
  171. * no default value for this location.
  172. * </p>
  173. *
  174. * @param path the name of the path to get from this location
  175. * @return the URL to the data area with the specified path.
  176. * @throws ctkRuntimeException if the location URL is not already set
  177. */
  178. virtual QUrl getDataArea(const QString& path) const = 0;
  179. };
  180. Q_DECLARE_INTERFACE(ctkLocation, "org.commontk.service.datalocation.Location")
  181. #endif // CTKLOCATION_H