ctkConfigurationAdmin.h 12 KB

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