ServerRunner.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * ServerRunner.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. struct StartInfo;
  13. VCMI_LIB_NAMESPACE_END
  14. class CVCMIServer;
  15. class IServerRunner
  16. {
  17. public:
  18. virtual void start(uint16_t port, bool connectToLobby, std::shared_ptr<StartInfo> startingInfo) = 0;
  19. virtual void shutdown() = 0;
  20. virtual void wait() = 0;
  21. virtual int exitCode() = 0;
  22. virtual ~IServerRunner() = default;
  23. };
  24. /// Class that runs server instance as a thread of client process
  25. class ServerThreadRunner : public IServerRunner, boost::noncopyable
  26. {
  27. std::unique_ptr<CVCMIServer> server;
  28. boost::thread threadRunLocalServer;
  29. public:
  30. void start(uint16_t port, bool connectToLobby, std::shared_ptr<StartInfo> startingInfo) override;
  31. void shutdown() override;
  32. void wait() override;
  33. int exitCode() override;
  34. ServerThreadRunner();
  35. ~ServerThreadRunner();
  36. };
  37. #ifndef VCMI_MOBILE
  38. namespace boost::process {
  39. class child;
  40. }
  41. /// Class that runs server instance as a child process
  42. /// Available only on desktop systems where process management is allowed
  43. class ServerProcessRunner : public IServerRunner, boost::noncopyable
  44. {
  45. std::unique_ptr<boost::process::child> child;
  46. public:
  47. void start(uint16_t port, bool connectToLobby, std::shared_ptr<StartInfo> startingInfo) override;
  48. void shutdown() override;
  49. void wait() override;
  50. int exitCode() override;
  51. ServerProcessRunner();
  52. ~ServerProcessRunner();
  53. };
  54. #endif