AWSGameLiftClientLocalTicketTracker.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/parallel/binary_semaphore.h>
  10. #include <AzCore/std/parallel/mutex.h>
  11. #include <AzCore/std/parallel/thread.h>
  12. #include <Request/AWSGameLiftMatchmakingRequestBus.h>
  13. #include <aws/gamelift/model/MatchmakingTicket.h>
  14. namespace AWSGameLift
  15. {
  16. enum TicketTrackerStatus
  17. {
  18. Idle,
  19. Running
  20. };
  21. //! AWSGameLiftClientLocalTicketTracker
  22. //! GameLift client ticket tracker to describe submitted matchmaking ticket periodically,
  23. //! and join player to the match once matchmaking ticket is complete.
  24. //! For use in production, please see GameLifts guidance about matchmaking at volume.
  25. //! The continuous polling approach here is only suitable for low volume matchmaking and is meant to aid with development only
  26. class AWSGameLiftClientLocalTicketTracker
  27. : public AWSGameLiftMatchmakingEventRequestBus::Handler
  28. {
  29. public:
  30. static constexpr const char AWSGameLiftClientLocalTicketTrackerName[] = "AWSGameLiftClientLocalTicketTracker";
  31. // Set ticket polling period to 10 seconds
  32. // https://docs.aws.amazon.com/gamelift/latest/flexmatchguide/match-client.html#match-client-track
  33. static constexpr const uint64_t AWSGameLiftClientDefaultPollingPeriodInMS = 10000;
  34. AWSGameLiftClientLocalTicketTracker();
  35. virtual ~AWSGameLiftClientLocalTicketTracker() = default;
  36. virtual void ActivateTracker();
  37. virtual void DeactivateTracker();
  38. // AWSGameLiftMatchmakingEventRequestBus interface implementation
  39. void StartPolling(const AZStd::string& ticketId, const AZStd::string& playerId) override;
  40. void StopPolling() override;
  41. protected:
  42. // For testing friendly access
  43. uint64_t m_pollingPeriodInMS;
  44. TicketTrackerStatus m_status;
  45. private:
  46. void ProcessPolling(const AZStd::string& ticketId, const AZStd::string& playerId);
  47. void RequestPlayerJoinMatch(const Aws::GameLift::Model::MatchmakingTicket& ticket, const AZStd::string& playerId);
  48. AZStd::mutex m_trackerMutex;
  49. AZStd::thread m_trackerThread;
  50. AZStd::binary_semaphore m_waitEvent;
  51. };
  52. } // namespace AWSGameLift