27 #include "internal/berrySimpleExtensionPointFilter.h"
36 struct ExtensionTracker::Impl
38 struct HandlerWrapper;
41 QHash<IExtension::Pointer, QSet<Object::Pointer> > extensionToStrongObjects;
42 QHash<IExtension::Pointer, QSet<Object::WeakPtr> > extensionToWeakObjects;
44 QHash<IExtensionChangeHandler*, HandlerWrapper*> handlerToWrapper;
47 IExtensionRegistry* registry;
52 , registry(theRegistry)
57 struct ExtensionTracker::Impl::HandlerWrapper :
public IRegistryEventListener
60 IExtensionChangeHandler*
const handler;
67 bool operator==(
const HandlerWrapper& target)
const
69 return handler == target.handler;
72 virtual void Added(
const QList<IExtension::Pointer>& extensions)
override
74 for (
int i = 0; i < extensions.size(); ++i)
76 q->ApplyAdd(handler, extensions[i]);
80 virtual void Removed(
const QList<IExtension::Pointer>& extensions)
override
82 QList<QList<Object::Pointer> > removedObjects;
84 QMutexLocker lock(&q->d->mutex);
85 for (
int i = 0; i < extensions.size(); ++i)
87 QSet<Object::Pointer> associatedObjects = q->d->extensionToStrongObjects.take(extensions[i]);
88 foreach(
const Object::WeakPtr& ptr, q->d->extensionToWeakObjects.take(extensions[i]))
92 associatedObjects.insert(ptr.Lock());
95 removedObjects.push_back(associatedObjects.toList());
98 for (
int i = 0; i < extensions.size(); ++i)
100 q->ApplyRemove(handler, extensions[i], removedObjects[i]);
104 virtual void Added(
const QList<IExtensionPoint::Pointer>& )
override
109 virtual void Removed(
const QList<IExtensionPoint::Pointer>& )
override
127 this->Init(theRegistry);
132 d.reset(
new Impl(
this, registry));
133 if (registry ==
nullptr)
136 BERRY_ERROR <<
"Extension tracker was unable to obtain BlueBerry extension registry.";
143 QMutexLocker lock(&d->mutex);
144 if (d->closed)
return;
145 auto iter = d->handlerToWrapper.insert(handler,
new Impl::HandlerWrapper(
this, handler));
146 d->registry->AddListener(iter.value(), filter);
157 QMutexLocker lock(&d->mutex);
158 if (d->closed)
return;
160 d->registry->RemoveListener(listener);
166 if (element.
IsNull() ||
object.IsNull())
return;
168 QMutexLocker lock(&d->mutex);
169 if (d->closed)
return;
173 d->extensionToStrongObjects[element].insert(
object);
183 QSet<Object::Pointer> objectSet;
185 QMutexLocker lock(&d->mutex);
186 if (d->closed)
return objectSet.toList();
188 auto iter = d->extensionToStrongObjects.find(element);
189 if (iter != d->extensionToStrongObjects.end())
191 objectSet.unite(iter.value());
193 auto iter2 = d->extensionToWeakObjects.find(element);
194 if (iter2 != d->extensionToWeakObjects.end())
201 return objectSet.toList();
206 QMutexLocker lock(&d->mutex);
207 if (d->closed)
return;
208 foreach(Impl::HandlerWrapper* wrapper, d->handlerToWrapper.values())
210 d->registry->RemoveListener(wrapper);
213 d->extensionToStrongObjects.clear();
214 d->extensionToWeakObjects.clear();
215 d->handlerToWrapper.clear();
222 QMutexLocker lock(&d->mutex);
223 if (d->closed)
return;
225 auto iter = d->extensionToStrongObjects.find(extension);
226 if (iter != d->extensionToStrongObjects.end())
228 iter.value().remove(
object);
230 auto iter2 = d->extensionToWeakObjects.find(extension);
231 if (iter2 != d->extensionToWeakObjects.end())
239 QSet<Object::Pointer> objectSet;
241 QMutexLocker lock(&d->mutex);
242 if (d->closed)
return objectSet.toList();
244 auto iter = d->extensionToStrongObjects.find(extension);
245 if (iter != d->extensionToStrongObjects.end())
247 objectSet.unite(iter.value());
248 d->extensionToStrongObjects.erase(iter);
250 auto iter2 = d->extensionToWeakObjects.find(extension);
251 if (iter2 != d->extensionToWeakObjects.end())
257 d->extensionToWeakObjects.erase(iter2);
260 return objectSet.toList();
274 return m_Xpt == target;
284 const QList<IExtensionPoint::Pointer> m_Xpts;
286 F(
const QList<IExtensionPoint::Pointer>& xps)
292 for (
int i = 0; i < m_Xpts.size(); i++)
294 if (m_Xpts[i] == target)
static MsgHandler handler
QList< SmartPointer< Object > > GetObjects(const SmartPointer< IExtension > &element) const override
Implements transparent reference counting.
virtual void ApplyRemove(IExtensionChangeHandler *handler, const SmartPointer< IExtension > &removedExtension, const QList< SmartPointer< Object > > &removedObjects)
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
static IExtensionPointFilter CreateExtensionPointFilter(const SmartPointer< IExtensionPoint > &xpt)
void RegisterHandler(IExtensionChangeHandler *handler, const IExtensionPointFilter &filter) override
virtual void Removed(const QList< SmartPointer< IExtension > > &extensions)=0
void UnregisterObject(const SmartPointer< IExtension > &extension, const SmartPointer< Object > &object) override
virtual void Added(const QList< SmartPointer< IExtension > > &extensions)=0
virtual QString GetNamespaceIdentifier() const =0
void UnregisterHandler(IExtensionChangeHandler *handler) override
static IExtensionPointFilter CreateNamespaceFilter(const QString &id)
berry::WeakPointer< Self > WeakPtr
virtual void RemoveExtension(const SmartPointer< IExtension > &extension, const QList< SmartPointer< Object > > &objects)=0
virtual void AddExtension(IExtensionTracker *tracker, const SmartPointer< IExtension > &extension)=0
SmartPointer< ObjectType > Lock() const
virtual void ApplyAdd(IExtensionChangeHandler *handler, const SmartPointer< IExtension > &extension)
void RegisterObject(const SmartPointer< IExtension > &element, const SmartPointer< Object > &object, ReferenceType referenceType) override