Parcourir la source

changes as per last commit message

logicp il y a 5 ans
Parent
commit
a910093f52
2 fichiers modifiés avec 31 ajouts et 10 suppressions
  1. 16 9
      headers/util.hpp
  2. 15 1
      src/client.cpp

+ 16 - 9
headers/util.hpp

@@ -1,20 +1,20 @@
 #ifndef UTIL_HPP
 #define UTIL_HPP
 #pragma GCC system_header
-#include <string>
+#include <QDebug>
+#include <QQueue>
+#include <QString>
+#include <QVector>
 #include <charconv>
+#include <string>
 #include <utility>
 #include <vector>
-#include <QDebug>
-#include <QVector>
-#include <QString>
-#include "rapidjson/writer.h"
-#include "rapidjson/prettywriter.h"
+#include "json.hpp"
+#include "rapidjson/document.h"
 #include "rapidjson/pointer.h"
+#include "rapidjson/prettywriter.h"
 #include "rapidjson/stringbuffer.h"
-#include "rapidjson/document.h"
-#include "json.hpp"
-
+#include "rapidjson/writer.h"
 
 namespace Kontainer {
 /** Reverse Iterator */
@@ -39,6 +39,13 @@ struct KFileData {
     QByteArray bytes;
 };
 
+struct Task {
+  QVector<KFileData> files;
+  std::vector<std::string> args;
+};
+
+typedef QQueue<Task> TaskQueue;
+
 namespace {
 using namespace rapidjson;
 using json = nlohmann::json;

+ 15 - 1
src/client.cpp

@@ -279,6 +279,20 @@ void Client::sendTaskEncoded(TaskType type, std::vector<std::string> args) {
         builder.Clear();
         sent_files.clear();
         m_task.clear();
+        if (!m_task_queue.isEmpty()) {
+          auto task = m_task_queue.dequeue();
+          if (!task.files.empty()) {
+            if (!outgoing_files.empty()) {
+              qDebug() << "There are still outgoing files left over from last "
+                          "task which were never sent. They are being deleted";
+              outgoing_files.clear();
+            }
+          }
+          // We simply need to send files. Once the last file is sent, Client
+          // will check the value of m_task and send it to Server.
+          m_task = task.args;
+          sendFiles(task.files);
+        }
     }
 }
 
@@ -464,7 +478,7 @@ void Client::sendFiles(QVector<KFileData> files) {
     if (outgoing_files.isEmpty()) {
       file_was_sent = false;
       for (const auto& file : files) {
-        outgoing_files.enqueue(file);
+        outgoing_files.enqueue(std::move(file));
         }
         std::string send_file_operation = createOperation("FileUpload", {});
         sendEncoded(send_file_operation);