CallProcessorBus.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/std/containers/vector.h>
  10. #include <AzCore/RTTI/RTTI.h>
  11. #include <AzCore/EBus/EBus.h>
  12. #include <SceneAPI/SceneCore/SceneCoreConfiguration.h>
  13. #include <SceneAPI/SceneCore/Events/ProcessingResult.h>
  14. namespace AZ
  15. {
  16. namespace SceneAPI
  17. {
  18. namespace Events
  19. {
  20. class ICallContext
  21. {
  22. public:
  23. AZ_RTTI(ICallContext, "{525ED64B-9425-4F88-8E6B-D02FF61429B7}");
  24. virtual ~ICallContext() = 0;
  25. };
  26. class SCENE_CORE_CLASS CallProcessor
  27. : public AZ::EBusTraits
  28. {
  29. public:
  30. enum ProcessingPriority : uint8_t
  31. {
  32. EarliestProcessing = 0,
  33. EarlyProcessing = 64,
  34. NormalProcessing = 128,
  35. LateProcessing = 192,
  36. LatestProcessing = 255
  37. };
  38. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::MultipleAndOrdered;
  39. using MutexType = AZStd::recursive_mutex;
  40. virtual ~CallProcessor() = 0;
  41. // Request to process the event for the given context.
  42. virtual ProcessingResult Process(ICallContext* context) = 0;
  43. // The order of the calling processors is undetermined, but sometimes a context needs to be
  44. // processed before another. In these situations the priority of a processor can be
  45. // reduced or increased to make sure it gets called before or after normal processing
  46. // has happened. Note that if two or more processors are raised to the same priority
  47. // there will still not be a guarantee which will gets to do work first.
  48. SCENE_CORE_API virtual uint8_t GetPriority() const;
  49. SCENE_CORE_API bool Compare(const CallProcessor* rhs) const;
  50. };
  51. using CallProcessorBus = AZ::EBus<CallProcessor>;
  52. // Utility function to call the CallProcessor EBus.
  53. SCENE_CORE_API ProcessingResult Process(ICallContext& context);
  54. // Utility function to all the CallProcessor EBus.
  55. // Usage:
  56. // Process<Context>(ContextArg1, ContextArg2, ContextArg3);
  57. template<typename Context, typename... Args>
  58. ProcessingResult Process(Args&&... args);
  59. inline ICallContext::~ICallContext()
  60. {
  61. }
  62. inline CallProcessor::~CallProcessor()
  63. {
  64. }
  65. } // namespace Events
  66. } // namespace SceneAPI
  67. } // namespace AZ
  68. #include <SceneAPI/SceneCore/Events/CallProcessorBus.inl>