ctkConfigurationEvent.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 "ctkConfigurationEvent.h"
  16. #include <stdexcept>
  17. class ctkConfigurationEventData : public QSharedData
  18. {
  19. public:
  20. ctkConfigurationEventData(const ctkServiceReference& reference,
  21. ctkConfigurationEvent::Type type,
  22. const QString& factoryPid,
  23. const QString& pid)
  24. : type(type), factoryPid(factoryPid), pid(pid), reference(reference)
  25. {
  26. }
  27. ctkConfigurationEventData(const ctkConfigurationEventData& other)
  28. : QSharedData(other), type(other.type), factoryPid(other.factoryPid),
  29. pid(other.pid), reference(other.reference)
  30. {
  31. }
  32. /**
  33. * Type of this event.
  34. */
  35. const ctkConfigurationEvent::Type type;
  36. /**
  37. * The factory pid associated with this event.
  38. */
  39. const QString factoryPid;
  40. /**
  41. * The pid associated with this event.
  42. */
  43. const QString pid;
  44. /**
  45. * The ConfigurationAdmin service which created this event.
  46. */
  47. const ctkServiceReference reference;
  48. };
  49. ctkConfigurationEvent::ctkConfigurationEvent()
  50. : d(0)
  51. {
  52. }
  53. ctkConfigurationEvent::~ctkConfigurationEvent()
  54. {
  55. }
  56. bool ctkConfigurationEvent::isNull() const
  57. {
  58. return !d;
  59. }
  60. ctkConfigurationEvent::ctkConfigurationEvent(const ctkServiceReference& reference,
  61. Type type, const QString& factoryPid,
  62. const QString& pid)
  63. : d(new ctkConfigurationEventData(reference, type, factoryPid, pid))
  64. {
  65. if (pid.isNull())
  66. {
  67. throw std::logic_error("pid must not be null");
  68. }
  69. }
  70. ctkConfigurationEvent::ctkConfigurationEvent(const ctkConfigurationEvent& other)
  71. : d(other.d)
  72. {
  73. }
  74. ctkConfigurationEvent& ctkConfigurationEvent::operator=(const ctkConfigurationEvent& other)
  75. {
  76. d = other.d;
  77. return *this;
  78. }
  79. QString ctkConfigurationEvent::getFactoryPid() const
  80. {
  81. return d->factoryPid;
  82. }
  83. QString ctkConfigurationEvent::getPid() const
  84. {
  85. return d->pid;
  86. }
  87. int ctkConfigurationEvent::getType() const
  88. {
  89. return d->type;
  90. }
  91. ctkServiceReference ctkConfigurationEvent::getReference() const
  92. {
  93. return d->reference;
  94. }
  95. QDebug operator<<(QDebug dbg, ctkConfigurationEvent::Type type)
  96. {
  97. switch (type)
  98. {
  99. case ctkConfigurationEvent::CM_UPDATED: return dbg << "CM_UPDATED";
  100. case ctkConfigurationEvent::CM_DELETED: return dbg << "CM_DELETED";
  101. default: return dbg << "unknown configuration event type (" << static_cast<int>(type) << ")";
  102. }
  103. }
  104. QDebug operator<<(QDebug dbg, const ctkConfigurationEvent& event)
  105. {
  106. if (event.isNull()) return dbg << "NONE";
  107. dbg.nospace() << event.getType() << (event.getFactoryPid().isEmpty() ? " " : event.getFactoryPid() + ", ")
  108. << "pid=" << event.getPid();
  109. return dbg.maybeSpace();
  110. }