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

EventAdmin now provides MetaType information.

Sascha Zelzer 14 éve
szülő
commit
4f657ce9e5

+ 3 - 0
Plugins/org.commontk.eventadmin/CMakeLists.txt

@@ -5,6 +5,8 @@ SET(PLUGIN_export_directive "org_commontk_eventadmin_EXPORT")
 SET(PLUGIN_SRCS
   ctkEAConfiguration_p.h
   ctkEAConfiguration.cpp
+  ctkEAMetaTypeProvider_p.h
+  ctkEAMetaTypeProvider.cpp
   ctkEventAdminActivator.cpp
   ctkEventAdminActivator_p.h
   ctkEventAdminImpl_p.h
@@ -97,6 +99,7 @@ SET(PLUGIN_MOC_SRCS
   tasks/ctkEASyncThread_p.h
 
   ctkEAConfiguration_p.h
+  ctkEAMetaTypeProvider_p.h
   ctkEventAdminActivator_p.h
   ctkEventAdminService_p.h
 )

+ 34 - 33
Plugins/org.commontk.eventadmin/ctkEAConfiguration.cpp

@@ -23,6 +23,7 @@
 #include "ctkEAConfiguration_p.h"
 
 #include "ctkEventAdminService_p.h"
+#include "ctkEAMetaTypeProvider_p.h"
 #include "adapter/ctkEAFrameworkEventAdapter_p.h"
 #include "adapter/ctkEALogEventAdapter_p.h"
 #include "adapter/ctkEAPluginEventAdapter_p.h"
@@ -50,27 +51,30 @@ ctkEAConfiguration::ctkEAConfiguration(ctkPluginContext* pluginContext )
   configure(ctkDictionary());
   startOrUpdate();
 
-  // check for Configuration Admin configuration
-//  try
-//  {
-      //TODO MetaType Provider
-//      // add meta type provider if interfaces are available
-//      QObject* enhancedService = tryToCreateMetaTypeProvider(service);
-//      QStringList interfaceNames;
-//      if (enhancedService == 0)
-//      {
-//        interfaceNames.append(getIIDs<ctkManagedService>());
-//      }
-//      else
-//      {
-//        interfaceNames.append(getIIDs<ctkManagedService, ctkMetaTypeProvider>());
-//        service = enhancedService;
-//      }
-//  }
-//  catch (...)
-//  {
-//    // don't care
-//  }
+  try
+  {
+    QObject* service = this;
+
+    // add meta type provider
+    metaTypeService.reset(tryToCreateMetaTypeProvider(qobject_cast<ctkManagedService*>(service)));
+    QStringList interfaceNames;
+    if (metaTypeService.isNull())
+    {
+      interfaceNames.append(getIIDs<ctkManagedService>());
+    }
+    else
+    {
+      interfaceNames.append(getIIDs<ctkManagedService, ctkMetaTypeProvider>());
+      service = metaTypeService.data();
+    }
+    ctkDictionary props;
+    props.insert(ctkPluginConstants::SERVICE_PID, PID);
+    managedServiceReg = pluginContext->registerService(interfaceNames, service, props);
+  }
+  catch (...)
+  {
+    // don't care
+  }
 }
 
 void ctkEAConfiguration::updateFromConfigAdmin(const ctkDictionary& config)
@@ -286,18 +290,15 @@ void ctkEAConfiguration::adaptEvents(ctkEventAdmin* admin)
 
 QObject* ctkEAConfiguration::tryToCreateMetaTypeProvider(ctkManagedService* managedService)
 {
-  Q_UNUSED(managedService)
-  //TODO
-//  try
-//  {
-//    return new MetaTypeProviderImpl((ManagedService)managedService,
-//                                    m_cacheSize, m_threadPoolSize, m_timeout, m_requireTopic,
-//                                    m_ignoreTimeout);
-//  }
-//  catch (Throwable t)
-//  {
-//    // we simply ignore this
-//  }
+  try
+  {
+    return new ctkEAMetaTypeProvider(managedService, cacheSize, threadPoolSize,
+                                     timeout, requireTopic, ignoreTimeout);
+  }
+  catch (...)
+  {
+    // we simply ignore this
+  }
   return 0;
 }
 

