ctkConfiguration.h 9.7 KB

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