CMake/Source/cmServerProtocol.h

131 lines
3.4 KiB
C
Raw Normal View History

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
2016-09-27 19:01:08 +00:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
#include "cmListFileCache.h"
#include "cmake.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
#include "cm_jsoncpp_writer.h"
#endif
#include <memory>
#include <string>
class cmake;
class cmFileMonitor;
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:
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);
void ReportProgress(int min, int current, int max,
const std::string& message) const;
void ReportMessage(const std::string& message,
const std::string& title) const;
cmServer* m_Server;
friend class cmServer;
};
class cmServerProtocol
{
public:
virtual ~cmServerProtocol() {}
virtual std::pair<int, int> ProtocolVersion() const = 0;
virtual bool IsExperimental() const = 0;
virtual const cmServerResponse Process(const cmServerRequest& request) = 0;
bool Activate(cmServer* server, const cmServerRequest& request,
std::string* errorMessage);
cmFileMonitor* FileMonitor() const;
void SendSignal(const std::string& name, const Json::Value& data) const;
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;
cmServer* m_Server = nullptr; // not owned!
friend class cmServer;
};
class cmServerProtocol1_0 : public cmServerProtocol
{
public:
std::pair<int, int> ProtocolVersion() const override;
bool IsExperimental() const override;
const cmServerResponse Process(const cmServerRequest& request) override;
private:
bool DoActivate(const cmServerRequest& request,
std::string* errorMessage) override;
// Handle requests:
cmServerResponse ProcessCache(const cmServerRequest& request);
cmServerResponse ProcessCMakeInputs(const cmServerRequest& request);
cmServerResponse ProcessCodeModel(const cmServerRequest& request);
cmServerResponse ProcessCompute(const cmServerRequest& request);
cmServerResponse ProcessConfigure(const cmServerRequest& request);
cmServerResponse ProcessGlobalSettings(const cmServerRequest& request);
cmServerResponse ProcessSetGlobalSettings(const cmServerRequest& request);
cmServerResponse ProcessFileSystemWatchers(const cmServerRequest& request);
enum State
{
STATE_INACTIVE,
STATE_ACTIVE,
STATE_CONFIGURED,
STATE_COMPUTED
};
State m_State = STATE_INACTIVE;
};