Added "monitor version machine" command, to display the current Bloom version in JSON format

This commit is contained in:
Nav
2022-05-05 20:14:23 +01:00
parent c9d1dd92a3
commit 4a9c26b73e
4 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
#include "BloomVersionMachine.hpp"
#include <QString>
#include <QJsonDocument>
#include <QJsonObject>
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
#include "src/Application.hpp"
#include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp"
namespace Bloom::DebugServer::Gdb::CommandPackets
{
using TargetController::TargetControllerConsole;
using ResponsePackets::ErrorResponsePacket;
using ResponsePackets::ResponsePacket;
using Exceptions::Exception;
BloomVersionMachine::BloomVersionMachine(Monitor&& monitorPacket)
: Monitor(std::move(monitorPacket))
{}
void BloomVersionMachine::handle(DebugSession& debugSession, TargetControllerConsole&) {
Logger::debug("Handling BloomVersionMachine packet");
debugSession.connection.writePacket(ResponsePacket(Packet::toHex(
QJsonDocument(QJsonObject({
{"version", QString::fromStdString(Application::VERSION.toString())},
{"components", QJsonObject({
{"major", Application::VERSION.getMajor()},
{"minor", Application::VERSION.getMinor()},
{"patch", Application::VERSION.getPatch()},
})},
})).toJson().toStdString()
)));
}
}

View File

@@ -0,0 +1,24 @@
#pragma once
#include <cstdint>
#include "Monitor.hpp"
namespace Bloom::DebugServer::Gdb::CommandPackets
{
/**
* The BloomVersionMachine class implements a structure for the "monitor version machine" GDB command.
*
* We just output Bloom's current version number in JSON format.
*/
class BloomVersionMachine: public Monitor
{
public:
explicit BloomVersionMachine(Monitor&& monitorPacket);
void handle(
DebugSession& debugSession,
TargetController::TargetControllerConsole& targetControllerConsole
) override;
};
}

View File

@@ -27,6 +27,7 @@
#include "CommandPackets/Monitor.hpp"
#include "CommandPackets/ResetTarget.hpp"
#include "CommandPackets/BloomVersion.hpp"
#include "CommandPackets/BloomVersionMachine.hpp"
// Response packets
#include "ResponsePackets/TargetStopped.hpp"
@@ -298,6 +299,11 @@ namespace Bloom::DebugServer::Gdb
if (monitorCommand->command == "version") {
return std::make_unique<CommandPackets::BloomVersion>(std::move(*(monitorCommand.get())));
}
if (monitorCommand->command == "version machine") {
return std::make_unique<CommandPackets::BloomVersionMachine>(std::move(*(monitorCommand.get())));
}
if (monitorCommand->command == "reset") {
return std::make_unique<CommandPackets::ResetTarget>(std::move(*(monitorCommand.get())));
}