ctkServiceEvent.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 "ctkServiceEvent.h"
  16. #include "ctkServiceReference.h"
  17. #include "ctkPluginConstants.h"
  18. #include <QStringList>
  19. //----------------------------------------------------------------------------
  20. class ctkServiceEventData : public QSharedData
  21. {
  22. public:
  23. ctkServiceEventData(ctkServiceEvent::Type type, const ctkServiceReference& reference)
  24. : type(type), reference(reference)
  25. {
  26. }
  27. ctkServiceEventData(const ctkServiceEventData& other)
  28. : QSharedData(other), type(other.type), reference(other.reference)
  29. {
  30. }
  31. const ctkServiceEvent::Type type;
  32. const ctkServiceReference reference;
  33. };
  34. //----------------------------------------------------------------------------
  35. ctkServiceEvent::ctkServiceEvent()
  36. : d(0)
  37. {
  38. }
  39. //----------------------------------------------------------------------------
  40. ctkServiceEvent::~ctkServiceEvent()
  41. {
  42. }
  43. //----------------------------------------------------------------------------
  44. bool ctkServiceEvent::isNull() const
  45. {
  46. return !d;
  47. }
  48. //----------------------------------------------------------------------------
  49. ctkServiceEvent::ctkServiceEvent(Type type, const ctkServiceReference& reference)
  50. : d(new ctkServiceEventData(type, reference))
  51. {
  52. }
  53. //----------------------------------------------------------------------------
  54. ctkServiceEvent::ctkServiceEvent(const ctkServiceEvent& other)
  55. : d(other.d)
  56. {
  57. }
  58. //----------------------------------------------------------------------------
  59. ctkServiceEvent& ctkServiceEvent::operator=(const ctkServiceEvent& other)
  60. {
  61. d = other.d;
  62. return *this;
  63. }
  64. //----------------------------------------------------------------------------
  65. ctkServiceReference ctkServiceEvent::getServiceReference() const
  66. {
  67. return d->reference;
  68. }
  69. //----------------------------------------------------------------------------
  70. ctkServiceEvent::Type ctkServiceEvent::getType() const
  71. {
  72. return d->type;
  73. }
  74. //----------------------------------------------------------------------------
  75. QDebug operator<<(QDebug dbg, ctkServiceEvent::Type type)
  76. {
  77. switch(type)
  78. {
  79. case ctkServiceEvent::MODIFIED: return dbg << "MODIFIED";
  80. case ctkServiceEvent::MODIFIED_ENDMATCH: return dbg << "MODIFIED_ENDMATCH";
  81. case ctkServiceEvent::REGISTERED: return dbg << "REGISTERED";
  82. case ctkServiceEvent::UNREGISTERING: return dbg << "UNREGISTERING";
  83. default: return dbg << "unknown service event type (" << static_cast<int>(type) << ")";
  84. }
  85. }
  86. //----------------------------------------------------------------------------
  87. QDebug operator<<(QDebug dbg, const ctkServiceEvent& event)
  88. {
  89. if (event.isNull()) return dbg << "NONE";
  90. ctkServiceReference sr = event.getServiceReference();
  91. // Some events will not have a service reference
  92. qlonglong sid = sr.getProperty(ctkPluginConstants::SERVICE_ID).toLongLong();
  93. QStringList classes = sr.getProperty(ctkPluginConstants::OBJECTCLASS).toStringList();
  94. dbg.nospace() << event.getType() << " " << sid << " objectClass=" << classes;
  95. return dbg.maybeSpace();
  96. }