Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
usTrackedService.tpp
Go to the documentation of this file.
1 /*=============================================================================
2 
3  Library: CppMicroServices
4 
5  Copyright (c) German Cancer Research Center,
6  Division of Medical and Biological Informatics
7 
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 =============================================================================*/
21 
22 US_BEGIN_NAMESPACE
23 
24 template<class S, class TTT>
25 TrackedService<S,TTT>::TrackedService(ServiceTracker<S,TTT>* serviceTracker,
26  ServiceTrackerCustomizer<S,T>* customizer)
27  : serviceTracker(serviceTracker), customizer(customizer)
28 {
29 
30 }
31 
32 template<class S, class TTT>
33 void TrackedService<S,TTT>::ServiceChanged(const ServiceEvent event)
34 {
35  /*
36  * Check if we had a delayed call (which could happen when we
37  * close).
38  */
39  if (this->closed)
40  {
41  return;
42  }
43 
44  ServiceReference<S> reference = event.GetServiceReference(InterfaceType<S>());
45  US_DEBUG(serviceTracker->d->DEBUG_OUTPUT) << "TrackedService::ServiceChanged["
46  << event.GetType() << "]: " << reference;
47  if (!reference)
48  {
49  return;
50  }
51 
52  switch (event.GetType())
53  {
54  case ServiceEvent::REGISTERED :
55  case ServiceEvent::MODIFIED :
56  {
57  if (!serviceTracker->d->listenerFilter.empty())
58  { // service listener added with filter
59  this->Track(reference, event);
60  /*
61  * If the customizer throws an unchecked exception, it
62  * is safe to let it propagate
63  */
64  }
65  else
66  { // service listener added without filter
67  if (serviceTracker->d->filter.Match(reference))
68  {
69  this->Track(reference, event);
70  /*
71  * If the customizer throws an unchecked exception,
72  * it is safe to let it propagate
73  */
74  }
75  else
76  {
77  this->Untrack(reference, event);
78  /*
79  * If the customizer throws an unchecked exception,
80  * it is safe to let it propagate
81  */
82  }
83  }
84  break;
85  }
86  case ServiceEvent::MODIFIED_ENDMATCH :
87  case ServiceEvent::UNREGISTERING :
88  this->Untrack(reference, event);
89  /*
90  * If the customizer throws an unchecked exception, it is
91  * safe to let it propagate
92  */
93  break;
94  }
95 }
96 
97 template<class S, class TTT>
98 void TrackedService<S,TTT>::Modified()
99 {
100  Superclass::Modified(); /* increment the modification count */
101  serviceTracker->d->Modified();
102 }
103 
104 template<class S, class TTT>
105 typename TrackedService<S,TTT>::T
106 TrackedService<S,TTT>::CustomizerAdding(ServiceReference<S> item,
107  const ServiceEvent& /*related*/)
108 {
109  return customizer->AddingService(item);
110 }
111 
112 template<class S, class TTT>
113 void TrackedService<S,TTT>::CustomizerModified(ServiceReference<S> item,
114  const ServiceEvent& /*related*/,
115  T object)
116 {
117  customizer->ModifiedService(item, object);
118 }
119 
120 template<class S, class TTT>
121 void TrackedService<S,TTT>::CustomizerRemoved(ServiceReference<S> item,
122  const ServiceEvent& /*related*/,
123  T object)
124 {
125  customizer->RemovedService(item, object);
126 }
127 
128 US_END_NAMESPACE