ServerRunner.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. class CVCMIServer;
  12. class IServerRunner
  13. {
  14. public:
  15. virtual void start(uint16_t port, bool connectToLobby) = 0;
  16. virtual void shutdown() = 0;
  17. virtual void wait() = 0;
  18. virtual int exitCode() = 0;
  19. virtual ~IServerRunner() = default;
  20. };
  21. /// Class that runs server instance as a thread of client process
  22. class ServerThreadRunner : public IServerRunner, boost::noncopyable
  23. {
  24. std::unique_ptr<CVCMIServer> server;
  25. boost::thread threadRunLocalServer;
  26. public:
  27. void start(uint16_t port, bool connectToLobby) override;
  28. void shutdown() override;
  29. void wait() override;
  30. int exitCode() override;
  31. ServerThreadRunner();
  32. ~ServerThreadRunner();
  33. };
  34. #ifndef VCMI_MOBILE
  35. namespace boost::process {
  36. class child;
  37. }
  38. /// Class that runs server instance as a child process
  39. /// Available only on desktop systems where process management is allowed
  40. class ServerProcessRunner : public IServerRunner, boost::noncopyable
  41. {
  42. std::unique_ptr<boost::process::child> child;
  43. public:
  44. void start(uint16_t port, bool connectToLobby) override;
  45. void shutdown() override;
  46. void wait() override;
  47. int exitCode() override;
  48. ServerProcessRunner();
  49. ~ServerProcessRunner();
  50. };
  51. #endif