/*============================================================================= Library: CTK Copyright (c) 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 #include "ctkPlugin.h" #include "ctkPluginFrameworkExport.h" class ctkServiceRegistrationPrivate; class ctkServiceReferencePrivate; class ctkServiceEvent; /** * \ingroup PluginFramework * * A reference to a service. * *

* The Framework returns ctkServiceReference objects from the * ctkPluginContext::getServiceReference and * ctkPluginContext::getServiceReferences methods. *

* A ctkServiceReference 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 * ctkServiceRegistration object and may have multiple, distinct * ctkServiceReference objects referring to it. * ctkServiceReference objects associated with a * ctkServiceRegistration are considered equal * (more specifically, their operator==() * method will return true when compared). *

* If the same service object is registered multiple times, * ctkServiceReference objects associated with different * ctkServiceRegistration objects are not equal. * * @see ctkPluginContext::getServiceReference * @see ctkPluginContext::getServiceReferences * @see ctkPluginContext::getService * @remarks This class is thread safe. */ class CTK_PLUGINFW_EXPORT ctkServiceReference { Q_DECLARE_PRIVATE(ctkServiceReference) public: /** * Creates an invalid ctkServiceReference object. You can use * this object in boolean expressions and it will evaluate to * false. */ ctkServiceReference(); ctkServiceReference(const ctkServiceReference& ref); /** * Converts this ctkServiceReference instance into a boolean * expression. If this instance was default constructed or * the service it references has been unregistered, the conversion * returns false, otherwise it returns true. */ operator bool() const; /** * Releases any resources held or locked by this * ctkServiceReference and renders it invalid. */ ctkServiceReference& operator=(int null); ~ctkServiceReference(); /** * Returns the property value to which the specified property key is mapped * in the properties ctkDictionary object of the service * referenced by this ctkServiceReference 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 ctkDictionary * object of the service referenced by this ctkServiceReference * 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 ctkDictionary that was passed to the * {@link ctkPluginContext::registerService(const QStringList&, QObject*, const ctkDictionary&)} or * {@link ctkServiceRegistration::setProperties} methods. * * @return A list of property keys. */ QStringList getPropertyKeys() const; /** * Returns the plugin that registered the service referenced by this * ctkServiceReference 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 * ctkServiceReference object; 0 if that * service has already been unregistered. * @see ctkPluginContext::registerService(const QStringList&, QObject* , const ctkDictionary&) */ QSharedPointer getPlugin() const; /** * Returns the plugins that are using the service referenced by this * ctkServiceReference 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 ctkServiceReference object is greater than * zero. */ QList > getUsingPlugins() const; /** * Compares this ctkServiceReference with the specified * ctkServiceReference for order. * *

* If this ctkServiceReference and the specified * ctkServiceReference have the same {@link ctkPluginConstants::SERVICE_ID * service id} they are equal. This ctkServiceReference is less * than the specified ctkServiceReference if it has a lower * {@link ctkPluginConstants::SERVICE_RANKING service ranking} and greater if it has a * higher service ranking. Otherwise, if this ctkServiceReference * and the specified ctkServiceReference have the same * {@link ctkPluginConstants::SERVICE_RANKING service ranking}, this * ctkServiceReference is less than the specified * ctkServiceReference if it has a higher * {@link ctkPluginConstants::SERVICE_ID service id} and greater if it has a lower * service id. * * @param reference The ctkServiceReference to be compared. * @return Returns a false or true if this * ctkServiceReference is less than or greater * than the specified ctkServiceReference. * @throws std::invalid_argument If the specified * ctkServiceReference was not created by the same * framework instance as this ctkServiceReference. */ bool operator<(const ctkServiceReference& reference) const; bool operator==(const ctkServiceReference& reference) const; ctkServiceReference& operator=(const ctkServiceReference& reference); protected: friend class ctkLDAPSearchFilter; friend class ctkServiceRegistrationPrivate; friend class ctkPluginContext; friend class ctkPluginPrivate; friend class ctkPluginFrameworkListeners; template friend class ctkServiceTracker; template friend class ctkServiceTrackerPrivate; template friend class ctkPluginAbstractTracked; friend uint CTK_PLUGINFW_EXPORT qHash(const ctkServiceReference&); ctkServiceReference(ctkServiceRegistrationPrivate* reg); ctkServiceReferencePrivate * d_ptr; }; /** * \ingroup PluginFramework * @{ */ uint CTK_PLUGINFW_EXPORT qHash(const ctkServiceReference& serviceRef); QDebug CTK_PLUGINFW_EXPORT operator<<(QDebug dbg, const ctkServiceReference& serviceRef); /** @}*/ Q_DECLARE_METATYPE(ctkServiceReference) #endif // CTKSERVICEREFERENCE_H