GUIApplicationServer.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #include <native/utilities/GUIApplicationServer.h>
  9. #include <AzFramework/API/ApplicationAPI.h>
  10. #include "native/utilities/assetUtils.h"
  11. GUIApplicationServer::GUIApplicationServer(QObject* parent)
  12. : ApplicationServer(parent)
  13. {
  14. }
  15. GUIApplicationServer::~GUIApplicationServer()
  16. {
  17. }
  18. bool GUIApplicationServer::startListening(unsigned short port)
  19. {
  20. if (!isListening())
  21. {
  22. const AzFramework::CommandLine* commandLine = nullptr;
  23. AzFramework::ApplicationRequests::Bus::BroadcastResult(commandLine, &AzFramework::ApplicationRequests::GetCommandLine);
  24. bool randomPort = commandLine && commandLine->HasSwitch(ApplicationServer::RandomListeningPortOption);
  25. if (port == 0 && !randomPort)
  26. {
  27. quint16 listeningPort = AssetUtilities::ReadListeningPortFromSettingsRegistry();
  28. m_serverListeningPort = static_cast<int>(listeningPort);
  29. }
  30. else
  31. {
  32. // override the port
  33. m_serverListeningPort = port;
  34. }
  35. if (!listen(QHostAddress::Any, aznumeric_cast<quint16>(m_serverListeningPort)))
  36. {
  37. AZ_Error(
  38. AssetProcessor::ConsoleChannel,
  39. false,
  40. "Cannot start Asset Processor server - another instance of the Asset Processor may already be running on port number %d. "
  41. "If you'd like to run multiple Asset Processors on different branches at the same time, please modify the /Amazon/AzCore/Bootstrap/remote_port "
  42. " registry setting (by default this is set in bootstrap.setreg) and assign different remote_port values to each branch "
  43. "instance.\n",
  44. m_serverListeningPort);
  45. return false;
  46. }
  47. m_serverListeningPort = serverPort();
  48. AZ_TracePrintf(AssetProcessor::ConsoleChannel, "Listening Port: %d\n", m_serverListeningPort);
  49. ApplicationServerBus::Handler::BusConnect();
  50. AZ_TracePrintf(AssetProcessor::DebugChannel, "Asset Processor server listening on port %d\n", m_serverListeningPort);
  51. }
  52. return true;
  53. }