cmServer.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2015 Stephen Kelly <[email protected]>
  4. Copyright 2016 Tobias Hunger <[email protected]>
  5. Distributed under the OSI-approved BSD License (the "License");
  6. see accompanying file Copyright.txt for details.
  7. This software is distributed WITHOUT ANY WARRANTY; without even the
  8. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. See the License for more information.
  10. ============================================================================*/
  11. #pragma once
  12. #include "cmListFileCache.h"
  13. #include "cmState.h"
  14. #if defined(CMAKE_BUILD_WITH_CMAKE)
  15. #include "cm_jsoncpp_value.h"
  16. #include "cm_uv.h"
  17. #endif
  18. #include <string>
  19. #include <vector>
  20. class cmServerProtocol;
  21. class cmServerRequest;
  22. class cmServerResponse;
  23. class cmServer
  24. {
  25. public:
  26. cmServer();
  27. ~cmServer();
  28. void Serve();
  29. // for callbacks:
  30. void PopOne();
  31. void handleData(std::string const& data);
  32. private:
  33. void RegisterProtocol(cmServerProtocol* protocol);
  34. // Handle requests:
  35. cmServerResponse SetProtocolVersion(const cmServerRequest& request);
  36. void PrintHello() const;
  37. // Write responses:
  38. void WriteProgress(const cmServerRequest& request, int min, int current,
  39. int max, const std::string& message) const;
  40. void WriteResponse(const cmServerResponse& response) const;
  41. void WriteParseError(const std::string& message) const;
  42. void WriteJsonObject(Json::Value const& jsonValue) const;
  43. static cmServerProtocol* FindMatchingProtocol(
  44. const std::vector<cmServerProtocol*>& protocols, int major, int minor);
  45. cmServerProtocol* Protocol = nullptr;
  46. std::vector<cmServerProtocol*> SupportedProtocols;
  47. std::vector<std::string> Queue;
  48. std::string DataBuffer;
  49. std::string JsonData;
  50. uv_loop_t* Loop = nullptr;
  51. typedef union
  52. {
  53. uv_tty_t tty;
  54. uv_pipe_t pipe;
  55. } InOutUnion;
  56. InOutUnion Input;
  57. InOutUnion Output;
  58. uv_stream_t* InputStream = nullptr;
  59. uv_stream_t* OutputStream = nullptr;
  60. mutable bool Writing = false;
  61. friend class cmServerRequest;
  62. };