MCPcopy Create free account
hub / github.com/MITK/MITK / FilterServiceEventReceivers

Method FilterServiceEventReceivers

Modules/CppMicroServices/src/usServiceHooks.cpp:141–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141void ServiceHooks::FilterServiceEventReceivers(const ServiceEvent& evt,
142 ServiceListeners::ServiceListenerEntries& receivers)
143{
144 std::vector<ServiceRegistrationBase> eventListenerHooks;
145 coreCtx->services.Get_unlocked(us_service_interface_iid<ServiceEventListenerHook>(), eventListenerHooks);
146 if (!eventListenerHooks.empty())
147 {
148 std::sort(eventListenerHooks.begin(), eventListenerHooks.end());
149 std::map<ModuleContext*, std::vector<ServiceListenerHook::ListenerInfo> > listeners;
150 for (ServiceListeners::ServiceListenerEntries::iterator sleIter = receivers.begin(),
151 sleEnd = receivers.end(); sleIter != sleEnd; ++sleIter)
152 {
153 listeners[sleIter->GetModuleContext()].push_back(*sleIter);
154 }
155
156 std::map<ModuleContext*, ShrinkableVector<ServiceListenerHook::ListenerInfo> > shrinkableListeners;
157 for (std::map<ModuleContext*, std::vector<ServiceListenerHook::ListenerInfo> >::iterator iter = listeners.begin(),
158 iterEnd = listeners.end(); iter != iterEnd; ++iter)
159 {
160 shrinkableListeners.insert(std::make_pair(iter->first, ShrinkableVector<ServiceListenerHook::ListenerInfo>(iter->second)));
161 }
162
163 ShrinkableMap<ModuleContext*, ShrinkableVector<ServiceListenerHook::ListenerInfo> > filtered(shrinkableListeners);
164
165 for(std::vector<ServiceRegistrationBase>::reverse_iterator sriIter = eventListenerHooks.rbegin(),
166 sriEnd = eventListenerHooks.rend(); sriIter != sriEnd; ++sriIter)
167 {
168 ServiceReference<ServiceEventListenerHook> sr = sriIter->GetReference();
169 ServiceEventListenerHook* elh = reinterpret_cast<ServiceEventListenerHook*>(sr.d->GetService(GetModuleContext()->GetModule()));
170 if(elh != nullptr)
171 {
172 try
173 {
174 elh->Event(evt, filtered);
175 }
176 catch(const std::exception& e)
177 {
178 MITK_WARN << "Failed to call event hook #" << sr.GetProperty(ServiceConstants::SERVICE_ID()).ToString()
179 << ": " << e.what();
180 }
181 catch(...)
182 {
183 MITK_WARN << "Failed to call event hook #" << sr.GetProperty(ServiceConstants::SERVICE_ID()).ToString()
184 << ": unknown exception type";
185 }
186 }
187 }
188 receivers.clear();
189 for(std::map<ModuleContext*, std::vector<ServiceListenerHook::ListenerInfo> >::iterator iter = listeners.begin(),
190 iterEnd = listeners.end(); iter != iterEnd; ++iter)
191 {
192 receivers.insert(iter->second.begin(), iter->second.end());
193 }
194 }
195}
196
197void ServiceHooks::HandleServiceListenerReg(const ServiceListenerEntry& sle)
198{

Callers 1

Calls 14

GetModuleContextFunction · 0.85
Get_unlockedMethod · 0.80
whatMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
GetModuleContextMethod · 0.45
GetReferenceMethod · 0.45
GetServiceMethod · 0.45
GetModuleMethod · 0.45
EventMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected