Medical Imaging Interaction Toolkit
2024.12.99-0da743f6
Medical Imaging Interaction Toolkit
|
#include <usServiceTracker.h>
Public Types | |
typedef S | ServiceType |
The type of the service being tracked. More... | |
typedef TTT::TrackedType | T |
The type of the tracked object. More... | |
typedef ServiceReference< S > | ServiceReferenceType |
typedef std::map< ServiceReference< S >, T > | TrackingMap |
Public Member Functions | |
~ServiceTracker () override | |
ServiceTracker (ModuleContext *context, const ServiceReferenceType &reference, ServiceTrackerCustomizer< S, T > *customizer=nullptr) | |
ServiceTracker (ModuleContext *context, const std::string &clazz, ServiceTrackerCustomizer< S, T > *customizer=0) | |
ServiceTracker (ModuleContext *context, const LDAPFilter &filter, ServiceTrackerCustomizer< S, T > *customizer=nullptr) | |
ServiceTracker (ModuleContext *context, ServiceTrackerCustomizer< S, T > *customizer=nullptr) | |
virtual void | Open () |
virtual void | Close () |
virtual T | WaitForService (unsigned long timeoutMillis=0) |
virtual std::vector< ServiceReferenceType > | GetServiceReferences () const |
virtual ServiceReferenceType | GetServiceReference () const |
virtual T | GetService (const ServiceReferenceType &reference) const |
virtual std::vector< T > | GetServices () const |
virtual T | GetService () const |
virtual void | Remove (const ServiceReferenceType &reference) |
virtual int | Size () const |
virtual int | GetTrackingCount () const |
virtual void | GetTracked (TrackingMap &tracked) const |
virtual bool | IsEmpty () const |
Protected Member Functions | |
T | AddingService (const ServiceReferenceType &reference) override |
void | ModifiedService (const ServiceReferenceType &reference, T service) override |
void | RemovedService (const ServiceReferenceType &reference, T service) override |
Protected Member Functions inherited from us::ServiceTrackerCustomizer< S, TrackedTypeTraits< S, S * > ::TrackedType > | |
virtual | ~ServiceTrackerCustomizer () |
virtual TrackedType | AddingService (const ServiceReferenceType &reference)=0 |
virtual void | ModifiedService (const ServiceReferenceType &reference, TrackedType service)=0 |
virtual void | RemovedService (const ServiceReferenceType &reference, TrackedType service)=0 |
Additional Inherited Members | |
Protected Types inherited from us::ServiceTrackerCustomizer< S, TrackedTypeTraits< S, S * > ::TrackedType > | |
typedef S | ServiceType |
typedef TrackedTypeTraits< S, S * > ::TrackedType | TrackedType |
typedef ServiceReference< ServiceType > | ServiceReferenceType |
The ServiceTracker
class simplifies using services from the framework's service registry.
A ServiceTracker
object is constructed with search criteria and a ServiceTrackerCustomizer
object. A ServiceTracker
can use a ServiceTrackerCustomizer
to customize the service objects to be tracked. The ServiceTracker
can then be opened to begin tracking all services in the framework's service registry that match the specified search criteria. The ServiceTracker
correctly handles all of the details of listening to ServiceEvent
s and getting and ungetting services.
The GetServiceReferences
method can be called to get references to the services being tracked. The GetService
and GetServices
methods can be called to get the service objects for the tracked service.
ServiceTracker
class is thread-safe. It does not call a ServiceTrackerCustomizer
while holding any locks. ServiceTrackerCustomizer
implementations must also be thread-safe.Customization of the services to be tracked requires a custom tracked type traits class if the custom tracked type is not a pointer type. To customize a tracked service using a custom type with value-semantics like
the custom tracked type traits class should look like this:
For a custom tracked type, a ServiceTrackerCustomizer is required, which knows how to associate the tracked service with the custom tracked type:
The custom tracking type traits class and customizer can now be used to instantiate a ServiceTracker:
If the custom tracked type is a pointer type, a suitable tracked type traits template is provided by the framework and only a ServiceTrackerCustomizer needs to be provided:
S | The type of the service being tracked. The type S* must be an assignable datatype. |
TTT | Type traits of the tracked object. The type traits class provides information about the customized service object, see TrackedTypeTraitsBase. |
Definition at line 231 of file usServiceTracker.h.
typedef ServiceReference<S> us::ServiceTracker< S, TTT >::ServiceReferenceType |
Definition at line 240 of file usServiceTracker.h.
typedef S us::ServiceTracker< S, TTT >::ServiceType |
The type of the service being tracked.
Definition at line 236 of file usServiceTracker.h.
typedef TTT::TrackedType us::ServiceTracker< S, TTT >::T |
The type of the tracked object.
Definition at line 238 of file usServiceTracker.h.
typedef std::map<ServiceReference<S>,T> us::ServiceTracker< S, TTT >::TrackingMap |
Definition at line 242 of file usServiceTracker.h.
|
override |
us::ServiceTracker< S, TTT >::ServiceTracker | ( | ModuleContext * | context, |
const ServiceReferenceType & | reference, | ||
ServiceTrackerCustomizer< S, T > * | customizer = nullptr |
||
) |
Create a ServiceTracker
on the specified ServiceReference
.
The service referenced by the specified ServiceReference
will be tracked by this ServiceTracker
.
context | The ModuleContext against which the tracking is done. |
reference | The ServiceReference for the service to be tracked. |
customizer | The customizer object to call when services are added, modified, or removed in this ServiceTracker . If customizer is null , then this ServiceTracker will be used as the ServiceTrackerCustomizer and this ServiceTracker will call the ServiceTrackerCustomizer methods on itself. |
us::ServiceTracker< S, TTT >::ServiceTracker | ( | ModuleContext * | context, |
const std::string & | clazz, | ||
ServiceTrackerCustomizer< S, T > * | customizer = 0 |
||
) |
Create a ServiceTracker
on the specified class name.
Services registered under the specified class name will be tracked by this ServiceTracker
.
context | The ModuleContext against which the tracking is done. |
clazz | The class name of the services to be tracked. |
customizer | The customizer object to call when services are added, modified, or removed in this ServiceTracker . If customizer is null , then this ServiceTracker will be used as the ServiceTrackerCustomizer and this ServiceTracker will call the ServiceTrackerCustomizer methods on itself. |
us::ServiceTracker< S, TTT >::ServiceTracker | ( | ModuleContext * | context, |
const LDAPFilter & | filter, | ||
ServiceTrackerCustomizer< S, T > * | customizer = nullptr |
||
) |
Create a ServiceTracker
on the specified LDAPFilter
object.
Services which match the specified LDAPFilter
object will be tracked by this ServiceTracker
.
context | The ModuleContext against which the tracking is done. |
filter | The LDAPFilter to select the services to be tracked. |
customizer | The customizer object to call when services are added, modified, or removed in this ServiceTracker . If customizer is null, then this ServiceTracker will be used as the ServiceTrackerCustomizer and this ServiceTracker will call the ServiceTrackerCustomizer methods on itself. |
us::ServiceTracker< S, TTT >::ServiceTracker | ( | ModuleContext * | context, |
ServiceTrackerCustomizer< S, T > * | customizer = nullptr |
||
) |
Create a ServiceTracker
on the class template argument S.
Services registered under the interface name of the class template argument S will be tracked by this ServiceTracker
.
context | The ModuleContext against which the tracking is done. |
customizer | The customizer object to call when services are added, modified, or removed in this ServiceTracker . If customizer is null, then this ServiceTracker will be used as the ServiceTrackerCustomizer and this ServiceTracker will call the ServiceTrackerCustomizer methods on itself. |
|
overrideprotected |
Default implementation of the ServiceTrackerCustomizer::AddingService
method.
This method is only called when this ServiceTracker
has been constructed with a null
ServiceTrackerCustomizer argument.
This implementation returns the result of calling GetService
on the ModuleContext
with which this ServiceTracker
was created passing the specified ServiceReference
.
This method can be overridden in a subclass to customize the service object to be tracked for the service being added. In that case, take care not to rely on the default implementation of removedService to unget the service.
reference | The reference to the service being added to this ServiceTracker . |
ServiceTracker
.
|
virtual |
Close this ServiceTracker
.
This method should be called when this ServiceTracker
should end the tracking of services.
This implementation calls GetServiceReferences() to get the list of tracked services to remove.
|
virtual |
Returns a service object for one of the services being tracked by this ServiceTracker
.
If any services are being tracked, this implementation returns the result of calling GetService(GetServiceReference())
.
null
if no services are being tracked.
|
virtual |
Returns the service object for the specified ServiceReference
if the specified referenced service is being tracked by this ServiceTracker
.
reference | The reference to the desired service. |
null
if the service referenced by the specified ServiceReference
is not being tracked.
|
virtual |
Returns a ServiceReference
for one of the services being tracked by this ServiceTracker
.
If multiple services are being tracked, the service with the highest ranking (as specified in its service.ranking
property) is returned. If there is a tie in ranking, the service with the lowest service ID (as specified in its service.id
property); that is, the service that was registered first is returned. This is the same algorithm used by ModuleContext::GetServiceReference()
.
This implementation calls GetServiceReferences() to get the list of references for the tracked services.
ServiceReference
for a tracked service. ServiceException | if no services are being tracked. |
|
virtual |
Return a list of ServiceReference
s for all services being tracked by this ServiceTracker
.
ServiceReference
s.
|
virtual |
Return a list of service objects for all services being tracked by this ServiceTracker
.
This implementation calls GetServiceReferences() to get the list of references for the tracked services and then calls GetService(const ServiceReference&) for each reference to get the tracked service object.
|
virtual |
Return a sorted map of the ServiceReference
s and service objects for all services being tracked by this ServiceTracker
. The map is sorted in natural order of ServiceReference
. That is, the last entry is the service with the highest ranking and the lowest service id.
tracked | A TrackingMap with the ServiceReference s and service objects for all services being tracked by this ServiceTracker . If no services are being tracked, then the returned map is empty. |
|
virtual |
Returns the tracking count for this ServiceTracker
.
The tracking count is initialized to 0 when this ServiceTracker
is opened. Every time a service is added, modified or removed from this ServiceTracker
, the tracking count is incremented.
The tracking count can be used to determine if this ServiceTracker
has added, modified or removed a service by comparing a tracking count value previously collected with the current tracking count value. If the value has not changed, then no service has been added, modified or removed from this ServiceTracker
since the previous tracking count was collected.
ServiceTracker
or -1 if this ServiceTracker
is not open.
|
virtual |
Return if this ServiceTracker
is empty.
true
if this ServiceTracker
is not tracking any services.
|
overrideprotected |
Default implementation of the ServiceTrackerCustomizer::ModifiedService
method.
This method is only called when this ServiceTracker
has been constructed with a null
ServiceTrackerCustomizer argument.
This implementation does nothing.
reference | The reference to modified service. |
service | The service object for the modified service. |
|
virtual |
Open this ServiceTracker
and begin tracking services.
Services which match the search criteria specified when this ServiceTracker
was created are now tracked by this ServiceTracker
.
std::logic_error | If the ModuleContext with which this ServiceTracker was created is no longer valid. |
|
virtual |
Remove a service from this ServiceTracker
.
The specified service will be removed from this ServiceTracker
. If the specified service was being tracked then the ServiceTrackerCustomizer::RemovedService
method will be called for that service.
reference | The reference to the service to be removed. |
|
overrideprotected |
Default implementation of the ServiceTrackerCustomizer::RemovedService
method.
This method is only called when this ServiceTracker
has been constructed with a null
ServiceTrackerCustomizer argument.
This implementation calls UngetService
, on the ModuleContext
with which this ServiceTracker
was created, passing the specified ServiceReference
.
This method can be overridden in a subclass. If the default implementation of AddingService method was used, this method must unget the service.
reference | The reference to removed service. |
service | The service object for the removed service. |
|
virtual |
Return the number of services being tracked by this ServiceTracker
.
|
virtual |
Wait for at least one service to be tracked by this ServiceTracker
. This method will also return when this ServiceTracker
is closed.
It is strongly recommended that WaitForService
is not used during the calling of the ModuleActivator
methods. ModuleActivator
methods are expected to complete in a short period of time.
This implementation calls GetService() to determine if a service is being tracked.