ctkEABlacklistingHandlerTasks_p.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 CTKEABLACKLISTINGHANDLERTASKS_P_H
  16. #define CTKEABLACKLISTINGHANDLERTASKS_P_H
  17. #include "ctkEAHandlerTasks_p.h"
  18. #include <ctkPluginContext.h>
  19. #include <ctkEventAdminActivator_p.h>
  20. #include <service/event/ctkEventConstants.h>
  21. #include <service/event/ctkEventHandler.h>
  22. #include "ctkEATopicHandlerFilters_p.h"
  23. #include "ctkEAFilters_p.h"
  24. #include "ctkEABlackList_p.h"
  25. /**
  26. * This class is an implementation of the ctkEAHandlerTasks interface that does provide
  27. * blacklisting of event handlers. Furthermore, handlers are determined from the
  28. * framework on any call to <tt>createHandlerTasks()</tt> hence, there is no
  29. * book-keeping of <tt>ctkEventHandler</tt> services while they come and go but a
  30. * query for each sent event. In order to do this, an ldap-filter is created that
  31. * will match applicable <tt>ctkEventHandler</tt> references. In order to ease some of
  32. * the overhead pains of this approach some light caching is going on.
  33. */
  34. template<class BlackList, class TopicHandlerFilters, class Filters>
  35. class ctkEABlacklistingHandlerTasks :
  36. public ctkEAHandlerTasks<
  37. ctkEABlacklistingHandlerTasks<BlackList, TopicHandlerFilters, Filters> >
  38. {
  39. private:
  40. typedef ctkEABlacklistingHandlerTasks<BlackList, TopicHandlerFilters, Filters> Self;
  41. // The blacklist that holds blacklisted event handler service references
  42. ctkEABlackList<BlackList>* const blackList;
  43. // The context of the plugin used to get the actual event handler services
  44. ctkPluginContext* const context;
  45. // Used to create the filters that can determine applicable event handlers for
  46. // a given event
  47. ctkEATopicHandlerFilters<TopicHandlerFilters>* topicHandlerFilters;
  48. // Used to create the filters that are used to determine whether an applicable
  49. // event handler is interested in a particular event
  50. ctkEAFilters<Filters>* filters;
  51. public:
  52. /**
  53. * The constructor of the factory.
  54. *
  55. * @param context The context of the plugin
  56. * @param blackList The set to use for keeping track of blacklisted references
  57. * @param topicHandlerFilters The factory for topic handler filters
  58. * @param filters The factory for <tt>ctkLDAPSearchFilter</tt> objects
  59. */
  60. ctkEABlacklistingHandlerTasks(ctkPluginContext* context,
  61. ctkEABlackList<BlackList>* blackList,
  62. ctkEATopicHandlerFilters<TopicHandlerFilters>* topicHandlerFilters,
  63. ctkEAFilters<Filters>* filters);
  64. ~ctkEABlacklistingHandlerTasks();
  65. /**
  66. * Create the handler tasks for the event. All matching event handlers are
  67. * determined and delivery tasks for them returned.
  68. *
  69. * @param event The event for which' handlers delivery tasks must be created
  70. *
  71. * @return A delivery task for each handler that matches the given event
  72. *
  73. * @see ctkHandlerTasks#createHandlerTasks(const ctkEvent&)
  74. */
  75. QList<ctkEAHandlerTask<Self> > createHandlerTasks(const ctkEvent& event);
  76. /**
  77. * Blacklist the given service reference. This is a private method and only
  78. * public due to its usage in a friend class.
  79. *
  80. * @param handlerRef The service reference to blacklist
  81. */
  82. void blackListRef(const ctkServiceReference& handlerRef);
  83. /**
  84. * Get the real ctkEventHandler service for the handlerRef from the context in case
  85. * the ref is not blacklisted and the service is not unregistered. The
  86. * NullEventHandler object is returned otherwise. This is a private method and
  87. * only public due to its usage in a friend class.
  88. *
  89. * @param handlerRef The service reference for which to get its service
  90. * @return The service of the reference or a null object if the service is
  91. * unregistered
  92. */
  93. ctkEventHandler* getEventHandler(const ctkServiceReference& handlerRef);
  94. /**
  95. * Unget the service reference for the given event handler unless it is the
  96. * NullEventHandler. This is a private method and only public due to
  97. * its usage in a friend class.
  98. *
  99. * @param handler The event handler service to unget
  100. * @param handlerRef The service reference to unget
  101. */
  102. void ungetEventHandler(ctkEventHandler* handler,
  103. const ctkServiceReference& handlerRef);
  104. private:
  105. /*
  106. * This is a null object that is supposed to do nothing. This is used once an
  107. * EventHandler is requested for a service reference that is either stale
  108. * (i.e., unregistered) or blacklisted
  109. */
  110. struct NullEventHandler : public ctkEventHandler
  111. {
  112. /**
  113. * This is a null object that is supposed to do nothing at this point.
  114. *
  115. * @param event an event that is not used
  116. */
  117. void handleEvent(const ctkEvent& /*event*/)
  118. {
  119. // This is a null object that is supposed to do nothing at this
  120. // point. This is used once a ctkEventHandler is requested for a
  121. // servicereference that is either stale (i.e., unregistered) or
  122. // blacklisted.
  123. }
  124. };
  125. NullEventHandler nullEventHandler;
  126. /*
  127. * This is a utility method that will throw a <tt>ctkInvalidArgumentException</tt>
  128. * in case that the given object is null. The message will be of the form name +
  129. * may not be null.
  130. */
  131. void checkNull(void* object, const QString& name);
  132. };
  133. #include "ctkEABlacklistingHandlerTasks.tpp"
  134. #endif // CTKEABLACKLISTINGHANDLERTASKS_P_H