ctkConfiguration.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 CTKCONFIGURATION_H
  16. #define CTKCONFIGURATION_H
  17. #include <QSharedPointer>
  18. #include "ctkDictionary.h"
  19. /**
  20. * The configuration information for a <code>ctkManagedService</code> or
  21. * <code>ctkManagedServiceFactory</code> object.
  22. *
  23. * The Configuration Admin service uses this interface to represent the
  24. * configuration information for a <code>ctkManagedService</code> or for a
  25. * service instance of a <code>ctkManagedServiceFactory</code>.
  26. *
  27. * <p>
  28. * A <code>ctkConfiguration</code> object contains a configuration dictionary and
  29. * allows the properties to be updated via this object. Plugins wishing to
  30. * receive configuration dictionaries do not need to use this class - they
  31. * register a <code>ctkManagedService</code> or
  32. * <code>ctkManagedServiceFactory</code>. Only administrative plugins, and
  33. * plugins wishing to update their own configurations need to use this class.
  34. *
  35. * <p>
  36. * The properties handled in this configuration have case insensitive
  37. * <code>QString</code> objects as keys. However, case is preserved from the
  38. * last set key/value.
  39. * <p>
  40. * A configuration can be <i>bound </i> to a plugin location (
  41. * <code>ctkPlugin#getLocation()</code>). The purpose of binding a
  42. * <code>ctkConfiguration</code> object to a location is to make it impossible
  43. * for another plugin to forge a PID that would match this configuration. When a
  44. * configuration is bound to a specific location, and a plugin with a different
  45. * location registers a corresponding <code>ctkManagedService</code> object or
  46. * <code>ctkManagedServiceFactory</code> object, then the configuration is not
  47. * passed to the updated method of that object.
  48. *
  49. * <p>
  50. * If a configuration's location is empty, it is not yet bound to
  51. * a location. It will become bound to the location of the first plugin that
  52. * registers a <code>ctkManagedService</code> or
  53. * <code>ctkManagedServiceFactory</code> object with the corresponding PID.
  54. * <p>
  55. * The same <code>ctkConfiguration</code> object is used for configuring both a
  56. * Managed Service Factory and a Managed Service. When it is important to
  57. * differentiate between these two the term "factory configuration" is used.
  58. *
  59. * @noimplement
  60. * @version
  61. */
  62. struct CTK_PLUGINFW_EXPORT ctkConfiguration
  63. {
  64. virtual ~ctkConfiguration();
  65. /**
  66. * Get the PID for this <code>ctkConfiguration</code> object.
  67. *
  68. * @return the PID for this <code>ctkConfiguration</code> object.
  69. * @throws std::logic_error if this configuration has been deleted
  70. */
  71. virtual QString getPid() const = 0;
  72. /**
  73. * Return the properties of this <code>ctkConfiguration</code> object.
  74. *
  75. * The <code>Dictionary</code> object returned is a private copy for the
  76. * caller and may be changed without influencing the stored configuration.
  77. * The keys in the returned dictionary are case insensitive and are always
  78. * of type <code>String</code>.
  79. *
  80. * <p>
  81. * If called just after the configuration is created and before update has
  82. * been called, this method returns <code>null</code>.
  83. *
  84. * @return A private copy of the properties for the caller or
  85. * <code>null</code>. These properties must not contain the
  86. * "service.bundleLocation" property. The value of this property may
  87. * be obtained from the <code>getBundleLocation</code> method.
  88. * @throws IllegalStateException if this configuration has been deleted
  89. */
  90. virtual ctkDictionary getProperties() const = 0;
  91. /**
  92. * Update the properties of this <code>ctkConfiguration</code> object.
  93. *
  94. * Stores the properties in persistent storage after adding or overwriting
  95. * the following properties:
  96. * <ul>
  97. * <li>"service.pid" : is set to be the PID of this configuration.</li>
  98. * <li>"service.factoryPid" : if this is a factory configuration it is set
  99. * to the factory PID else it is not set.</li>
  100. * </ul>
  101. * These system properties are all of type <code>QString</code>.
  102. *
  103. * <p>
  104. * If the corresponding Managed Service/Managed Service Factory is
  105. * registered, its updated method must be called asynchronously. Else, this
  106. * callback is delayed until aforementioned registration occurs.
  107. *
  108. * <p>
  109. * Also initiates an asynchronous call to all
  110. * <code>ctkConfigurationListener</code>s with a
  111. * <code>ctkConfigurationEvent::CM_UPDATED</code> event.
  112. *
  113. * @param properties the new set of properties for this configuration
  114. * @throws ctkIOException if update cannot be made persistent
  115. * @throws std::invalid_argument if the <code>ctkDictionary</code> object
  116. * contains invalid configuration types or contains case variants of
  117. * the same key name.
  118. * @throws std::logic_error if this configuration has been deleted
  119. */
  120. virtual void update(const ctkDictionary& properties) = 0;
  121. /**
  122. * Delete this <code>ctkConfiguration</code> object.
  123. *
  124. * Removes this configuration object from the persistent store. Notify
  125. * asynchronously the corresponding Managed Service or Managed Service
  126. * Factory. A <code>ctkManagedService</code> object is notified by a call to
  127. * its <code>updated</code> method with a <code>null</code> properties
  128. * argument. A <code>ctkManagedServiceFactory</code> object is notified by a
  129. * call to its <code>deleted</code> method.
  130. *
  131. * <p>
  132. * Also initiates an asynchronous call to all
  133. * <code>ctkConfigurationListener</code>s with a
  134. * <code>ctkConfigurationEvent::CM_DELETED</code> event.
  135. *
  136. * @throws ctkIOException If delete fails
  137. * @throws std::logic_error if this configuration has been deleted
  138. */
  139. virtual void remove() = 0;
  140. /**
  141. * For a factory configuration return the PID of the corresponding Managed
  142. * Service Factory, else return a null QString.
  143. *
  144. * @return factory PID or <code>null</code>
  145. * @throws std::logic_error if this configuration has been deleted
  146. */
  147. virtual QString getFactoryPid() const = 0;
  148. /**
  149. * Update the <code>ctkConfiguration</code> object with the current
  150. * properties.
  151. *
  152. * Initiate the <code>updated</code> callback to the Managed Service or
  153. * Managed Service Factory with the current properties asynchronously.
  154. *
  155. * <p>
  156. * This is the only way for a plugin that uses a Configuration Plugin
  157. * service to initiate a callback. For example, when that plugin detects a
  158. * change that requires an update of the Managed Service or Managed Service
  159. * Factory via its <code>ctkConfigurationPlugin</code> object.
  160. *
  161. * @see ctkConfigurationPlugin
  162. * @throws ctkIOException if update cannot access the properties in persistent
  163. * storage
  164. * @throws std::logic_error if this configuration has been deleted
  165. */
  166. virtual void update() = 0;
  167. /**
  168. * Bind this <code>ctkConfiguration</code> object to the specified plugin
  169. * location.
  170. *
  171. * If the pluginLocation parameter is <code>null</code> then the
  172. * <code>ctkConfiguration</code> object will not be bound to a location. It
  173. * will be set to the plugin's location before the first time a Managed
  174. * Service/Managed Service Factory receives this <code>ctkConfiguration</code>
  175. * object via the updated method and before any plugins are called. The
  176. * plugin location will be set persistently.
  177. *
  178. * @param pluginLocation a plugin location or <code>null</code>.
  179. * @throws std::logic_error If this configuration has been deleted.
  180. * @throws ctkSecurityException If the caller does not have
  181. * <code>ctkConfigurationPermission[*,CONFIGURE]</code>.
  182. */
  183. virtual void setPluginLocation(const QString& pluginLocation) = 0;
  184. /**
  185. * Get the plugin location.
  186. *
  187. * Returns the plugin location to which this configuration is bound, or
  188. * <code>null</code> if it is not yet bound to a plugin location.
  189. *
  190. * @return location to which this configuration is bound, or
  191. * <code>null</code>.
  192. * @throws std::logic_error If this <code>Configuration</code> object
  193. * has been deleted.
  194. * @throws ctkSecurityException If the caller does not have
  195. * <code>ctkConfigurationPermission[*,CONFIGURE]</code>.
  196. */
  197. virtual QString getPluginLocation() const = 0;
  198. /**
  199. * Equality is defined to have equal PIDs
  200. *
  201. * Two Configuration objects are equal when their PIDs are equal.
  202. *
  203. * @param other <code>ctkConfiguration</code> object to compare against
  204. * @return <code>true} if equal, {@code false</code> if the PID's differ.
  205. */
  206. bool operator==(const ctkConfiguration& other) const;
  207. };
  208. typedef QSharedPointer<ctkConfiguration> ctkConfigurationPtr;
  209. /**
  210. * Hash code is based on PID.
  211. *
  212. * The hashcode for two ctkConfiguration objects must be the same when the
  213. * Configuration PID's are the same.
  214. *
  215. * @param configuration The configuration object for which to compute the hash value.
  216. * @return hash code for this ctkConfiguration object
  217. */
  218. uint CTK_PLUGINFW_EXPORT qHash(ctkConfigurationPtr configuration);
  219. bool CTK_PLUGINFW_EXPORT operator==(const ctkConfigurationPtr& c1, const ctkConfigurationPtr c2);
  220. #endif // CTKCONFIGURATION_H