From 66467e4c18747baec949d3cec595b0c985f7a00c Mon Sep 17 00:00:00 2001
From: Tobias Triffterer <tobias@ep1.ruhr-uni-bochum.de>
Date: Wed, 11 Aug 2021 02:30:11 +0200
Subject: [PATCH] Parse updateHistogram Command

This adds the code necessary to process this new command.
---
 src/command.cpp | 16 +++++++++++++++-
 src/command.h   |  1 +
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/command.cpp b/src/command.cpp
index ba054af..b72ec31 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -98,7 +98,7 @@ Command Command::fromString(const QString& source)
         // Not yet implemented:
         case Action::queryServerInformation:
         case Action::updateHistogram:
-            return Command();
+            return parseUpdateHistogram(rootobj);
         default:
             return Command();
     }
@@ -250,6 +250,20 @@ Protocol::Command Protocol::Command::parseFillHistogram(const QJsonObject& input
            );
 }
 
+Protocol::Command Protocol::Command::parseUpdateHistogram(const QJsonObject& input)
+{
+    if (!input.keys().contains(QStringLiteral("bincontents")) || !input.value(QStringLiteral("bincontents")).isString()) {
+        logError(QStringLiteral("updateHistogram command does not contain bincontents."));
+        return Command();
+    }
+
+     return Command(
+               Action::updateHistogram,
+               Arguments{std::make_pair(QStringLiteral("bincontents"), input.value(QStringLiteral("bincontents")).toString())},
+               input.value(QStringLiteral("token")).toString()
+           );
+}
+
 QString Command::toString() const
 {
     if (action == Action::invalid)
diff --git a/src/command.h b/src/command.h
index e83a266..c1b553f 100644
--- a/src/command.h
+++ b/src/command.h
@@ -75,6 +75,7 @@ private:
     static Command parseUpdateExperimentState(const QJsonObject& input);
     static Command parseSetTargetState(const QJsonObject& input);
     static Command parseFillHistogram(const QJsonObject& input);
+    static Command parseUpdateHistogram(const QJsonObject& input);
 
     static QString getActionString(const Action action);
 };
-- 
GitLab