Parcourir la source

implement machine mode listing

Missingmew il y a 5 ans
Parent
commit
00493f7a62
1 fichiers modifiés avec 35 ajouts et 0 suppressions
  1. 35 0
      cli/src/machineiomanager.cpp

+ 35 - 0
cli/src/machineiomanager.cpp

@@ -205,6 +205,41 @@ void MachineIoManager::run() {
 	    if(recv["remaining"].asInt()) std::cerr << "not all data received, remain chunks " << recv["remaining"].asInt();
 	    break;
     }
+    case CMD_LIST: {
+	    int chunks, rec = 0;
+	    root["command"] = "list";
+	    if(!sendJson(root) | !receiveJson(recvbuf) | !parseJson(&recv, recvbuf)) {
+		    // error occured, stop working
+		    break;
+	    }
+	    // dump received data for GUI
+	    std::cout << recv << std::endl;
+	    
+	    if(recv["accept"].asBool()) {
+		    // ACK?
+		    root["command"] = "list";
+		    root["cancel"] = false;
+		    chunks = std::numeric_limits<int>::max();
+		    while(chunks) {
+			    if(!receiveJson(recvbuf) | !parseJson(&recv, recvbuf)) break;
+			    // dump received data for GUI
+			    std::cout << recv << std::endl;
+			    /*
+			    Json::Value arraything = recv["names"];
+			    if(arraything.isArray())
+			    for(Json::Value d : recv["names"])
+			    */
+			    chunks = recv["remaining"].asInt();
+			    root["received"] = rec;
+			    if(!sendJson(root)) {
+				// couldnt ACK
+				break;
+			    }
+			    rec++;
+		    }
+	    }
+	    
+    }
     default: {
       std::cerr << "unknown command " << line << "\n";
       break;