ctkEAAsyncDeliverTasks_p.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 CTKEAASYNCDELIVERTASKS_P_H
  16. #define CTKEAASYNCDELIVERTASKS_P_H
  17. #include "ctkEADeliverTask_p.h"
  18. #include <dispatch/ctkEADefaultThreadPool_p.h>
  19. class ctkEARunnable;
  20. /**
  21. * This class does the actual work of the asynchronous event dispatch.
  22. */
  23. template<class SyncDeliverTasks, class HandlerTask>
  24. class ctkEAAsyncDeliverTasks : public ctkEADeliverTask<ctkEAAsyncDeliverTasks<SyncDeliverTasks,HandlerTask>, HandlerTask>
  25. {
  26. private:
  27. /** The thread pool to use to spin-off new threads. */
  28. ctkEADefaultThreadPool* pool;
  29. /**
  30. * The deliver task for actually delivering the events. This
  31. * is the sync deliver tasks as this has all the code for timeout
  32. * handling etc.
  33. */
  34. typedef ctkEADeliverTask<SyncDeliverTasks, HandlerTask> DeliverTask;
  35. DeliverTask* deliver_task;
  36. /** A map of running threads currently delivering async events. */
  37. QHash<QThread*, ctkEARunnable*> running_threads;
  38. QMutex running_threads_mutex;
  39. public:
  40. /**
  41. * The constructor of the class that will use the asynchronous.
  42. *
  43. * @param pool The thread pool used to spin-off new asynchronous event
  44. * dispatching threads in case of timeout or that the asynchronous event
  45. * dispatching thread is used to send a synchronous event
  46. * @param deliverTask The deliver tasks for dispatching the event.
  47. */
  48. ctkEAAsyncDeliverTasks(ctkEADefaultThreadPool* pool, DeliverTask* deliverTask);
  49. /**
  50. * This does not block an unrelated thread used to send a synchronous event.
  51. *
  52. * @param tasks The event handler dispatch tasks to execute
  53. *
  54. * @see ctkEADeliverTask#execute(const QList<HandlerTask>&)
  55. */
  56. void execute(const QList<HandlerTask>& tasks);
  57. private:
  58. class TaskExecuter;
  59. };
  60. #include "ctkEAAsyncDeliverTasks.tpp"
  61. #endif // CTKEAASYNCDELIVERTASKS_P_H