소스 검색

Added new API getTracked() and isEmpty().

This follows the OSGi Core R4.3 Draft specs.
Sascha Zelzer 14 년 전
부모
커밋
471dc9ab0a

+ 18 - 0
Libs/PluginFramework/ctkPluginAbstractTracked.tpp

@@ -235,6 +235,12 @@ int ctkPluginAbstractTracked<S,T,R>::size() const
 }
 
 template<class S, class T, class R>
+bool ctkPluginAbstractTracked<S,T,R>::isEmpty() const
+{
+  return tracked.isEmpty();
+}
+
+template<class S, class T, class R>
 T ctkPluginAbstractTracked<S,T,R>::getCustomizedObject(S item) const
 {
   return tracked.value(item);
@@ -259,6 +265,18 @@ int ctkPluginAbstractTracked<S,T,R>::getTrackingCount() const
 }
 
 template<class S, class T, class R>
+QMap<S,T> ctkPluginAbstractTracked<S,T,R>::copyEntries(QMap<S,T>& map) const
+{
+  typename QHash<S,T>::ConstIterator end = tracked.end();
+  for (typename QHash<S,T>::ConstIterator it = tracked.begin();
+       it != end; ++it)
+  {
+    map.insert(it.key(), it.value());
+  }
+  return map;
+}
+
+template<class S, class T, class R>
 bool ctkPluginAbstractTracked<S,T,R>::customizerAddingFinal(S item, const T& custom)
 {
   QMutexLocker lock(this);

+ 20 - 0
Libs/PluginFramework/ctkPluginAbstractTracked_p.h

@@ -115,6 +115,15 @@ public:
   int size() const;
 
   /**
+   * Returns if the tracker is empty.
+   *
+   * @return Whether the tracker is empty.
+   *
+   * @GuardedBy this
+   */
+  bool isEmpty() const;
+
+  /**
    * Return the customized object for the specified item
    *
    * @param item The item to lookup in the map
@@ -153,6 +162,17 @@ public:
   int getTrackingCount() const;
 
   /**
+   * Copy the tracked items and associated values into the specified map.
+   *
+   * @param map The map into which to copy the tracked items and associated
+   *        values. This map must not be a user provided map so that user code
+   *        is not executed while synchronized on this.
+   * @return The specified map.
+   * @GuardedBy this
+   */
+  QMap<S,T> copyEntries(QMap<S,T>& map) const;
+
+  /**
    * Call the specific customizer adding method. This method must not be
    * called while synchronized on this object.
    *

+ 19 - 0
Libs/PluginFramework/ctkPluginTracker.h

@@ -179,6 +179,25 @@ public:
    */
   virtual int getTrackingCount() const;
 
+  /**
+   * Return a <code>QMap</code> with the <code>ctkPlugin</code>s and customized
+   * objects for all plugins being tracked by this <code>ctkPluginTracker</code>.
+   *
+   * @return A <code>QMap</code> with the <code>ctkPlugin</code>s and customized
+   *         objects for all services being tracked by this
+   *         <code>ctkPluginTracker</code>. If no plugins are being tracked, then
+   *         the returned map is empty.
+   */
+  virtual QMap<QSharedPointer<ctkPlugin>, T> getTracked() const;
+
+  /**
+   * Return if this <code>ctkPluginTracker</code> is empty.
+   *
+   * @return <code>true</code> if this <code>ctkPluginTracker</code> is not tracking any
+   *         plugins.
+   */
+  virtual bool isEmpty() const;
+
 protected:
 
   /**

+ 30 - 0
Libs/PluginFramework/ctkPluginTracker.tpp

@@ -190,6 +190,36 @@ int ctkPluginTracker<T>::getTrackingCount() const
   }
 }
 
+template<class T>
+QMap<QSharedPointer<ctkPlugin>, T> ctkPluginTracker<T>::getTracked() const
+{
+  QMap<QSharedPointer<ctkPlugin>, T> map;
+  Q_D(const PluginTracker);
+  QSharedPointer<TrackedPlugin> t = d->tracked();
+  if (t.isNull())
+  { /* if PluginTracker is not open */
+    return map;
+  }
+  {
+    QMutexLocker lock(t.data());
+    return t->copyEntries(map);
+  }
+}
+
+template<class T>
+bool ctkPluginTracker<T>::isEmpty() const
+{
+  QSharedPointer<TrackedPlugin> t = d->tracked();
+  if (t.isNull())
+  { /* if PluginTracker is not open */
+    return true;
+  }
+  {
+    QMutexLocker lock(t.data());
+    return t->isEmpty();
+  }
+}
+
 template<>
 inline QSharedPointer<ctkPlugin> ctkPluginTracker<QSharedPointer<ctkPlugin> >::addingPlugin(QSharedPointer<ctkPlugin> plugin, const ctkPluginEvent& event)
 {

+ 22 - 0
Libs/PluginFramework/ctkServiceTracker.h

@@ -319,6 +319,28 @@ public:
    */
   virtual int getTrackingCount() const;
 
+  /**
+   * Return a sorted <code>QMap</code> of the <code>ctkServiceReference</code>s and
+   * service objects for all services being tracked by this
+   * <code>ctkServiceTracker</code>. The map is sorted in natural order
+   * of <code>ctkServiceReference</code>. That is, the last entry is the service
+   * with the highest ranking and the lowest service id.
+   *
+   * @return A <code>QMap</code> with the <code>ctkServiceReference</code>s
+   *         and service objects for all services being tracked by this
+   *         <code>ctkServiceTracker</code>. If no services are being tracked,
+   *         then the returned map is empty.
+   */
+  virtual QMap<ctkServiceReference, T> getTracked() const;
+
+  /**
+   * Return if this <code>ctkServiceTracker</code> is empty.
+   *
+   * @return <code>true</code> if this <code>ctkServiceTracker</code> is not tracking any
+   *         services.
+   */
+  virtual bool isEmpty() const;
+
 protected:
 
   /**

+ 31 - 0
Libs/PluginFramework/ctkServiceTracker.tpp

@@ -413,6 +413,37 @@ int ctkServiceTracker<S,T>::getTrackingCount() const
 }
 
 template<class S, class T>
+QMap<ctkServiceReference, T> ctkServiceTracker<S,T>::getTracked() const
+{
+  QMap<ctkServiceReference, T> map;
+  Q_D(const ServiceTracker);
+  QSharedPointer<TrackedService> t = d->tracked();
+  if (t.isNull())
+  { /* if ServiceTracker is not open */
+    return map;
+  }
+  {
+    QMutexLocker lockT(t.data());
+    return t->copyEntries(map);
+  }
+}
+
+template<class S, class T>
+bool ctkServiceTracker<S,T>::isEmpty() const
+{
+  Q_D(const ServiceTracker);
+  QSharedPointer<TrackedService> t = d->tracked();
+  if (t.isNull())
+  { /* if ServiceTracker is not open */
+    return true;
+  }
+  {
+    QMutexLocker lockT(t.data());
+    return t->isEmpty();
+  }
+}
+
+template<class S, class T>
 T ctkServiceTracker<S,T>::addingService(const ctkServiceReference& reference)
 {
   Q_D(ServiceTracker);