3
0

BarrierInputClient.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/Memory/SystemAllocator.h>
  10. #include <AzCore/Socket/AzSocket_fwd.h>
  11. #include <AzCore/std/parallel/thread.h>
  12. #include <AzCore/std/parallel/atomic.h>
  13. #include <AzCore/std/string/string.h>
  14. ////////////////////////////////////////////////////////////////////////////////////////////////////
  15. namespace BarrierInput
  16. {
  17. ////////////////////////////////////////////////////////////////////////////////////////////////
  18. //! Barrier client that manages a connection with a Barrier server.
  19. class BarrierClient
  20. {
  21. public:
  22. ////////////////////////////////////////////////////////////////////////////////////////////
  23. static constexpr AZ::u32 DEFAULT_BARRIER_CONNECTION_PORT_NUMBER = 24800;
  24. ////////////////////////////////////////////////////////////////////////////////////////////
  25. // Allocator
  26. AZ_CLASS_ALLOCATOR(BarrierClient, AZ::SystemAllocator);
  27. ////////////////////////////////////////////////////////////////////////////////////////////
  28. //! Constructor
  29. //! \param[in] clientScreenName Name of the Barrier client screen this class implements
  30. //! \param[in] serverHostName Name of the Barrier server host this client connects to
  31. //! \param[in] connectionPort Port number over which to connect to the Barrier server
  32. BarrierClient(const char* clientScreenName,
  33. const char* serverHostName,
  34. AZ::u32 connectionPort = DEFAULT_BARRIER_CONNECTION_PORT_NUMBER);
  35. ////////////////////////////////////////////////////////////////////////////////////////////
  36. //! Destructor
  37. ~BarrierClient();
  38. ////////////////////////////////////////////////////////////////////////////////////////////
  39. //! Access to the Barrier client screen this class implements
  40. //! \return Name of the Barrier client screen this class implements
  41. const AZStd::string& GetClientScreenName() const { return m_clientScreenName; }
  42. ////////////////////////////////////////////////////////////////////////////////////////////
  43. //! Access to the Barrier server host this client connects to
  44. //! \return Name of the Barrier server host this client connects to
  45. const AZStd::string& GetServerHostName() const { return m_serverHostName; }
  46. ////////////////////////////////////////////////////////////////////////////////////////////
  47. //! Access to the socket the Barrier client is communicating over
  48. //! \return The socket the Barrier client is communicating over
  49. const AZSOCKET& GetSocket() const { return m_socket; }
  50. protected:
  51. ////////////////////////////////////////////////////////////////////////////////////////////
  52. //! The client connection loop that runs in it's own thread
  53. void Run();
  54. ////////////////////////////////////////////////////////////////////////////////////////////
  55. //! Try to connect to the Barrier server
  56. //! \return True if we're connected to the Barrier server, false otherwise
  57. bool ConnectToServer();
  58. private:
  59. ////////////////////////////////////////////////////////////////////////////////////////////
  60. // Variables
  61. AZStd::string m_clientScreenName;
  62. AZStd::string m_serverHostName;
  63. AZ::u32 m_connectionPort;
  64. AZStd::thread m_threadHandle;
  65. AZStd::atomic_bool m_threadQuit;
  66. AZSOCKET m_socket;
  67. };
  68. } // namespace BarrierInput