Forráskód Böngészése

Removed ServiceProperties typedef and added ctkDictionary class.

Sascha Zelzer 14 éve
szülő
commit
9c5da044fe
27 módosított fájl, 163 hozzáadás és 55 törlés
  1. 1 0
      Libs/PluginFramework/CMakeLists.txt
  2. 1 1
      Libs/PluginFramework/Testing/ConfigAdminTest/ctkConfigAdminTestActivator.cpp
  3. 1 1
      Libs/PluginFramework/Testing/FrameworkTest/ctkPluginFrameworkTestActivator.cpp
  4. 51 0
      Libs/PluginFramework/ctkDictionary.cpp
  5. 63 0
      Libs/PluginFramework/ctkDictionary.h
  6. 1 1
      Libs/PluginFramework/ctkLDAPExpr_p.h
  7. 1 1
      Libs/PluginFramework/ctkLDAPSearchFilter.h
  8. 1 1
      Libs/PluginFramework/ctkPluginConstants.h
  9. 2 2
      Libs/PluginFramework/ctkPluginContext.cpp
  10. 7 7
      Libs/PluginFramework/ctkPluginContext.h
  11. 0 4
      Libs/PluginFramework/ctkPluginFramework_global.h
  12. 5 5
      Libs/PluginFramework/ctkServiceReference.h
  13. 1 1
      Libs/PluginFramework/ctkServiceReferencePrivate.cpp
  14. 3 3
      Libs/PluginFramework/ctkServiceReferencePrivate.h
  15. 2 2
      Libs/PluginFramework/ctkServiceRegistration.cpp
  16. 3 3
      Libs/PluginFramework/ctkServiceRegistration.h
  17. 1 1
      Libs/PluginFramework/ctkServiceRegistrationPrivate.cpp
  18. 3 3
      Libs/PluginFramework/ctkServiceRegistrationPrivate.h
  19. 3 3
      Libs/PluginFramework/ctkServices.cpp
  20. 4 4
      Libs/PluginFramework/ctkServices_p.h
  21. 1 1
      Libs/PluginFramework/service/cm/ctkConfiguration.h
  22. 1 3
      Libs/PluginFramework/service/cm/ctkConfigurationPlugin.h
  23. 3 3
      Libs/PluginFramework/service/cm/ctkManagedService.h
  24. 1 2
      Libs/PluginFramework/service/cm/ctkManagedServiceFactory.h
  25. 1 1
      Plugins/org.commontk.configadmin/ctkCMPluginManager_p.h
  26. 1 1
      Plugins/org.commontk.plugingenerator.ui/ctkPluginGeneratorUiPlugin.cpp
  27. 1 1
      Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceRuntime.cpp

+ 1 - 0
Libs/PluginFramework/CMakeLists.txt

@@ -10,6 +10,7 @@ SET(KIT_export_directive "CTK_PLUGINFW_EXPORT")
 # Source files
 SET(KIT_SRCS
   ctkCaseInsensitiveString.cpp
+  ctkDictionary.cpp
   ctkLDAPExpr.cpp
   ctkLDAPExpr_p.h
   ctkLDAPSearchFilter.cpp

+ 1 - 1
Libs/PluginFramework/Testing/ConfigAdminTest/ctkConfigAdminTestActivator.cpp

@@ -59,7 +59,7 @@ void ctkConfigAdminTestActivator::start(ctkPluginContext* context)
     throw std::logic_error(msg.toStdString());
   }
 
-  ServiceProperties props;
+  ctkDictionary props;
 
   configAdminTestSuite = new ctkConfigurationAdminTestSuite(context, cmPluginId);
   props.clear();

+ 1 - 1
Libs/PluginFramework/Testing/FrameworkTest/ctkPluginFrameworkTestActivator.cpp

