ctkConfigurationAdmin.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 CTKCONFIGURATIONADMIN_H
  16. #define CTKCONFIGURATIONADMIN_H
  17. #include "ctkConfiguration.h"
  18. /**
  19. * \ingroup ConfigAdmin
  20. * Service for administering configuration data.
  21. *
  22. * <p>
  23. * The main purpose of this interface is to store plugin configuration data
  24. * persistently. This information is represented in <code>ctkConfiguration</code>
  25. * objects. The actual configuration data is a <code>Dictionary</code> of
  26. * properties inside a <code>ctkConfiguration</code> object.
  27. *
  28. * <p>
  29. * There are two principally different ways to manage configurations. First
  30. * there is the concept of a Managed Service, where configuration data is
  31. * uniquely associated with an object registered with the service registry.
  32. *
  33. * <p>
  34. * Next, there is the concept of a factory where the Configuration Admin service
  35. * will maintain 0 or more <code>ctkConfiguration</code> objects for a Managed
  36. * Service Factory that is registered with the Framework.
  37. *
  38. * <p>
  39. * The first concept is intended for configuration data about "things/services"
  40. * whose existence is defined externally, e.g. a specific printer. Factories are
  41. * intended for "things/services" that can be created any number of times, e.g.
  42. * a configuration for a DHCP server for different networks.
  43. *
  44. * <p>
  45. * Plugins that require configuration should register a Managed Service or a
  46. * Managed Service Factory in the service registry. A registration property
  47. * named <code>service.pid</code> (persistent identifier or PID) must be used to
  48. * identify this Managed Service or Managed Service Factory to the Configuration
  49. * Admin service.
  50. *
  51. * <p>
  52. * When the ConfigurationAdmin detects the registration of a Managed Service, it
  53. * checks its persistent storage for a configuration object whose
  54. * <code>service.pid</code> property matches the PID service property (
  55. * <code>service.pid</code>) of the Managed Service. If found, it calls
  56. * {@link ctkManagedService#updated} method with the new properties. The
  57. * implementation of a Configuration Admin service must run these call-backs
  58. * asynchronously to allow proper synchronization.
  59. *
  60. * <p>
  61. * When the Configuration Admin service detects a Managed Service Factory
  62. * registration, it checks its storage for configuration objects whose
  63. * <code>service.factoryPid</code> property matches the PID service property of
  64. * the Managed Service Factory. For each such <code>ctkConfiguration</code>
  65. * objects, it calls the <code>ctkManagedServiceFactory#updated</code> method
  66. * asynchronously with the new properties. The calls to the <code>updated</code>
  67. * method of a <code>ctkManagedServiceFactory</code> must be executed sequentially
  68. * and not overlap in time.
  69. *
  70. * <p>
  71. * In general, plugins having permission to use the Configuration Admin service
  72. * can only access and modify their own configuration information. Accessing or
  73. * modifying the configuration of another bundle requires
  74. * <code>ctkConfigurationPermission[*,CONFIGURE]</code>.
  75. *
  76. * <p>
  77. * <code>ctkConfiguration</code> objects can be <i>bound </i> to a specified plugin
  78. * location. In this case, if a matching Managed Service or Managed Service
  79. * Factory is registered by a plugin with a different location, then the
  80. * Configuration Admin service must not do the normal callback, and it should
  81. * log an error. In the case where a <code>ctkConfiguration</code> object is not
  82. * bound, its location field is <code>null</code>, the Configuration Admin
  83. * service will bind it to the location of the plugin that registers the first
  84. * Managed Service or Managed Service Factory that has a corresponding PID
  85. * property. When a <code>ctkConfiguration</code> object is bound to a plugin
  86. * location in this manner, the Configuration Admin service must detect if the
  87. * plugin corresponding to the location is uninstalled. If this occurs, the
  88. * <code>ctkConfiguration</code> object is unbound, that is its location field is
  89. * set back to <code>null</code>.
  90. *
  91. * <p>
  92. * The method descriptions of this class refer to a concept of "the calling
  93. * plugin". This is a loose way of referring to the plugin which obtained the
  94. * Configuration Admin service from the service registry. Implementations of
  95. * <code>ctkConfigurationAdmin</code> must use a
  96. * {@link ctkServiceFactory} to support this concept.
  97. *
  98. */
  99. struct CTK_PLUGINFW_EXPORT ctkConfigurationAdmin
  100. {
  101. /**
  102. * Configuration property naming the Factory PID in the configuration
  103. * dictionary. The property's value is of type <code>QString</code>.
  104. */
  105. static const QString SERVICE_FACTORYPID; // = "service.factoryPid";
  106. /**
  107. * Configuration property naming the location of the plugin that is
  108. * associated with a a <code>ctkConfiguration</code> object. This property can
  109. * be searched for but must not appear in the configuration dictionary for
  110. * security reason. The property's value is of type <code>QString</code>.
  111. */
  112. static const QString SERVICE_PLUGINLOCATION; // = "service.pluginLocation";
  113. /**
  114. * Create a new factory <code>ctkConfiguration</code> object with a new PID.
  115. *
  116. * The properties of the new <code>ctkConfiguration</code> object are
  117. * <code>null</code> until the first time that its
  118. * {@link ctkConfiguration#update(const ctkDictionary&)} method is called.
  119. *
  120. * <p>
  121. * It is not required that the <code>factoryPid</code> maps to a
  122. * registered Managed Service Factory.
  123. * <p>
  124. * The <code>ctkConfiguration</code> object is bound to the location of the
  125. * calling plugin.
  126. *
  127. * @param factoryPid PID of factory (not <code>null</code>).
  128. * @return A new <code>ctkConfiguration</code> object.
  129. * @throws ctkIOException if access to persistent storage fails.
  130. * @throws ctkSecurityException if caller does not have
  131. * <code>ctkConfigurationPermission[*,CONFIGURE]</code> and
  132. * <code>factoryPid</code> is bound to another plugin.
  133. */
  134. virtual ctkConfigurationPtr createFactoryConfiguration(const QString& factoryPid) = 0;
  135. /**
  136. * Create a new factory <code>ctkConfiguration</code> object with a new PID.
  137. *
  138. * The properties of the new <code>ctkConfiguration</code> object are
  139. * <code>null</code> until the first time that its
  140. * {@link ctkConfiguration#update(Dictionary)} method is called.
  141. *
  142. * <p>
  143. * It is not required that the <code>factoryPid</code> maps to a
  144. * registered Managed Service Factory.
  145. *
  146. * <p>
  147. * The <code>ctkConfiguration</code> is bound to the location specified. If
  148. * this location is <code>null</code> it will be bound to the location of
  149. * the first plugin that registers a Managed Service Factory with a
  150. * corresponding PID.
  151. *
  152. * @param factoryPid PID of factory (not <code>null</code>).
  153. * @param location A plugin location string, or <code>null</code>.
  154. * @return a new <code>ctkConfiguration</code> object.
  155. * @throws ctkIOException if access to persistent storage fails.
  156. * @throws ctkSecurityException if caller does not have <code>ctkConfigurationPermission[*,CONFIGURE]</code>.
  157. */
  158. virtual ctkConfigurationPtr createFactoryConfiguration(const QString& factoryPid, const QString& location) = 0;
  159. /**
  160. * Get an existing <code>ctkConfiguration</code> object from the persistent
  161. * store, or create a new <code>ctkConfiguration</code> object.
  162. *
  163. * <p>
  164. * If a <code>ctkConfiguration</code> with this PID already exists in
  165. * Configuration Admin service return it. The location parameter is ignored
  166. * in this case.
  167. *
  168. * <p>
  169. * Else, return a new <code>ctkConfiguration</code> object. This new object
  170. * is bound to the location and the properties are set to <code>null</code>.
  171. * If the location parameter is <code>null</code>, it will be set when a
  172. * Managed Service with the corresponding PID is registered for the first
  173. * time.
  174. *
  175. * @param pid Persistent identifier.
  176. * @param location The plugin location string, or <code>null</code>.
  177. * @return An existing or new <code>ctkConfiguration</code> object.
  178. * @throws ctkIOException if access to persistent storage fails.
  179. * @throws ctkSecurityException if the caller does not have <code>ctkConfigurationPermission[*,CONFIGURE]</code>.
  180. */
  181. virtual ctkConfigurationPtr getConfiguration(const QString& pid, const QString& location) = 0;
  182. /**
  183. * Get an existing or new <code>ctkConfiguration</code> object from the
  184. * persistent store.
  185. *
  186. * If the <code>ctkConfiguration</code> object for this PID does not exist,
  187. * create a new <code>ctkConfiguration</code> object for that PID, where
  188. * properties are <code>null</code>. Bind its location to the calling
  189. * plugin's location.
  190. *
  191. * <p>
  192. * Otherwise, if the location of the existing <code>ctkConfiguration</code> object
  193. * is <code>null</code>, set it to the calling plugin's location.
  194. *
  195. * @param pid persistent identifier.
  196. * @return an existing or new <code>ctkConfiguration</code> matching the PID.
  197. * @throws ctkIOException if access to persistent storage fails.
  198. * @throws ctkSecurityException if the <code>ctkConfiguration</code> object is
  199. * bound to a location different from that of the calling plugin and it
  200. * has no <code>ctkConfigurationPermission[*,CONFIGURE]</code>.
  201. */
  202. virtual ctkConfigurationPtr getConfiguration(const QString& pid) = 0;
  203. /**
  204. * List the current <code>ctkConfiguration</code> objects which match the
  205. * filter.
  206. *
  207. * <p>
  208. * Only <code>ctkConfiguration</code> objects with non- <code>null</code>
  209. * properties are considered current. That is,
  210. * <code>ctkConfiguration#getProperties()</code> is guaranteed not to return
  211. * an empty list for each of the returned <code>ctkConfiguration</code>
  212. * objects.
  213. *
  214. * <p>
  215. * Normally only <code>ctkConfiguration</code> objects that are bound to the
  216. * location of the calling plugin are returned, or all if the caller has
  217. * <code>ctkConfigurationPermission[*,CONFIGURE]</code>.
  218. *
  219. * <p>
  220. * The syntax of the filter string is as defined in the
  221. * {@link ctkLDAPSearchFilter} class. The filter can test any
  222. * configuration properties including the following:
  223. * <ul>
  224. * <li><code>service.pid</code>-<code>QString</code>- the PID under which
  225. * this is registered</li>
  226. * <li><code>service.factoryPid</code>-<code>QString</code>- the factory if
  227. * applicable</li>
  228. * <li><code>service.pluginLocation</code>-<code>QString</code>- the plugin
  229. * location</li>
  230. * </ul>
  231. * The filter can also be empty, meaning that all
  232. * <code>ctkConfiguration</code> objects should be returned.
  233. *
  234. * @param filter A filter string, or an empty string to retrieve all
  235. * <code>ctkConfiguration</code> objects.
  236. * @return All matching <code>ctkConfiguration</code> objects, or
  237. * an empty list if there aren't any.
  238. * @throws ctkIOException if access to persistent storage fails
  239. * @throws std::invalid_argument if the filter string is invalid
  240. */
  241. virtual QList<ctkConfigurationPtr> listConfigurations(const QString& filter = QString()) = 0;
  242. };
  243. Q_DECLARE_INTERFACE(ctkConfigurationAdmin, "org.commontk.service.cm.ConfigurationAdmin")
  244. #endif // CTKCONFIGURATIONADMIN_H