SystemEventDispatcher.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #ifndef CRYINCLUDE_CRYSYSTEM_SYSTEMEVENTDISPATCHER_H
  9. #define CRYINCLUDE_CRYSYSTEM_SYSTEMEVENTDISPATCHER_H
  10. #pragma once
  11. #include <ISystem.h>
  12. #include <CryListenerSet.h>
  13. #include <MultiThread_Containers.h>
  14. class CSystemEventDispatcher
  15. : public ISystemEventDispatcher
  16. {
  17. public:
  18. CSystemEventDispatcher();
  19. virtual ~CSystemEventDispatcher(){}
  20. // ISystemEventDispatcher
  21. virtual bool RegisterListener(ISystemEventListener* pListener);
  22. virtual bool RemoveListener(ISystemEventListener* pListener);
  23. virtual void OnSystemEvent(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam);
  24. virtual void Update();
  25. // ~ISystemEventDispatcher
  26. private:
  27. void OnSystemEventAnyThread(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam);
  28. typedef CListenerSet<ISystemEventListener*> TSystemEventListeners;
  29. TSystemEventListeners m_listeners;
  30. // for the events coming from other threads
  31. struct SEventParams
  32. {
  33. ESystemEvent event;
  34. UINT_PTR wparam;
  35. UINT_PTR lparam;
  36. };
  37. typedef CryMT::queue<SEventParams> TSystemEventQueue;
  38. TSystemEventQueue m_systemEventQueue;
  39. AZStd::recursive_mutex m_listenerRegistrationLock;
  40. };
  41. #endif // CRYINCLUDE_CRYSYSTEM_SYSTEMEVENTDISPATCHER_H