Browse Source

added listdata command to JsonCommander

marius.rescheleit 5 năm trước cách đây
mục cha
commit
639cd8fbb8
2 tập tin đã thay đổi với 25 bổ sung1 xóa
  1. 5 0
      daemon/include/JsonCommander.h
  2. 20 1
      daemon/src/JsonCommander.cpp

+ 5 - 0
daemon/include/JsonCommander.h

@@ -101,6 +101,11 @@ private:
    */
   Response executeList(const Json::Value &message);
 
+  /**
+   * Executes the listdata command
+   */
+  Response executeListData(const Json::Value &message);
+
   /**
    * Executes the put command
    */

+ 20 - 1
daemon/src/JsonCommander.cpp

@@ -6,6 +6,7 @@ JsonCommander::JsonCommander(FileManager &fileManager)
   commandsMap["status"] = &JsonCommander::executeStatus;
   commandsMap["close"] = &JsonCommander::executeClose;
   commandsMap["list"] = &JsonCommander::executeList;
+  commandsMap["listdata"] = &JsonCommander::executeListData;
   commandsMap["put"] = &JsonCommander::executePut;
   commandsMap["putdata"] = &JsonCommander::executePutdata;
   commandsMap["get"] = &JsonCommander::executeGet;
@@ -70,7 +71,6 @@ JsonCommander::Response JsonCommander::executeList(const Json::Value &message) {
   response.json["accept"] = true;
 
   int chunks = 0;
-  int counter = 0;
 
   std::vector<std::string> v = fileManager.listFiles();
   for(int i=0; i<v.size(); i++) {
@@ -84,6 +84,25 @@ JsonCommander::Response JsonCommander::executeList(const Json::Value &message) {
   return response;
 }
 
+JsonCommander::Response JsonCommander::executeListData(const Json::Value &message) {
+  JsonCommander::Response response;
+  response.action = send;
+  response.json["command"] = "listdata";
+  Json::Value array;
+
+  std::vector<std::string> v = fileManager.listFiles();
+  for(int i=0; i<v.size(); i++) {
+    array.append(v.at(i));
+  }
+
+  response.json["remaining"] = (int) v.size();
+  response.json["cancel"] = false;
+  response.json["names"] = array;
+  response.json["error"] = "";
+
+  return response;
+}
+
 JsonCommander::Response JsonCommander::executePut(const Json::Value &message) {
   JsonCommander::Response response;
   response.json["command"] = "put";