ctkConfiguration.h 9.8 KB

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