diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2016-09-13 09:26:34 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-09-19 12:57:57 (GMT) |
commit | b13d3e0d0b3c644242ef8dc4977d35da73398a9d (patch) | |
tree | 76312d0c8123d1053d4f98cd3c81edf7f860198d /Source/cmServerProtocol.h | |
parent | cd049f012ef22f8f1214b35e351fda823d534b92 (diff) | |
download | CMake-b13d3e0d0b3c644242ef8dc4977d35da73398a9d.zip CMake-b13d3e0d0b3c644242ef8dc4977d35da73398a9d.tar.gz CMake-b13d3e0d0b3c644242ef8dc4977d35da73398a9d.tar.bz2 |
cmake-server: Bare-bones server implementation
Adds a bare-bones cmake-server implementation and makes it possible
to start that with "cmake -E server".
Communication happens via stdin/stdout for now.
Protocol is based on Json objects surrounded by magic strings
("[== CMake Server ==[" and "]== CMake Server ==]"), which simplifies
Json parsing significantly.
This patch also defines an interface used to implement different
versions of the protocol spoken by the server, but does not include
any protocol implementaiton.
Diffstat (limited to 'Source/cmServerProtocol.h')
-rw-r--r-- | Source/cmServerProtocol.h | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/Source/cmServerProtocol.h b/Source/cmServerProtocol.h new file mode 100644 index 0000000..e086f72 --- /dev/null +++ b/Source/cmServerProtocol.h @@ -0,0 +1,97 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + 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" + +#if defined(CMAKE_BUILD_WITH_CMAKE) +#include "cm_jsoncpp_writer.h" +#endif + +#include <memory> +#include <string> + +class cmake; +class cmServer; + +class cmServerRequest; + +class cmServerResponse +{ +public: + explicit cmServerResponse(const cmServerRequest& request); + + void SetData(const Json::Value& data); + void SetError(const std::string& message); + + bool IsComplete() const; + bool IsError() const; + std::string ErrorMessage() const; + Json::Value Data() const; + + const std::string Type; + const std::string Cookie; + +private: + enum PayLoad + { + PAYLOAD_UNKNOWN, + PAYLOAD_ERROR, + PAYLOAD_DATA + }; + PayLoad m_Payload = PAYLOAD_UNKNOWN; + std::string m_ErrorMessage; + Json::Value m_Data; +}; + +class cmServerRequest +{ +public: + void ReportProgress(int min, int current, int max, + const std::string& message) const; + + cmServerResponse Reply(const Json::Value& data) const; + cmServerResponse ReportError(const std::string& message) const; + + const std::string Type; + const std::string Cookie; + const Json::Value Data; + +private: + cmServerRequest(cmServer* server, const std::string& t, const std::string& c, + const Json::Value& d); + + cmServer* m_Server; + + friend class cmServer; +}; + +class cmServerProtocol +{ +public: + virtual ~cmServerProtocol() {} + + virtual std::pair<int, int> ProtocolVersion() const = 0; + virtual const cmServerResponse Process(const cmServerRequest& request) = 0; + + bool Activate(const cmServerRequest& request, std::string* errorMessage); + +protected: + cmake* CMakeInstance() const; + // Implement protocol specific activation tasks here. Called from Activate(). + virtual bool DoActivate(const cmServerRequest& request, + std::string* errorMessage); + +private: + std::unique_ptr<cmake> m_CMakeInstance; +}; |