+ 6 - 6
Plugins/org.commontk.eventadmin/ctkEAConfiguration_p.h

@@ -87,10 +87,8 @@ class ctkEAAbstractAdapter;
  * as the timout handling requires an additional thread to call the event handler.
  * However, the application should work without this configuration property. It is a
  * pure optimization!
- * The value is a list of string (separated by comma). If the string ends with a dot,
- * all handlers in exactly this package are ignored. If the string ends with a star,
- * all handlers in this package and all subpackages are ignored. If the string neither
- * ends with a dot nor with a start, this is assumed to define an exact class name.
+ * The value is a list of strings (separated by comma) which is assumed to define
+ * exact class names.
  *
  * These properties are read at startup and serve as a default configuration.
  * If a configuration admin is configured, the event admin can be configured
@@ -106,8 +104,6 @@ public:
   /** The PID for the event admin. */
   static const QString PID; // = "org.commontk.eventadmin.impl.EventAdmin"
 
-private:
-
   static const QString PROP_CACHE_SIZE; // = "org.commontk.eventadmin.CacheSize"
   static const QString PROP_THREAD_POOL_SIZE; // = "org.commontk.eventadmin.ThreadPoolSize"
   static const QString PROP_TIMEOUT; // = "org.commontk.eventadmin.Timeout"
@@ -115,6 +111,8 @@ private:
   static const QString PROP_IGNORE_TIMEOUT; // = "org.commontk.eventadmin.IgnoreTimeout"
   static const QString PROP_LOG_LEVEL; // = "org.commontk.eventadmin.LogLevel"
 
+private:
+
   QMutex mutex;
 
   /** The plugin context. */
@@ -142,6 +140,8 @@ private:
   // the wrapper).
   ctkEventAdminService* admin;
 
+  QScopedPointer<QObject> metaTypeService;
+
   // The registration of the security decorator factory (i.e., the service)
   ctkServiceRegistration registration;
 

+ 226 - 0
Plugins/org.commontk.eventadmin/ctkEAMetaTypeProvider.cpp

