cmServer.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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(bool supportExperimental);
  27. ~cmServer();
  28. bool Serve();
  29. // for callbacks:
  30. void PopOne();
  31. void handleData(std::string const& data);
  32. private:
  33. void RegisterProtocol(cmServerProtocol* protocol);
  34. static void reportProgress(const char* msg, float progress, void* data);
  35. // Handle requests:
  36. cmServerResponse SetProtocolVersion(const cmServerRequest& request);
  37. void PrintHello() const;
  38. // Write responses:
  39. void WriteProgress(const cmServerRequest& request, int min, int current,
  40. int max, const std::string& message) const;
  41. void WriteResponse(const cmServerResponse& response) const;
  42. void WriteParseError(const std::string& message) const;
  43. void WriteJsonObject(Json::Value const& jsonValue) const;
  44. static cmServerProtocol* FindMatchingProtocol(
  45. const std::vector<cmServerProtocol*>& protocols, int major, int minor);
  46. const bool SupportExperimental;
  47. cmServerProtocol* Protocol = nullptr;
  48. std::vector<cmServerProtocol*> SupportedProtocols;
  49. std::vector<std::string> Queue;
  50. std::string DataBuffer;
  51. std::string JsonData;
  52. uv_loop_t* Loop = nullptr;
  53. typedef union
  54. {
  55. uv_tty_t tty;
  56. uv_pipe_t pipe;
  57. } InOutUnion;
  58. InOutUnion Input;
  59. InOutUnion Output;
  60. uv_stream_t* InputStream = nullptr;
  61. uv_stream_t* OutputStream = nullptr;
  62. mutable bool Writing = false;
  63. friend class cmServerRequest;
  64. };