/*============================================================================= 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 CTKSERVICEREGISTRATION_H #define CTKSERVICEREGISTRATION_H #include "ctkDictionary.h" #include "ctkServiceReference.h" #include "ctkPluginFrameworkExport.h" class ctkServiceRegistrationPrivate; /** * \ingroup PluginFramework * * A registered service. * *
* The Framework returns a ctkServiceRegistration
object when a
* ctkPluginContext#registerService()
method invocation is successful.
* The ctkServiceRegistration
object is for the private use of the
* registering plugin and should not be shared with other plugins.
*
* The ctkServiceRegistration
object may be used to update the
* properties of the service or to unregister the service.
*
* @see ctkPluginContext#registerService()
* @remarks This class is thread safe.
*/
class CTK_PLUGINFW_EXPORT ctkServiceRegistration {
public:
/**
* Creates an invalid ctkServiceRegistration object. You can use
* this object in boolean expressions and it will evaluate to
* false
.
*/
ctkServiceRegistration();
ctkServiceRegistration(const ctkServiceRegistration& reg);
operator bool() const;
/**
* Releases any resources held or locked by this
* ctkServiceRegistration
and renders it invalid.
*/
ctkServiceRegistration& operator=(int null);
~ctkServiceRegistration();
/**
* Returns a ctkServiceReference
object for a service being
* registered.
*
* The ctkServiceReference
object may be shared with other
* plugins.
*
* @throws ctkIllegalStateException If this
* ctkServiceRegistration
object has already been
* unregistered or if it is invalid.
* @return ctkServiceReference
object.
*/
ctkServiceReference getReference() const;
/**
* Updates the properties associated with a service.
*
*
* The {@link ctkPluginConstants#OBJECTCLASS} and {@link ctkPluginConstants#SERVICE_ID} keys * cannot be modified by this method. These values are set by the Framework * when the service is registered in the environment. * *
* The following steps are required to modify service properties: *
ctkServiceRegistration
* object has already been unregistered or if it is invalid.
* @throws ctkInvalidArgumentException If properties
contains
* case variants of the same key name.
*/
void setProperties(const ctkDictionary& properties);
/**
* Unregisters a service. Remove a ctkServiceRegistration
object
* from the Framework service registry. All ctkServiceReference
* objects associated with this ctkServiceRegistration
object
* can no longer be used to interact with the service once unregistration is
* complete.
*
* * The following steps are required to unregister a service: *
ctkServiceReference
objects for the service may no longer be
* used to get a service object for the service.
* ctkServiceFactory#ungetService
method is called to release
* the service object for the plugin.
* ctkServiceRegistration
object has already been
* unregistered or if it is invalid.
* @see ctkPluginContext#ungetService
* @see ctkServiceFactory#ungetService
*/
void unregister();
bool operator<(const ctkServiceRegistration& o) const;
bool operator==(const ctkServiceRegistration& registration) const;
ctkServiceRegistration& operator=(const ctkServiceRegistration& registration);
protected:
friend class ctkServices;
friend class ctkServiceReferencePrivate;
friend uint CTK_PLUGINFW_EXPORT qHash(const ctkServiceRegistration&);
ctkServiceRegistration(ctkServiceRegistrationPrivate* registrationPrivate);
ctkServiceRegistration(ctkPluginPrivate* plugin, QObject* service,
const ctkDictionary& props);
ctkServiceRegistrationPrivate* d_ptr;
private:
Q_DECLARE_PRIVATE(ctkServiceRegistration)
};
/**
* \ingroup PluginFramework
*/
uint CTK_PLUGINFW_EXPORT qHash(const ctkServiceRegistration& serviceRef);
#endif // CTKSERVICEREGISTRATION_H