/*============================================================================= Library: CTK Copyright (c) 2010 German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #ifndef CTKSERVICEREFERENCE_H #define CTKSERVICEREFERENCE_H #include #include "ctkPlugin.h" #include "CTKPluginFrameworkExport.h" namespace ctk { class ServiceRegistrationPrivate; class ServiceReferencePrivate; /** * A reference to a service. * *

* The Framework returns ServiceReference objects from the * PluginContext::getServiceReference and * PluginContext::getServiceReferences methods. *

* A ServiceReference object may be shared between plugins and * can be used to examine the properties of the service and to get the service * object. *

* Every service registered in the Framework has a unique * ServiceRegistration object and may have multiple, distinct * ServiceReference objects referring to it. * ServiceReference objects associated with a * ServiceRegistration are considered equal * (more specifically, their operator==() * method will return true when compared). *

* If the same service object is registered multiple times, * ServiceReference objects associated with different * ServiceRegistration objects are not equal. * * @see PluginContext::getServiceReference * @see PluginContext::getServiceReferences * @see PluginContext::getService * @threadsafe */ class CTK_PLUGINFW_EXPORT ServiceReference { Q_DECLARE_PRIVATE(ServiceReference) public: ~ServiceReference(); /** * Returns the property value to which the specified property key is mapped * in the properties ServiceProperties object of the service * referenced by this ServiceReference object. * *

* Property keys are case-insensitive. * *

* This method must continue to return property values after the service has * been unregistered. This is so references to unregistered services can * still be interrogated. * * @param key The property key. * @return The property value to which the key is mapped; an invalid QVariant * if there is no property named after the key. */ QVariant getProperty(const QString& key) const; /** * Returns a list of the keys in the ServiceProperties * object of the service referenced by this ServiceReference * object. * *

* This method will continue to return the keys after the service has been * unregistered. This is so references to unregistered services can * still be interrogated. * *

* This method is not case-preserving; this means that every key in the * returned array is in lower case, which may not be the case for the corresponding key in the * properties ServiceProperties that was passed to the * {@link PluginContext::registerService(const QStringList&, QObject*, const ServiceProperties&)} or * {@link ServiceRegistration::setProperties} methods. * * @return A list of property keys. */ QStringList getPropertyKeys() const; /** * Returns the plugin that registered the service referenced by this * ServiceReference object. * *

* This method must return 0 when the service has been * unregistered. This can be used to determine if the service has been * unregistered. * * @return The plugin that registered the service referenced by this * ServiceReference object; 0 if that * service has already been unregistered. * @see PluginContext::registerService(const QStringList&, QObject* , const ServiceProperties&) */ Plugin* getPlugin() const; /** * Returns the plugins that are using the service referenced by this * ServiceReference object. Specifically, this method returns * the plugins whose usage count for that service is greater than zero. * * @return A list of plugins whose usage count for the service referenced * by this ServiceReference object is greater than * zero. */ QList getUsingPlugins() const; /** * Compares this ServiceReference with the specified * ServiceReference for order. * *

* If this ServiceReference and the specified * ServiceReference have the same {@link PluginConstants::SERVICE_ID * service id} they are equal. This ServiceReference is less * than the specified ServiceReference if it has a lower * {@link PluginConstants::SERVICE_RANKING service ranking} and greater if it has a * higher service ranking. Otherwise, if this ServiceReference * and the specified ServiceReference have the same * {@link PluginConstants::SERVICE_RANKING service ranking}, this * ServiceReference is less than the specified * ServiceReference if it has a higher * {@link PluginConstants::SERVICE_ID service id} and greater if it has a lower * service id. * * @param reference The ServiceReference to be compared. * @return Returns a false or true if this * ServiceReference is less than or greater * than the specified ServiceReference. * @throws std::invalid_argument If the specified * ServiceReference was not created by the same * framework instance as this ServiceReference. */ bool operator<(const ServiceReference& reference) const; bool operator==(const ServiceReference& reference) const; protected: friend class ServiceRegistrationPrivate; friend class PluginContext; ServiceReference(ServiceRegistrationPrivate* reg); ServiceReferencePrivate * const d_ptr; }; } #endif // CTKSERVICEREFERENCE_H