ctkDebugOptions.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. #ifndef CTKDEBUGOPTIONS_H
  16. #define CTKDEBUGOPTIONS_H
  17. #include <ctkPluginFrameworkExport.h>
  18. #include <QString>
  19. #include <QHash>
  20. #include <QVariant>
  21. /**
  22. * Used to get debug options settings.
  23. */
  24. struct CTK_PLUGINFW_EXPORT ctkDebugOptions
  25. {
  26. virtual ~ctkDebugOptions() {}
  27. /**
  28. * The service property (named &quot;listener.symbolic.name&quot;) which specifies
  29. * the bundle symbolic name of a {@link DebugOptionsListener} service.
  30. */
  31. static const QString LISTENER_SYMBOLICNAME; // = "listener.symbolic.name";
  32. /**
  33. * Returns the identified option as a boolean value. The specified
  34. * defaultValue is returned if no such option is found or if debug is not enabled.
  35. *
  36. * <p>
  37. * Options are specified in the general form <i>&lt;Plugin-SymbolicName&gt;/&lt;option-path&gt;</i>.
  38. * For example, <code>org.commontk.configadmin/debug</code>
  39. * </p>
  40. *
  41. * @param option the name of the option to lookup
  42. * @param defaultValue the value to return if no such option is found
  43. * @return the value of the requested debug option or the
  44. * defaultValue if no such option is found.
  45. */
  46. virtual bool getBooleanOption(const QString& option, bool defaultValue) const = 0;
  47. /**
  48. * Returns the identified option. A null value
  49. * is returned if no such option is found or if debug is not enabled.
  50. *
  51. * <p>
  52. * Options are specified
  53. * in the general form <i>&lt;Plugin-SymbolicName&gt;/&lt;option-path&gt;</i>.
  54. * For example, <code>org.commontk.configadmin/debug</code>
  55. * </p>
  56. *
  57. * @param option the name of the option to lookup
  58. * @return the value of the requested debug option or <code>null</code>
  59. */
  60. virtual QVariant getOption(const QString& option) const = 0;
  61. /**
  62. * Returns the identified option. The specified defaultValue is
  63. * returned if no such option is found or if debug is not enabled.
  64. *
  65. * <p>
  66. * Options are specified
  67. * in the general form <i>&lt;Plugin-SymbolicName&gt;/&lt;option-path&gt;</i>.
  68. * For example, <code>org.commontk.configadmin/debug</code>
  69. * </p>
  70. *
  71. * @param option the name of the option to lookup
  72. * @param defaultValue the value to return if no such option is found
  73. * @return the value of the requested debug option or the
  74. * defaultValue if no such option is found.
  75. */
  76. virtual QVariant getOption(const QString& option, const QVariant& defaultValue) const = 0;
  77. /**
  78. * Returns the identified option as an int value. The specified
  79. * defaultValue is returned if no such option is found or if an
  80. * error occurs while converting the option value
  81. * to an integer or if debug is not enabled.
  82. *
  83. * <p>
  84. * Options are specified
  85. * in the general form <i>&lt;Plugin-SymbolicName&gt;/&lt;option-path&gt;</i>.
  86. * For example, <code>org.commontk.configadmin/debug</code>
  87. * </p>
  88. *
  89. * @param option the name of the option to lookup
  90. * @param defaultValue the value to return if no such option is found
  91. * @return the value of the requested debug option or the
  92. * defaultValue if no such option is found.
  93. */
  94. virtual int getIntegerOption(const QString& option, int defaultValue) const = 0;
  95. /**
  96. * Returns a snapshot of the current options. If no
  97. * options are set then an empty map is returned.
  98. * <p>
  99. * If debug is not enabled then the snapshot of the current disabled
  100. * values is returned. See setDebugEnabled(bool).
  101. * </p>
  102. * @return a snapshot of the current options.
  103. */
  104. virtual QHash<QString, QVariant> getOptions() const = 0;
  105. /**
  106. * Sets the identified option to the identified value. If debug is
  107. * not enabled then the specified option is not changed.
  108. * @param option the name of the option to set
  109. * @param value the value of the option to set
  110. */
  111. virtual void setOption(const QString& option, const QVariant& value) = 0;
  112. /**
  113. * Sets the current option key/value pairs to the specified options.
  114. * The specified map replaces all keys and values of the current debug options.
  115. * <p>
  116. * If debug is not enabled then the specified options are saved as
  117. * the disabled values and no notifications will be sent.
  118. * See setDebugEnabled(bool).
  119. * If debug is enabled then notifications will be sent to the
  120. * listeners which have options that have been changed, added or removed.
  121. * </p>
  122. *
  123. * @param options the new set of options
  124. */
  125. virtual void setOptions(const QHash<QString, QVariant>& ops) = 0;
  126. /**
  127. * Removes the identified option. If debug is not enabled then
  128. * the specified option is not removed.
  129. * @param option the name of the option to remove
  130. */
  131. virtual void removeOption(const QString& option) = 0;
  132. /**
  133. * Returns true if debugging/tracing is currently enabled.
  134. * @return true if debugging/tracing is currently enabled; Otherwise false is returned.
  135. */
  136. virtual bool isDebugEnabled() const = 0;
  137. /**
  138. * Enables or disables debugging/tracing.
  139. * <p>
  140. * When debug is disabled all debug options are unset.
  141. * When disabling debug the current debug option values are
  142. * stored in memory as disabled values. If debug is re-enabled the
  143. * disabled values will be set back and enabled. The disabled values
  144. * are only stored in memory and if the framework is restarted then
  145. * the disabled option values will be lost.
  146. * </p>
  147. * @param value If <code>true</code>, debug is enabled, otherwise
  148. * debug is disabled.
  149. */
  150. virtual void setDebugEnabled(bool enabled) = 0;
  151. };
  152. Q_DECLARE_INTERFACE(ctkDebugOptions, "org.commontk.service.debug.DebugOptions")
  153. #endif // CTKDEBUGOPTIONS_H