@@ -0,0 +1,226 @@
+/*=============================================================================
+
+  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 "ctkEAMetaTypeProvider_p.h"
+
+#include "ctkEAConfiguration_p.h"
+
+#include <limits>
+
+
+class ctkEAMetaTypeProvider::ObjectClassDefinitionImpl : public ctkObjectClassDefinition
+{
+
+private:
+
+  QList<ctkAttributeDefinitionPtr> attrs;
+
+public:
+
+  ObjectClassDefinitionImpl(const QList<ctkAttributeDefinitionPtr>& attrs)
+    : attrs(attrs)
+  {
+
+  }
+
+  QString getName() const
+  {
+    return "CommonTK Event Admin Implementation";
+  }
+
+  QByteArray getIcon(int size) const
+  {
+    Q_UNUSED(size)
+    return QByteArray();
+  }
+
+  QString getID() const
+  {
+    return ctkEAConfiguration::PID;
+  }
+
+  QString getDescription() const
+  {
+    return "Configuration for the CommonTK Event Admin Implementation."
+        " This configuration overwrites configuration defined in framework properties of the same names.";
+  }
+
+  QList<ctkAttributeDefinitionPtr> getAttributeDefinitions(Filter filter)
+  {
+    return (filter == OPTIONAL) ? QList<ctkAttributeDefinitionPtr>() : attrs;
+  }
+};
+
+class ctkEAMetaTypeProvider::AttributeDefinitionImpl : public ctkAttributeDefinition
+{
+
+private:
+
+  const QString id;
+  const QString name;
+  const QString description;
+  const int type;
+  const QStringList defaultValues;
+  const int cardinality;
+  const QStringList optionLabels;
+  const QStringList optionValues;
+
+
+public:
+
+  AttributeDefinitionImpl(const QString& id, const QString& name, const QString& description, int type,
+                          const  QStringList& defaultValues, int cardinality = 0,
+                          const QStringList& optionLabels = QStringList(),
+                          const QStringList& optionValues = QStringList())
+    : id(id), name(name), description(description), type(type),
+      defaultValues(defaultValues), cardinality(cardinality),
+      optionLabels(optionLabels), optionValues(optionValues)
+  {
+
+  }
+
+  int getCardinality() const
+  {
+    return cardinality;
+  }
+
+  QStringList getDefaultValue() const
+  {
+    return defaultValues;
+  }
+
+  QString getDescription() const
+  {
+    return description;
+  }
+
+  QString getID() const
+  {
+    return id;
+  }
+
+  QString getName() const
+  {
+    return name;
+  }
+
+  QStringList getOptionLabels() const
+  {
+    return optionLabels;
+  }
+
+  QStringList getOptionValues() const
+  {
+    return optionValues;
+  }
+
+  int getType() const
+  {
+    return type;
+  }
+
+  QString validate(const QString& str) const
+  {
+    Q_UNUSED(str)
+    return QString();
+  }
+};
+
+
+ctkEAMetaTypeProvider::ctkEAMetaTypeProvider(ctkManagedService* delegatee, int cacheSize,
+                                             int threadPoolSize, int timeout, bool requireTopic,
+                                             const QStringList& ignoreTimeout)
+  : m_cacheSize(cacheSize), m_threadPoolSize(threadPoolSize), m_timeout(timeout),
+    m_requireTopic(requireTopic), m_ignoreTimeout(ignoreTimeout), m_delegatee(delegatee)
+{
+}
+
+void ctkEAMetaTypeProvider::updated(const ctkDictionary& properties)
+{
+  m_delegatee->updated(properties);
+}
+
+QList<QLocale> ctkEAMetaTypeProvider::getLocales() const
+{
+  return QList<QLocale>();
+}
+
+ctkObjectClassDefinitionPtr ctkEAMetaTypeProvider::getObjectClassDefinition(const QString& id, const QLocale& locale)
+{
+  Q_UNUSED(locale)
+
+  if (ctkEAConfiguration::PID != id)
+  {
+    return ctkObjectClassDefinitionPtr();
+  }
+
+  if (!ocd)
+  {
+    QList<ctkAttributeDefinitionPtr> adList;
+
+    adList.push_back(ctkAttributeDefinitionPtr(
+                       new AttributeDefinitionImpl(ctkEAConfiguration::PROP_CACHE_SIZE, "Cache Size",
+                                                   "The size of various internal caches. The default value is 30. Increase in case "
+                                                   "of a large number (more then 100) of services. A value less then 10 triggers the "
+                                                   "default value.", QVariant::Int, QStringList(QString::number(m_cacheSize)))));
+
+    adList.push_back(ctkAttributeDefinitionPtr(
+                       new AttributeDefinitionImpl(ctkEAConfiguration::PROP_THREAD_POOL_SIZE, "Thread Pool Size",
+                                                   "The size of the thread pool. The default value is 10. Increase in case of a large amount "
+                                                   "of synchronous events where the event handler services in turn send new synchronous events in "
+                                                   "the event dispatching thread or a lot of timeouts are to be expected. A value of "
+                                                   "less then 2 triggers the default value. A value of 2 effectively disables thread pooling.",
+                                                   QVariant::Int, QStringList(QString::number(m_threadPoolSize)))));
+
+    adList.push_back(ctkAttributeDefinitionPtr(
+                       new AttributeDefinitionImpl(ctkEAConfiguration::PROP_TIMEOUT, "Timeout",
+                                                   "The black-listing timeout in milliseconds. The default value is 5000. Increase or decrease "
+                                                   "at own discretion. A value of less then 100 turns timeouts off. Any other value is the time "
+                                                   "in milliseconds granted to each event handler before it gets blacklisted",
+                                                   QVariant::Int, QStringList(QString::number(m_timeout)))));
+
+    adList.push_back(ctkAttributeDefinitionPtr(
+                       new AttributeDefinitionImpl(ctkEAConfiguration::PROP_REQUIRE_TOPIC, "Require Topic",
+                                                   "Are event handlers required to be registered with a topic? "
+                                                   "This is enabled by default. The specification says that event handlers "
+                                                   "must register with a list of topics they are interested in. Disabling this setting "
+                                                   "will enable that handlers without a topic are receiving all events "
+                                                   "(i.e., they are treated the same as with a topic=*).",
+                                                   QVariant::Bool, m_requireTopic ? QStringList("true") : QStringList("false"))));
+
+    adList.push_back(ctkAttributeDefinitionPtr(
+                       new AttributeDefinitionImpl(ctkEAConfiguration::PROP_IGNORE_TIMEOUT, "Ignore Timeouts",
+                                                   "Configure event handlers to be called without a timeout. If a timeout is configured by default "
+                                                   "all event handlers are called using the timeout. For performance optimization it is possible to "
+                                                   "configure event handlers where the timeout handling is not used - this reduces the thread usage "
+                                                   "from the thread pools as the timout handling requires an additional thread to call the event "
+                                                   "handler. However, the application should work without this configuration property. It is a "
+                                                   "pure optimization! The value is a list of strings (separated by comma) which is assumed to define "
+                                                   "exact class names.",
+                                                   QVariant::String, m_ignoreTimeout, 0,
+                                                   QStringList(QString::number(std::numeric_limits<int>::max())))));
+
+    ocd = ctkObjectClassDefinitionPtr(new ObjectClassDefinitionImpl(adList));
+  }
+
+  return ocd;
+}
+

+ 77 - 0
Plugins/org.commontk.eventadmin/ctkEAMetaTypeProvider_p.h

@@ -0,0 +1,77 @@
+/*=============================================================================
+
+  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 CTKEAMETATYPEPROVIDER_P_H
+#define CTKEAMETATYPEPROVIDER_P_H
+
+#include <QObject>
+
+#include <service/metatype/ctkMetaTypeProvider.h>
+#include <service/cm/ctkManagedService.h>
+
+/**
+ * The optional meta type provider for the event admin config.
+ */
+class ctkEAMetaTypeProvider : public QObject, public ctkMetaTypeProvider, public ctkManagedService
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkMetaTypeProvider ctkManagedService)
+
+private:
+
+  const int m_cacheSize;
+  const int m_threadPoolSize;
+  const int m_timeout;
+  const bool m_requireTopic;
+  const QStringList m_ignoreTimeout;
+
+  ctkManagedService* const m_delegatee;
+
+  ctkObjectClassDefinitionPtr ocd;
+
+  class ObjectClassDefinitionImpl;
+  class AttributeDefinitionImpl;
+
+public:
+
+  ctkEAMetaTypeProvider(ctkManagedService* delegatee, int cacheSize,
+                        int threadPoolSize, int timeout, bool requireTopic,
+                        const QStringList& ignoreTimeout);
+
+
+  /**
+   * @see ctkManagedService#updated(ctkDictionary)
+   */
+  void updated(const ctkDictionary& properties);
+
+  /**
+   * @see ctkMetaTypeProvider#getLocales()
+   */
+  QList<QLocale> getLocales() const;
+
+  /**
+   * @see ctkMetaTypeProvider#getObjectClassDefinition(QString, QString)
+   */
+  ctkObjectClassDefinitionPtr getObjectClassDefinition(const QString& id, const QLocale& locale);
+
+};
+
+#endif // CTKEAMETATYPEPROVIDER_P_H

+ 0 - 7
Plugins/org.commontk.eventadmin/ctkEventAdminActivator.cpp

@@ -49,11 +49,6 @@ void ctkEventAdminActivator::start(ctkPluginContext* context)
   if (config) delete config;
   // this creates the event admin and starts it
   config = new ctkEAConfiguration(context);
-
-  // register the ctkEAConfiguration object as a ctkManagedService
-  ctkDictionary props;
-  props.insert(ctkPluginConstants::SERVICE_PID, ctkEAConfiguration::PID);
-  managedServiceReg = context->registerService<ctkManagedService>(config, props);
 }
 
 void ctkEventAdminActivator::stop(ctkPluginContext* context)
@@ -62,8 +57,6 @@ void ctkEventAdminActivator::stop(ctkPluginContext* context)
 
   if (config)
   {
-    managedServiceReg.unregister();
-    managedServiceReg = 0;
     config->destroy();
   }
 

+ 0 - 1
Plugins/org.commontk.eventadmin/ctkEventAdminActivator_p.h

@@ -79,7 +79,6 @@ private:
   static ctkEALogTracker* logTracker;
 
   ctkEAConfiguration* config;
-  ctkServiceRegistration managedServiceReg;
 };