ctkEAMetaTypeProvider.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkEAMetaTypeProvider_p.h"
  16. #include "ctkEAConfiguration_p.h"
  17. #include <limits>
  18. class ctkEAMetaTypeProvider::ObjectClassDefinitionImpl : public ctkObjectClassDefinition
  19. {
  20. private:
  21. QList<ctkAttributeDefinitionPtr> attrs;
  22. public:
  23. ObjectClassDefinitionImpl(const QList<ctkAttributeDefinitionPtr>& attrs)
  24. : attrs(attrs)
  25. {
  26. }
  27. QString getName() const
  28. {
  29. return "CommonTK Event Admin Implementation";
  30. }
  31. QByteArray getIcon(int size) const
  32. {
  33. Q_UNUSED(size)
  34. return QByteArray();
  35. }
  36. QString getID() const
  37. {
  38. return ctkEAConfiguration::PID;
  39. }
  40. QString getDescription() const
  41. {
  42. return "Configuration for the CommonTK Event Admin Implementation."
  43. " This configuration overwrites configuration defined in framework properties of the same names.";
  44. }
  45. QList<ctkAttributeDefinitionPtr> getAttributeDefinitions(Filter filter)
  46. {
  47. return (filter == OPTIONAL) ? QList<ctkAttributeDefinitionPtr>() : attrs;
  48. }
  49. };
  50. class ctkEAMetaTypeProvider::AttributeDefinitionImpl : public ctkAttributeDefinition
  51. {
  52. private:
  53. const QString id;
  54. const QString name;
  55. const QString description;
  56. const int type;
  57. const QStringList defaultValues;
  58. const int cardinality;
  59. const QStringList optionLabels;
  60. const QStringList optionValues;
  61. public:
  62. AttributeDefinitionImpl(const QString& id, const QString& name, const QString& description, int type,
  63. const QStringList& defaultValues, int cardinality = 0,
  64. const QStringList& optionLabels = QStringList(),
  65. const QStringList& optionValues = QStringList())
  66. : id(id), name(name), description(description), type(type),
  67. defaultValues(defaultValues), cardinality(cardinality),
  68. optionLabels(optionLabels), optionValues(optionValues)
  69. {
  70. }
  71. int getCardinality() const
  72. {
  73. return cardinality;
  74. }
  75. QStringList getDefaultValue() const
  76. {
  77. return defaultValues;
  78. }
  79. QString getDescription() const
  80. {
  81. return description;
  82. }
  83. QString getID() const
  84. {
  85. return id;
  86. }
  87. QString getName() const
  88. {
  89. return name;
  90. }
  91. QStringList getOptionLabels() const
  92. {
  93. return optionLabels;
  94. }
  95. QStringList getOptionValues() const
  96. {
  97. return optionValues;
  98. }
  99. int getType() const
  100. {
  101. return type;
  102. }
  103. QString validate(const QString& str) const
  104. {
  105. Q_UNUSED(str)
  106. return QString();
  107. }
  108. };
  109. ctkEAMetaTypeProvider::ctkEAMetaTypeProvider(ctkManagedService* delegatee, int cacheSize,
  110. int threadPoolSize, int timeout, bool requireTopic,
  111. const QStringList& ignoreTimeout)
  112. : m_cacheSize(cacheSize), m_threadPoolSize(threadPoolSize), m_timeout(timeout),
  113. m_requireTopic(requireTopic), m_ignoreTimeout(ignoreTimeout), m_delegatee(delegatee)
  114. {
  115. }
  116. void ctkEAMetaTypeProvider::updated(const ctkDictionary& properties)
  117. {
  118. m_delegatee->updated(properties);
  119. }
  120. QList<QLocale> ctkEAMetaTypeProvider::getLocales() const
  121. {
  122. return QList<QLocale>();
  123. }
  124. ctkObjectClassDefinitionPtr ctkEAMetaTypeProvider::getObjectClassDefinition(const QString& id, const QLocale& locale)
  125. {
  126. Q_UNUSED(locale)
  127. if (ctkEAConfiguration::PID != id)
  128. {
  129. return ctkObjectClassDefinitionPtr();
  130. }
  131. if (!ocd)
  132. {
  133. QList<ctkAttributeDefinitionPtr> adList;
  134. adList.push_back(ctkAttributeDefinitionPtr(
  135. new AttributeDefinitionImpl(ctkEAConfiguration::PROP_CACHE_SIZE, "Cache Size",
  136. "The size of various internal caches. The default value is 30. Increase in case "
  137. "of a large number (more then 100) of services. A value less then 10 triggers the "
  138. "default value.", QVariant::Int, QStringList(QString::number(m_cacheSize)))));
  139. adList.push_back(ctkAttributeDefinitionPtr(
  140. new AttributeDefinitionImpl(ctkEAConfiguration::PROP_THREAD_POOL_SIZE, "Thread Pool Size",
  141. "The size of the thread pool. The default value is 10. Increase in case of a large amount "
  142. "of synchronous events where the event handler services in turn send new synchronous events in "
  143. "the event dispatching thread or a lot of timeouts are to be expected. A value of "
  144. "less then 2 triggers the default value. A value of 2 effectively disables thread pooling.",
  145. QVariant::Int, QStringList(QString::number(m_threadPoolSize)))));
  146. adList.push_back(ctkAttributeDefinitionPtr(
  147. new AttributeDefinitionImpl(ctkEAConfiguration::PROP_TIMEOUT, "Timeout",
  148. "The black-listing timeout in milliseconds. The default value is 5000. Increase or decrease "
  149. "at own discretion. A value of less then 100 turns timeouts off. Any other value is the time "
  150. "in milliseconds granted to each event handler before it gets blacklisted",
  151. QVariant::Int, QStringList(QString::number(m_timeout)))));
  152. adList.push_back(ctkAttributeDefinitionPtr(
  153. new AttributeDefinitionImpl(ctkEAConfiguration::PROP_REQUIRE_TOPIC, "Require Topic",
  154. "Are event handlers required to be registered with a topic? "
  155. "This is enabled by default. The specification says that event handlers "
  156. "must register with a list of topics they are interested in. Disabling this setting "
  157. "will enable that handlers without a topic are receiving all events "
  158. "(i.e., they are treated the same as with a topic=*).",
  159. QVariant::Bool, m_requireTopic ? QStringList("true") : QStringList("false"))));
  160. adList.push_back(ctkAttributeDefinitionPtr(
  161. new AttributeDefinitionImpl(ctkEAConfiguration::PROP_IGNORE_TIMEOUT, "Ignore Timeouts",
  162. "Configure event handlers to be called without a timeout. If a timeout is configured by default "
  163. "all event handlers are called using the timeout. For performance optimization it is possible to "
  164. "configure event handlers where the timeout handling is not used - this reduces the thread usage "
  165. "from the thread pools as the timout handling requires an additional thread to call the event "
  166. "handler. However, the application should work without this configuration property. It is a "
  167. "pure optimization! The value is a list of strings (separated by comma) which is assumed to define "
  168. "exact class names.",
  169. QVariant::String, m_ignoreTimeout, 0,
  170. QStringList(QString::number(std::numeric_limits<int>::max())))));
  171. ocd = ctkObjectClassDefinitionPtr(new ObjectClassDefinitionImpl(adList));
  172. }
  173. return ocd;
  174. }