2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2016-09-13 12:26:34 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "cmListFileCache.h"
|
2016-09-09 11:01:45 +03:00
|
|
|
#include "cmake.h"
|
2016-09-13 12:26:34 +03:00
|
|
|
|
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
|
|
|
#include "cm_jsoncpp_writer.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class cmake;
|
2016-09-09 11:01:46 +03:00
|
|
|
class cmFileMonitor;
|
2016-09-13 12:26:34 +03:00
|
|
|
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);
|
|
|
|
|
2016-09-09 11:01:44 +03:00
|
|
|
void ReportProgress(int min, int current, int max,
|
|
|
|
const std::string& message) const;
|
2016-09-09 11:01:44 +03:00
|
|
|
void ReportMessage(const std::string& message,
|
|
|
|
const std::string& title) const;
|
2016-09-09 11:01:44 +03:00
|
|
|
|
2016-09-13 12:26:34 +03:00
|
|
|
cmServer* m_Server;
|
|
|
|
|
|
|
|
friend class cmServer;
|
|
|
|
};
|
|
|
|
|
|
|
|
class cmServerProtocol
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~cmServerProtocol() {}
|
|
|
|
|
|
|
|
virtual std::pair<int, int> ProtocolVersion() const = 0;
|
2016-09-09 11:01:44 +03:00
|
|
|
virtual bool IsExperimental() const = 0;
|
2016-09-13 12:26:34 +03:00
|
|
|
virtual const cmServerResponse Process(const cmServerRequest& request) = 0;
|
|
|
|
|
2016-09-09 13:50:23 +03:00
|
|
|
bool Activate(cmServer* server, const cmServerRequest& request,
|
|
|
|
std::string* errorMessage);
|
2016-09-13 12:26:34 +03:00
|
|
|
|
2016-09-09 11:01:46 +03:00
|
|
|
cmFileMonitor* FileMonitor() const;
|
2016-09-09 11:01:45 +03:00
|
|
|
void SendSignal(const std::string& name, const Json::Value& data) const;
|
|
|
|
|
2016-09-13 12:26:34 +03:00
|
|
|
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;
|
2016-09-09 13:50:23 +03:00
|
|
|
cmServer* m_Server = nullptr; // not owned!
|
2016-09-09 11:01:44 +03:00
|
|
|
|
|
|
|
friend class cmServer;
|
2016-09-13 12:26:34 +03:00
|
|
|
};
|
2016-09-13 12:39:24 +03:00
|
|
|
|
|
|
|
class cmServerProtocol1_0 : public cmServerProtocol
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::pair<int, int> ProtocolVersion() const override;
|
2016-09-09 11:01:44 +03:00
|
|
|
bool IsExperimental() const override;
|
2016-09-13 12:39:24 +03:00
|
|
|
const cmServerResponse Process(const cmServerRequest& request) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool DoActivate(const cmServerRequest& request,
|
|
|
|
std::string* errorMessage) override;
|
|
|
|
|
2016-09-09 11:01:46 +03:00
|
|
|
void HandleCMakeFileChanges(const std::string& path, int event, int status);
|
|
|
|
|
2016-09-09 11:01:45 +03:00
|
|
|
// Handle requests:
|
2016-09-09 11:01:46 +03:00
|
|
|
cmServerResponse ProcessCache(const cmServerRequest& request);
|
2016-09-09 11:01:46 +03:00
|
|
|
cmServerResponse ProcessCMakeInputs(const cmServerRequest& request);
|
2016-09-09 11:01:46 +03:00
|
|
|
cmServerResponse ProcessCodeModel(const cmServerRequest& request);
|
2016-09-09 11:01:45 +03:00
|
|
|
cmServerResponse ProcessCompute(const cmServerRequest& request);
|
2016-09-09 11:01:45 +03:00
|
|
|
cmServerResponse ProcessConfigure(const cmServerRequest& request);
|
2016-09-09 11:01:45 +03:00
|
|
|
cmServerResponse ProcessGlobalSettings(const cmServerRequest& request);
|
2016-09-09 11:01:45 +03:00
|
|
|
cmServerResponse ProcessSetGlobalSettings(const cmServerRequest& request);
|
2016-09-09 11:01:46 +03:00
|
|
|
cmServerResponse ProcessFileSystemWatchers(const cmServerRequest& request);
|
2016-09-09 11:01:45 +03:00
|
|
|
|
2016-09-13 12:39:24 +03:00
|
|
|
enum State
|
|
|
|
{
|
|
|
|
STATE_INACTIVE,
|
2016-09-09 11:01:45 +03:00
|
|
|
STATE_ACTIVE,
|
2016-09-09 11:01:45 +03:00
|
|
|
STATE_CONFIGURED,
|
|
|
|
STATE_COMPUTED
|
2016-09-13 12:39:24 +03:00
|
|
|
};
|
|
|
|
State m_State = STATE_INACTIVE;
|
2016-09-09 11:01:46 +03:00
|
|
|
|
|
|
|
bool m_isDirty = false;
|
2016-09-13 12:39:24 +03:00
|
|
|
};
|