|
@@ -31,18 +31,24 @@ void QMLHandler::onExit() {
|
|
|
write(outpipefd[1], "disconnect\n", strlen("disconnect\n"));
|
|
|
}
|
|
|
|
|
|
+// This method gets a string and tries to read it as Json
|
|
|
+// If it fails to do so, return and do nothing, else handle the content
|
|
|
void QMLHandler::handleJSON(string buffer) {
|
|
|
Json::Value root;
|
|
|
Json::CharReaderBuilder builder;
|
|
|
Json::CharReader *reader = builder.newCharReader();
|
|
|
string jsonError;
|
|
|
|
|
|
+ // Try to parse the string as Json and store the result of the pasring in a
|
|
|
+ // boolean
|
|
|
bool parsingSuccessful = reader->parse(
|
|
|
buffer.c_str(), buffer.c_str() + buffer.size(), &root, &jsonError);
|
|
|
|
|
|
+ // If the string is not correct Json, return
|
|
|
if (!parsingSuccessful) {
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
const Json::Value command = root["command"];
|
|
|
string cmd = command.asString();
|
|
|
|
|
@@ -56,7 +62,6 @@ void QMLHandler::handleJSON(string buffer) {
|
|
|
|
|
|
else if (cmd == "list") {
|
|
|
emit receivingClearFileList();
|
|
|
-
|
|
|
// Get the array of file Names
|
|
|
auto fileNames = root["names"];
|
|
|
for (int i = 0; i < fileNames.size(); i++) {
|
|
@@ -66,6 +71,10 @@ void QMLHandler::handleJSON(string buffer) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// This method is a loop which runs in a seperate thread.
|
|
|
+// If will read the Input Pipe, which containts the string that get printed
|
|
|
+// on stdout by the CLI/Server, and calls handleJSON with the read content
|
|
|
+// one it reads a newline.
|
|
|
void QMLHandler::readPipeLoop() {
|
|
|
unsigned int readOffset = 0;
|
|
|
unsigned int pollCount = 0;
|