ctkPluginFrameworkDebugOptions_p.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 CTKPLUGINFRAMEWORKDEBUGOPTIONS_H
  16. #define CTKPLUGINFRAMEWORKDEBUGOPTIONS_H
  17. #include <service/debug/ctkDebugOptions.h>
  18. #include <service/debug/ctkDebugOptionsListener.h>
  19. #include <ctkServiceTracker.h>
  20. #include <ctkServiceTrackerCustomizer.h>
  21. /**
  22. * Used to get debug options settings.
  23. */
  24. class ctkPluginFrameworkDebugOptions : public QObject, public ctkDebugOptions,
  25. private ctkServiceTrackerCustomizer<ctkDebugOptionsListener*>
  26. {
  27. Q_OBJECT
  28. Q_INTERFACES(ctkDebugOptions)
  29. public:
  30. ctkPluginFrameworkDebugOptions();
  31. static ctkPluginFrameworkDebugOptions* getDefault();
  32. void start(ctkPluginContext* pc);
  33. void stop(ctkPluginContext* pc);
  34. bool getBooleanOption(const QString& option, bool defaultValue) const;
  35. QVariant getOption(const QString& option) const;
  36. QVariant getOption(const QString& option, const QVariant& defaultValue) const;
  37. int getIntegerOption(const QString& option, int defaultValue) const;
  38. QHash<QString, QVariant> getOptions() const;
  39. void setOption(const QString& option, const QVariant& value);
  40. void setOptions(const QHash<QString, QVariant>& ops);
  41. void removeOption(const QString& option);
  42. bool isDebugEnabled() const;
  43. void setDebugEnabled(bool enabled);
  44. private:
  45. static const QString CTK_DEBUG;
  46. /** mutex used to lock the options maps */
  47. mutable QMutex mutex;
  48. /** A boolean value indicating if debug was enabled */
  49. bool enabled;
  50. /** A current map of all the options with values set */
  51. QHash<QString, QVariant> options;
  52. /** A map of all the disabled options with values set at the time debug was disabled */
  53. QHash<QString, QVariant> disabledOptions;
  54. /** The singleton object of this class */
  55. //static Impl* singleton = nullptr;
  56. /** The default name of the .options file if loading when the -debug command-line argument is used */
  57. static const QString OPTIONS;
  58. ctkPluginContext* context;
  59. QScopedPointer<ctkServiceTracker<ctkDebugOptionsListener*> > listenerTracker;
  60. QString getSymbolicName(const QString& option) const;
  61. /**
  62. * Notifies the trace listener for the specified plug-in that its option-path has changed.
  63. * @param pluginSymbolicName The plug-in of the owning trace listener to notify.
  64. */
  65. void optionsChanged(const QString& bundleSymbolicName);
  66. ctkDebugOptionsListener* addingService(const ctkServiceReference& reference);
  67. void modifiedService(const ctkServiceReference& reference,
  68. ctkDebugOptionsListener* service);
  69. void removedService(const ctkServiceReference& reference,
  70. ctkDebugOptionsListener* service);
  71. };
  72. #endif // CTKPLUGINFRAMEWORKDEBUGOPTIONS_H