ctkServiceEvent.cpp 2.9 KB

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