server-mode: Report watched files to client

* Add a command to report watched files and directories to clients.
This commit is contained in:
Tobias Hunger 2016-09-09 10:01:46 +02:00
parent 0d96e19329
commit 262500028c
4 changed files with 49 additions and 0 deletions

View File

@ -635,3 +635,26 @@ CMake will respond with the following output::
The output can be limited to a list of keys by passing an array of key names The output can be limited to a list of keys by passing an array of key names
to the "keys" optional field of the "cache" request. to the "keys" optional field of the "cache" request.
Type "fileSystemWatchers"
^^^^^^^^^^^^^^^^^^^^^^^^^
The server can watch the filesystem for changes. The "fileSystemWatchers"
command will report on the files and directories watched.
Example::
[== CMake Server ==]
{"type":"fileSystemWatchers"}
[== CMake Server ==]
CMake will respond with the following output::
[== CMake Server ==]
{
"cookie":"","inReplyTo":"fileSystemWatchers","type":"reply",
"watchedFiles": [ "/absolute/path" ],
"watchedDirectories": [ "/absolute" ]
}
[== CMake Server ==]

View File

@ -12,6 +12,7 @@ static const std::string kCODE_MODEL_TYPE = "codemodel";
static const std::string kCOMPUTE_TYPE = "compute"; static const std::string kCOMPUTE_TYPE = "compute";
static const std::string kCONFIGURE_TYPE = "configure"; static const std::string kCONFIGURE_TYPE = "configure";
static const std::string kERROR_TYPE = "error"; static const std::string kERROR_TYPE = "error";
static const std::string kFILESYSTEM_WATCHERS_TYPE = "fileSystemWatchers";
static const std::string kGLOBAL_SETTINGS_TYPE = "globalSettings"; static const std::string kGLOBAL_SETTINGS_TYPE = "globalSettings";
static const std::string kHANDSHAKE_TYPE = "handshake"; static const std::string kHANDSHAKE_TYPE = "handshake";
static const std::string kMESSAGE_TYPE = "message"; static const std::string kMESSAGE_TYPE = "message";
@ -80,6 +81,8 @@ static const std::string kVALUE_KEY = "value";
static const std::string kWARN_UNINITIALIZED_KEY = "warnUninitialized"; static const std::string kWARN_UNINITIALIZED_KEY = "warnUninitialized";
static const std::string kWARN_UNUSED_CLI_KEY = "warnUnusedCli"; static const std::string kWARN_UNUSED_CLI_KEY = "warnUnusedCli";
static const std::string kWARN_UNUSED_KEY = "warnUnused"; static const std::string kWARN_UNUSED_KEY = "warnUnused";
static const std::string kWATCHED_DIRECTORIES_KEY = "watchedDirectories";
static const std::string kWATCHED_FILES_KEY = "watchedFiles";
static const std::string kSTART_MAGIC = "[== CMake Server ==["; static const std::string kSTART_MAGIC = "[== CMake Server ==[";
static const std::string kEND_MAGIC = "]== CMake Server ==]"; static const std::string kEND_MAGIC = "]== CMake Server ==]";

View File

@ -391,6 +391,9 @@ const cmServerResponse cmServerProtocol1_0::Process(
if (request.Type == kCONFIGURE_TYPE) { if (request.Type == kCONFIGURE_TYPE) {
return this->ProcessConfigure(request); return this->ProcessConfigure(request);
} }
if (request.Type == kFILESYSTEM_WATCHERS_TYPE) {
return this->ProcessFileSystemWatchers(request);
}
if (request.Type == kGLOBAL_SETTINGS_TYPE) { if (request.Type == kGLOBAL_SETTINGS_TYPE) {
return this->ProcessGlobalSettings(request); return this->ProcessGlobalSettings(request);
} }
@ -1019,3 +1022,22 @@ cmServerResponse cmServerProtocol1_0::ProcessSetGlobalSettings(
return request.Reply(Json::Value()); return request.Reply(Json::Value());
} }
cmServerResponse cmServerProtocol1_0::ProcessFileSystemWatchers(
const cmServerRequest& request)
{
const cmFileMonitor* const fm = FileMonitor();
Json::Value result = Json::objectValue;
Json::Value files = Json::arrayValue;
for (const auto& f : fm->WatchedFiles()) {
files.append(f);
}
Json::Value directories = Json::arrayValue;
for (const auto& d : fm->WatchedDirectories()) {
directories.append(d);
}
result[kWATCHED_FILES_KEY] = files;
result[kWATCHED_DIRECTORIES_KEY] = directories;
return request.Reply(result);
}

View File

@ -117,6 +117,7 @@ private:
cmServerResponse ProcessConfigure(const cmServerRequest& request); cmServerResponse ProcessConfigure(const cmServerRequest& request);
cmServerResponse ProcessGlobalSettings(const cmServerRequest& request); cmServerResponse ProcessGlobalSettings(const cmServerRequest& request);
cmServerResponse ProcessSetGlobalSettings(const cmServerRequest& request); cmServerResponse ProcessSetGlobalSettings(const cmServerRequest& request);
cmServerResponse ProcessFileSystemWatchers(const cmServerRequest& request);
enum State enum State
{ {