Browse Source

redirect all non-json to stderr

Missingmew 5 năm trước cách đây
mục cha
commit
5d972eb5e0
2 tập tin đã thay đổi với 15 bổ sung13 xóa
  1. 6 3
      cli/src/iomanager.cpp
  2. 9 10
      cli/src/machineiomanager.cpp

+ 6 - 3
cli/src/iomanager.cpp

@@ -70,13 +70,14 @@ bool IoManager::connect() {
   // send version check
   root["version"] = VERSION;
 
-  std::cout << root << std::endl;
+  std::cerr << root << std::endl;
   
   if(!sendJson(root)) return false;
   // receive answer
   if(!receiveJson(recvbuf)) return false;
   if(!parseJson(&root, recvbuf)) return false;
 
+  // dump for GUI
   std::cout << root << std::endl;
 
   // check if version check was ok
@@ -100,7 +101,7 @@ bool IoManager::connect() {
   root["user"] = "user";
   root["pass"] = "pass";
 
-  std::cout << root << std::endl;
+  std::cerr << root << std::endl;
 
   // send login
   if(!sendJson(root)) return false;
@@ -108,6 +109,7 @@ bool IoManager::connect() {
   if(!receiveJson(recvbuf)) return false;
   if(!parseJson(&root, recvbuf)) return false;
 
+  // dump for GUI
   std::cout << root << std::endl;
   /* */
 
@@ -132,7 +134,7 @@ IoManager::~IoManager() {
   // TODO make client version global
   root["command"] = "close";
 
-  std::cout << root << std::endl;
+  std::cerr << root << std::endl;
 
   // send disconnect
   sendJson(root);
@@ -140,6 +142,7 @@ IoManager::~IoManager() {
   receiveJson(recvbuf);
   parseJson(&root, recvbuf);
 
+  // dump to GUI
   std::cout << root << std::endl;
   /* */
 

+ 9 - 10
cli/src/machineiomanager.cpp

@@ -13,7 +13,7 @@
 using boost::asio::buffer;
 
 void MachineIoManager::run() {
-  std::cout << "MachineIoManager::run() says hello!" << std::endl;
+  std::cerr << "MachineIoManager::run() says hello!" << std::endl;
 
   boost::asio::streambuf recvbuf;
 
@@ -83,8 +83,6 @@ void MachineIoManager::run() {
 
       // dump received data to stdout for gui to handle
 	    std::cout << recv;
-      //~ recvjson = boost::asio::buffer_cast<const char *>(recvbuf.data());
-      //~ std::cout << recvjson;
 
       break;
     }
@@ -104,7 +102,7 @@ void MachineIoManager::run() {
 	    size = fs.tellg();
 	    fs.seekg(0, fs.beg);
 	    chunks = size / BLOCKSIZE + ((size % BLOCKSIZE)?1:0);
-	    std::cout << "size is " << size << " chunks are " << chunks << std::endl;
+	    std::cerr << "size is " << size << " chunks are " << chunks << std::endl;
 	    
 	    if(!size) {
 		    std::cerr << "not sending empty file" << std::endl;
@@ -117,7 +115,7 @@ void MachineIoManager::run() {
 	    root["file"] = pathtemp.back();
 	    root["size"] = size;
 	    
-	    std::cout << root;
+	    std::cerr << root;
 	    
 	    if(!sendJson(root) | !receiveJson(recvbuf) | !parseJson(&recv, recvbuf)) {
 		    // error occured, stop working
@@ -133,7 +131,7 @@ void MachineIoManager::run() {
 		    root["command"] = "put";
 		    root["cancel"] = false;
 		    
-		    std::cout << root;
+		    std::cerr << root;
 		    
 		    while(chunks) {
 			haveread = fs.readsome(rbuf, BLOCKSIZE);
@@ -149,7 +147,6 @@ void MachineIoManager::run() {
 				break;
 			}
 			std::cout << root;
-			std::this_thread::sleep_for (std::chrono::seconds(1));
 		    }
 		    if(chunks) std::cerr << "not all data sent, remain chunks " << chunks << std::endl;
 	    }
@@ -177,6 +174,7 @@ void MachineIoManager::run() {
 		    break;
 	    }
 	    
+	    // dump received data for GUI
 	    std::cout << recv << std::endl;
 	    
 	    if(recv["accept"].asBool()) {
@@ -185,11 +183,12 @@ void MachineIoManager::run() {
 		    root["cancel"] = false;
 		    // request ok, start receiving
 		    chunks = std::numeric_limits<int>::max();
-		    std::cout << "survive" << std::endl;
+		    std::cerr << "survive" << std::endl;
 		    while(chunks) {
-			    std::cout << "survive" << std::endl;
+			    std::cerr << "survive" << std::endl;
 			    if(!receiveJson(recvbuf) | !parseJson(&recv, recvbuf)) break;
-			    std::cout << "survive" << std::endl;
+			    std::cerr << "survive" << std::endl;
+			    // dump received data for GUI
 			    std::cout << recv << std::endl;
 			    wtmp = base64::decodeVector(recv["data"].asString());
 			    fs.write(wtmp.data(), wtmp.size());