@@ -32,7 +32,7 @@
 
 void ctkPluginFrameworkTestActivator::start(ctkPluginContext* context)
 {
-  ServiceProperties props;
+  ctkDictionary props;
 
   frameworkTestSuite = new ctkPluginFrameworkTestSuite(context);
   props.clear();

+ 51 - 0
Libs/PluginFramework/ctkDictionary.cpp

@@ -0,0 +1,51 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#include "ctkDictionary.h"
+
+#include <stdexcept>
+
+ctkDictionary::ctkDictionary()
+{
+
+}
+
+ctkDictionary::ctkDictionary(const ctkDictionary& other)
+  : Super(other)
+{
+
+}
+
+ctkDictionary::ctkDictionary(const ctkProperties& properties)
+{
+  ctkProperties::ConstIterator end = properties.end();
+  for (ctkProperties::ConstIterator it = properties.begin(); it != end; ++it)
+  {
+    if (this->contains(it.key()))
+    {
+      QString msg("ctkProperties object contains case variants of the key: ");
+      msg += it.key();
+      throw std::invalid_argument(qPrintable(msg));
+    }
+    this->insert(it.key(), it.value());
+  }
+}

+ 63 - 0
Libs/PluginFramework/ctkDictionary.h

@@ -0,0 +1,63 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#ifndef CTKDICTIONARY_H
+#define CTKDICTIONARY_H
+
+#include <ctkPluginFrameworkExport.h>
+
+#include "ctkCaseInsensitiveString.h"
+#include "ctkPluginFramework_global.h"
+
+/**
+ * A QHash based dictionary class with case-insensitive keys. This class
+ * uses ctkCaseInsensitiveString as key type and QVariant as values. Due
+ * to the conversion capabilities of ctkCaseInsensitiveString, QString objects
+ * can be used transparantly to insert or retrieve key-value pairs.
+ *
+ * <p>
+ * Note that the case of the keys will be preserved.
+ */
+class CTK_PLUGINFW_EXPORT ctkDictionary : public QHash<ctkCaseInsensitiveString, QVariant>
+{
+
+public:
+
+  ctkDictionary();
+  ctkDictionary(const ctkDictionary& other);
+
+  /**
+   * Constructs a ctkDictionary object by using the entries of a
+   * ctkProperties object. The keys in <code>properties</code> must
+   * not contain case-variants of the same string.
+   *
+   * @param properties The ctkProperties object from which to copy the key-value pairs.
+   * @throws std::invalid_argument if <code>properties</code> contains case-variants of a key
+   */
+  ctkDictionary(const ctkProperties& properties);
+
+protected:
+
+  typedef QHash<ctkCaseInsensitiveString, QVariant> Super;
+};
+
+#endif // CTKDICTIONARY_H

+ 1 - 1
Libs/PluginFramework/ctkLDAPExpr_p.h

@@ -23,7 +23,7 @@ limitations under the License.
 #define CTKLDAPEXPR_P_H
 
 #include "ctkPluginConstants.h"
-#include "ctkPluginFramework_global.h"
+#include "ctkDictionary.h"
 
 #include <QString>
 #include <QHash>

+ 1 - 1
Libs/PluginFramework/ctkLDAPSearchFilter.h

@@ -25,7 +25,7 @@
 #include "ctkPluginFrameworkExport.h"
 
 #include "ctkServiceReference.h"
-#include "ctkPluginFramework_global.h"
+#include "ctkDictionary.h"
 
 #include <QSharedDataPointer>
 #include <QDebug>

+ 1 - 1
Libs/PluginFramework/ctkPluginConstants.h

@@ -335,7 +335,7 @@ struct CTK_PLUGINFW_EXPORT ctkPluginConstants {
    *
    * <p>
    * This property may be supplied in the
-   * <code>ServiceProperties</code> object passed to the
+   * <code>ctkDictionary</code> object passed to the
    * <code>ctkPluginContext::registerService</code> method. The value of this
    * property must be of type <code>int</code>.
    *

+ 2 - 2
Libs/PluginFramework/ctkPluginContext.cpp

@@ -109,14 +109,14 @@ QFileInfo ctkPluginContext::getDataFile(const QString& filename)
   return QFileInfo(dataRoot, filename);
 }
 
-ctkServiceRegistration ctkPluginContext::registerService(const QStringList& clazzes, QObject* service, const ServiceProperties& properties)
+ctkServiceRegistration ctkPluginContext::registerService(const QStringList& clazzes, QObject* service, const ctkDictionary& properties)
 {
   Q_D(ctkPluginContext);
   d->isPluginContextValid();
   return d->plugin->fwCtx->services->registerService(d->plugin, clazzes, service, properties);
 }
 
-ctkServiceRegistration ctkPluginContext::registerService(const char* clazz, QObject* service, const ServiceProperties& properties)
+ctkServiceRegistration ctkPluginContext::registerService(const char* clazz, QObject* service, const ctkDictionary& properties)
 {
   Q_D(ctkPluginContext);
   d->isPluginContextValid();

+ 7 - 7
Libs/PluginFramework/ctkPluginContext.h

@@ -168,13 +168,13 @@ public:
    * <code>std::invalid_argument</code> is thrown if <code>service</code>
    * is not an instance of all the specified class names.
    * <li>The Framework adds the following service properties to the service
-   * properties from the specified <code>ServiceProperties</code> (which may be
+   * properties from the specified <code>ctkDictionary</code> (which may be
    * omitted): <br/>
    * A property named {@link ctkPluginConstants#SERVICE_ID} identifying the
    * registration number of the service <br/>
    * A property named {@link ctkPluginConstants#OBJECTCLASS} containing all the
    * specified classes. <br/>
-   * Properties with these names in the specified <code>ServiceProperties</code> will
+   * Properties with these names in the specified <code>ctkDictionary</code> will
    * be ignored.
    * <li>The service is added to the Framework service registry and may now be
    * used by other plugins.
@@ -211,7 +211,7 @@ public:
    * @see ctkServiceRegistration
    * @see ctkServiceFactory
    */
-  ctkServiceRegistration registerService(const QStringList& clazzes, QObject* service, const ServiceProperties& properties = ServiceProperties());
+  ctkServiceRegistration registerService(const QStringList& clazzes, QObject* service, const ctkDictionary& properties = ctkDictionary());
 
   /**
    * Registers the specified service object with the specified properties
@@ -219,7 +219,7 @@ public:
    *
    * <p>
    * This method is otherwise identical to
-   * registerService(const QStringList&, QObject*, const ServiceProperties&) and is provided as
+   * registerService(const QStringList&, QObject*, const ctkDictionary&) and is provided as
    * a convenience when <code>service</code> will only be registered under a single
    * class name. Note that even in this case the value of the service's
    * ctkPluginConstants::OBJECTCLASS property will be a QStringList, rather
@@ -232,12 +232,12 @@ public:
    *         registering the service to update the service's properties or to
    *         unregister the service.
    * @throws std::logic_error If this ctkPluginContext is no longer valid.
-   * @see registerService(const QStringList&, QObject*, const ServiceProperties&)
+   * @see registerService(const QStringList&, QObject*, const ctkDictionary&)
    */
-  ctkServiceRegistration registerService(const char* clazz, QObject* service, const ServiceProperties& properties = ServiceProperties());
+  ctkServiceRegistration registerService(const char* clazz, QObject* service, const ctkDictionary& properties = ctkDictionary());
 
   template<class S>
-  ctkServiceRegistration registerService(QObject* service, const ServiceProperties& properties = ServiceProperties())
+  ctkServiceRegistration registerService(QObject* service, const ctkDictionary& properties = ctkDictionary())
   {
     const char* clazz = qobject_interface_iid<S*>();
     if (clazz == 0)

+ 0 - 4
Libs/PluginFramework/ctkPluginFramework_global.h

@@ -27,10 +27,6 @@
 #include <QStringList>
 #include <QVariant>
 
-#include "ctkCaseInsensitiveString.h"
-
-typedef QHash<ctkCaseInsensitiveString, QVariant> ServiceProperties;
-typedef QHash<ctkCaseInsensitiveString, QVariant> ctkDictionary;
 typedef QHash<QString, QVariant> ctkProperties;
 
 #if QT_VERSION < 0x040700

+ 5 - 5
Libs/PluginFramework/ctkServiceReference.h

@@ -96,7 +96,7 @@ public:
 
   /**
    * Returns the property value to which the specified property key is mapped
-   * in the properties <code>ServiceProperties</code> object of the service
+   * in the properties <code>ctkDictionary</code> object of the service
    * referenced by this <code>ctkServiceReference</code> object.
    *
    * <p>
@@ -114,7 +114,7 @@ public:
   QVariant getProperty(const QString& key) const;
 
   /**
-   * Returns a list of the keys in the <code>ServiceProperties</code>
+   * Returns a list of the keys in the <code>ctkDictionary</code>
    * object of the service referenced by this <code>ctkServiceReference</code>
    * object.
    *
@@ -126,8 +126,8 @@ public:
    * <p>
    * This method is not <i>case-preserving</i>; this means that every key in the
    * returned array is in lower case, which may not be the case for the corresponding key in the
-   * properties <code>ServiceProperties</code> that was passed to the
-   * {@link ctkPluginContext::registerService(const QStringList&, QObject*, const ServiceProperties&)} or
+   * properties <code>ctkDictionary</code> that was passed to the
+   * {@link ctkPluginContext::registerService(const QStringList&, QObject*, const ctkDictionary&)} or
    * {@link ctkServiceRegistration::setProperties} methods.
    *
    * @return A list of property keys.
@@ -146,7 +146,7 @@ public:
    * @return The plugin that registered the service referenced by this
    *         <code>ctkServiceReference</code> object; <code>0</code> if that
    *         service has already been unregistered.
-   * @see ctkPluginContext::registerService(const QStringList&, QObject* , const ServiceProperties&)
+   * @see ctkPluginContext::registerService(const QStringList&, QObject* , const ctkDictionary&)
    */
   QSharedPointer<ctkPlugin> getPlugin() const;
 

+ 1 - 1
Libs/PluginFramework/ctkServiceReferencePrivate.cpp

@@ -160,7 +160,7 @@ bool ctkServiceReferencePrivate::ungetService(QSharedPointer<ctkPlugin> plugin,
   return hadReferences;
 }
 
-ServiceProperties ctkServiceReferencePrivate::getProperties() const
+ctkDictionary ctkServiceReferencePrivate::getProperties() const
 {
   return registration->properties;
 }

+ 3 - 3
Libs/PluginFramework/ctkServiceReferencePrivate.h

@@ -26,7 +26,7 @@
 #include <QAtomicInt>
 #include <QSharedPointer>
 
-#include "ctkPluginFramework_global.h"
+#include "ctkDictionary.h"
 
 class QObject;
 
@@ -64,10 +64,10 @@ public:
   /**
    * Get all properties registered with this service.
    *
-   * @return A ServiceProperties object containing properties or being empty
+   * @return A ctkDictionary object containing properties or being empty
    *         if service has been removed.
    */
-  ServiceProperties getProperties() const;
+  ctkDictionary getProperties() const;
 
   /**
    * Reference count for implicitly shared private implementation.

+ 2 - 2
Libs/PluginFramework/ctkServiceRegistration.cpp

@@ -52,7 +52,7 @@ ctkServiceRegistration::ctkServiceRegistration(ctkServiceRegistrationPrivate* re
 }
 
 ctkServiceRegistration::ctkServiceRegistration(ctkPluginPrivate* plugin, QObject* service,
-                    const ServiceProperties& props)
+                    const ctkDictionary& props)
   : d_ptr(new ctkServiceRegistrationPrivate(plugin, service, props))
 {
 
@@ -92,7 +92,7 @@ ctkServiceReference ctkServiceRegistration::getReference() const
   return d->reference;
 }
 
-void ctkServiceRegistration::setProperties(const ServiceProperties& props)
+void ctkServiceRegistration::setProperties(const ctkDictionary& props)
 {
   Q_D(ctkServiceRegistration);
   if (!d) throw std::logic_error("ctkServiceRegistration object invalid");

+ 3 - 3
Libs/PluginFramework/ctkServiceRegistration.h

@@ -22,7 +22,7 @@
 #ifndef CTKSERVICEREGISTRATION_H
 #define CTKSERVICEREGISTRATION_H
 
-#include "ctkPluginFramework_global.h"
+#include "ctkDictionary.h"
 #include "ctkServiceReference.h"
 
 #include "ctkPluginFrameworkExport.h"
@@ -109,7 +109,7 @@ public:
    * @throws std::invalid_argument If <code>properties</code> contains
    *         case variants of the same key name.
    */
-  void setProperties(const ServiceProperties& properties);
+  void setProperties(const ctkDictionary& properties);
 
   /**
    * Unregisters a service. Remove a <code>ctkServiceRegistration</code> object
@@ -161,7 +161,7 @@ protected:
   ctkServiceRegistration(ctkServiceRegistrationPrivate* registrationPrivate);
 
   ctkServiceRegistration(ctkPluginPrivate* plugin, QObject* service,
-                         const ServiceProperties& props);
+                         const ctkDictionary& props);
 
   ctkServiceRegistrationPrivate* d_ptr;
 

+ 1 - 1
Libs/PluginFramework/ctkServiceRegistrationPrivate.cpp

@@ -24,7 +24,7 @@
 
 ctkServiceRegistrationPrivate::ctkServiceRegistrationPrivate(
   ctkPluginPrivate* plugin, QObject* service,
-  const ServiceProperties& props)
+  const ctkDictionary& props)
   : ref(1), service(service), plugin(plugin), reference(this),
     properties(props), available(true), unregistering(false),
     propsLock(QMutex::Recursive)

+ 3 - 3
Libs/PluginFramework/ctkServiceRegistrationPrivate.h

@@ -26,7 +26,7 @@
 #include <QHash>
 #include <QMutex>
 
-#include "ctkPluginFramework_global.h"
+#include "ctkDictionary.h"
 #include "ctkServiceReference.h"
 
 
@@ -65,7 +65,7 @@ public:
   /**
    * Service properties.
    */
-  ServiceProperties properties;
+  ctkDictionary properties;
 
   /**
    * Plugins dependent on this service. Integer is used as
@@ -99,7 +99,7 @@ public:
   QMutex propsLock;
 
   ctkServiceRegistrationPrivate(ctkPluginPrivate* plugin, QObject* service,
-                                const ServiceProperties& props);
+                                const ctkDictionary& props);
 
   virtual ~ctkServiceRegistrationPrivate();
 

+ 3 - 3
Libs/PluginFramework/ctkServices.cpp

@@ -43,12 +43,12 @@ struct ServiceRegistrationComparator
   }
 };
 
-ServiceProperties ctkServices::createServiceProperties(const ServiceProperties& in,
+ctkDictionary ctkServices::createServiceProperties(const ctkDictionary& in,
                                                        const QStringList& classes,
                                                        long sid)
 {
   static qlonglong nextServiceID = 1;
-  ServiceProperties props = in;
+  ctkDictionary props = in;
 
   if (!classes.isEmpty())
   {
@@ -81,7 +81,7 @@ void ctkServices::clear()
 ctkServiceRegistration ctkServices::registerService(ctkPluginPrivate* plugin,
                              const QStringList& classes,
                              QObject* service,
-                             const ServiceProperties& properties)
+                             const ctkDictionary& properties)
 {
   if (service == 0)
   {

+ 4 - 4
Libs/PluginFramework/ctkServices_p.h

@@ -43,15 +43,15 @@ public:
   mutable QMutex mutex;
 
   /**
-   * Creates a new ServiceProperties object containing <code>in</code>
+   * Creates a new ctkDictionary object containing <code>in</code>
    * with the keys converted to lower case.
    *
    * @param classes A list of class names which will be added to the
-   *        created ServiceProperties object under the key
+   *        created ctkDictionary object under the key
    *        PluginConstants::OBJECTCLASS.
    * @param sid A service id which will be used instead of a default one.
    */
-  static ServiceProperties createServiceProperties(const ServiceProperties& in,
+  static ctkDictionary createServiceProperties(const ctkDictionary& in,
                                  const QStringList& classes = QStringList(),
                                  long sid = -1);
 
@@ -96,7 +96,7 @@ public:
   ctkServiceRegistration registerService(ctkPluginPrivate* plugin,
                                const QStringList& classes,
                                QObject* service,
-                               const ServiceProperties& properties);
+                               const ctkDictionary& properties);
 
 
   /**

+ 1 - 1
Libs/PluginFramework/service/cm/ctkConfiguration.h

@@ -25,7 +25,7 @@
 
 #include <QSharedPointer>
 
-#include "ctkPluginFramework_global.h"
+#include "ctkDictionary.h"
 
 
 /**

+ 1 - 3
Libs/PluginFramework/service/cm/ctkConfigurationPlugin.h

@@ -23,10 +23,8 @@
 #ifndef CTKCONFIGURATIONPLUGIN_H
 #define CTKCONFIGURATIONPLUGIN_H
 
-#include <ctkPluginFrameworkExport.h>
-
 #include "ctkServiceReference.h"
-#include "ctkPluginFramework_global.h"
+#include "ctkDictionary.h"
 
 /**
  * A service interface for processing configuration dictionary before the

+ 3 - 3
Libs/PluginFramework/service/cm/ctkManagedService.h

@@ -24,7 +24,7 @@
 #define CTKMANAGEDSERVICE_H
 
 #include <QObject>
-#include <ctkPluginFramework_global.h>
+#include <ctkDictionary.h>
 
 /**
  * A service that can receive configuration data from a Configuration Admin
@@ -80,9 +80,9 @@
  *         this, getDefaults());
  *     }
  *
- *     ServiceProperties getDefaults()
+ *     ctkDictionary getDefaults()
  *     {
- *       ServiceProperties defaults;
+ *       ctkDictionary defaults;
  *       defaults.insert("port", id.getName());
  *       defaults.insert("product", "unknown");
  *       defaults.insert("baud", 9600);

+ 1 - 2
Libs/PluginFramework/service/cm/ctkManagedServiceFactory.h

@@ -23,8 +23,7 @@
 #ifndef CTKMANAGEDSERVICEFACTORY_H
 #define CTKMANAGEDSERVICEFACTORY_H
 
-#include <QString>
-#include <ctkPluginFramework_global.h>
+#include <ctkDictionary.h>
 
 /**
  * Manage multiple service instances.

+ 1 - 1
Plugins/org.commontk.configadmin/ctkCMPluginManager_p.h

@@ -24,7 +24,7 @@
 #define CTKCMPLUGINMANAGER_P_H
 
 #include <ctkServiceReference.h>
-#include <ctkPluginFramework_global.h>
+#include <ctkDictionary.h>
 
 class _PluginTracker;
 

+ 1 - 1
Plugins/org.commontk.plugingenerator.ui/ctkPluginGeneratorUiPlugin.cpp

@@ -33,7 +33,7 @@ void ctkPluginGeneratorUiPlugin::start(ctkPluginContext* context)
 {
   mainExtension = new ctkPluginGeneratorMainExtension();
 
-  ServiceProperties props;
+  ctkDictionary props;
   props.insert(ctkPluginConstants::SERVICE_RANKING, 0);
   context->registerService(QStringList("ctkPluginGeneratorAbstractUiExtension"),
                            mainExtension, props);

+ 1 - 1
Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceRuntime.cpp

@@ -137,7 +137,7 @@ void ctkQtMobilityServiceRuntime::processPlugin(QSharedPointer<ctkPlugin> plugin
       QServiceInterfaceDescriptor descr = it.next();
       CTK_DEBUG(ctkQtMobilityServiceActivator::getLogService()) << "Registering:" << descr.interfaceName();
       QStringList classes;
-      ServiceProperties props;
+      ctkDictionary props;
 
       QStringList customKeys = descr.customAttributes();
       QStringListIterator keyIt(customKeys);