diff options
author | Brad King <brad.king@kitware.com> | 2016-09-19 13:36:34 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2016-09-19 13:36:34 (GMT) |
commit | 5c87b92b1b7888ee032e3c2a75f35f1f94f4dfa5 (patch) | |
tree | ab19ef186570cb3637eab19d19bef17207a1b748 /Source/cmServer.h | |
parent | 419ad0510193eb2b2e227095a4dd167cd9b3df80 (diff) | |
parent | 7263667c24cecf4bb155fc0cbf687dee8b57f5f7 (diff) | |
download | CMake-5c87b92b1b7888ee032e3c2a75f35f1f94f4dfa5.zip CMake-5c87b92b1b7888ee032e3c2a75f35f1f94f4dfa5.tar.gz CMake-5c87b92b1b7888ee032e3c2a75f35f1f94f4dfa5.tar.bz2 |
Merge topic 'cmake-server-basic'
7263667c Help: Add notes for topic 'cmake-server-basic'
5adde4e7 cmake-server: Add documentation
b63c1f6c cmake-server: Add unit test
d341d077 cmake-server: Implement ServerProtocol 1.0
b13d3e0d cmake-server: Bare-bones server implementation
cd049f01 cmake-server: Report server mode availablitily in Capabilities
Diffstat (limited to 'Source/cmServer.h')
-rw-r--r-- | Source/cmServer.h | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/Source/cmServer.h b/Source/cmServer.h new file mode 100644 index 0000000..0ef1e17 --- /dev/null +++ b/Source/cmServer.h @@ -0,0 +1,85 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2015 Stephen Kelly <steveire@gmail.com> + Copyright 2016 Tobias Hunger <tobias.hunger@qt.io> + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#pragma once + +#include "cmListFileCache.h" +#include "cmState.h" + +#if defined(CMAKE_BUILD_WITH_CMAKE) +#include "cm_jsoncpp_value.h" +#include "cm_uv.h" +#endif + +#include <string> +#include <vector> + +class cmServerProtocol; +class cmServerRequest; +class cmServerResponse; + +class cmServer +{ +public: + cmServer(); + ~cmServer(); + + void Serve(); + + // for callbacks: + void PopOne(); + void handleData(std::string const& data); + +private: + void RegisterProtocol(cmServerProtocol* protocol); + + // Handle requests: + cmServerResponse SetProtocolVersion(const cmServerRequest& request); + + void PrintHello() const; + + // Write responses: + void WriteProgress(const cmServerRequest& request, int min, int current, + int max, const std::string& message) const; + void WriteResponse(const cmServerResponse& response) const; + void WriteParseError(const std::string& message) const; + + void WriteJsonObject(Json::Value const& jsonValue) const; + + static cmServerProtocol* FindMatchingProtocol( + const std::vector<cmServerProtocol*>& protocols, int major, int minor); + + cmServerProtocol* Protocol = nullptr; + std::vector<cmServerProtocol*> SupportedProtocols; + std::vector<std::string> Queue; + + std::string DataBuffer; + std::string JsonData; + + uv_loop_t* Loop = nullptr; + + typedef union + { + uv_tty_t tty; + uv_pipe_t pipe; + } InOutUnion; + + InOutUnion Input; + InOutUnion Output; + uv_stream_t* InputStream = nullptr; + uv_stream_t* OutputStream = nullptr; + + mutable bool Writing = false; + + friend class cmServerRequest; +}; |