From c44fc2a3c0a035bbf95e1d237184a2c6c618185c Mon Sep 17 00:00:00 2001 From: Nav Date: Wed, 22 Jun 2022 22:24:27 +0100 Subject: [PATCH] Other bits of tidying --- src/Application.cpp | 20 ++++++++--------- src/Application.hpp | 22 ++++++++----------- src/TargetController/README.md | 11 +++++----- .../TargetDescriptionFile.cpp | 5 +++-- src/main.cpp | 9 ++------ 5 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 23e511b6..f3c4446a 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -1,26 +1,28 @@ #include "Application.hpp" #include -#include -#include #include #include -#include #include "src/Logger/Logger.hpp" #include "src/Helpers/Paths.hpp" + #include "src/Exceptions/InvalidConfig.hpp" namespace Bloom { using namespace Exceptions; - int Application::run(const std::vector& arguments) { + Application::Application(std::vector&& arguments) + : arguments(std::move(arguments)) + {} + + int Application::run() { try { this->setName("Bloom"); - if (!arguments.empty()) { - auto& firstArg = arguments.front(); + if (this->arguments.size() > 1) { + auto& firstArg = this->arguments.at(1); const auto commandHandlersByCommandName = this->getCommandHandlersByCommandName(); if (commandHandlersByCommandName.contains(firstArg)) { @@ -36,7 +38,7 @@ namespace Bloom } #ifdef BLOOM_DEBUG_BUILD - Logger::warning("This is a debug build - some functions may not work as expected."); + Logger::warning("This is a debug build - some functions may not work as expected"); #endif this->startup(); @@ -332,9 +334,7 @@ namespace Bloom } int Application::initProject() { - auto configFile = QFile( - QString::fromStdString(std::filesystem::current_path().string() + "/bloom.json") - ); + auto configFile = QFile(QString::fromStdString(Paths::projectConfigPath())); if (configFile.exists()) { throw Exception("Bloom configuration file (bloom.json) already exists in working directory."); diff --git a/src/Application.hpp b/src/Application.hpp index 5deab95a..9725c31e 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -33,19 +33,16 @@ namespace Bloom class Application: public Thread { public: - static const inline VersionNumber VERSION = VersionNumber(BLOOM_VERSION); + static const inline VersionNumber VERSION = VersionNumber(std::string(BLOOM_VERSION)); - explicit Application() = default; + explicit Application(std::vector&& arguments); /** * Main entry-point for the Bloom program. * - * @param arguments - * A vector of string arguments passed from the user via the cli. - * * @return */ - int run(const std::vector& arguments); + int run(); /** * Checks if the current effective user running Bloom has root privileges. @@ -55,6 +52,8 @@ namespace Bloom static bool isRunningAsRoot(); private: + std::vector arguments; + EventListenerPointer applicationEventListener = std::make_shared("ApplicationEventListener"); /** @@ -67,14 +66,13 @@ namespace Bloom std::thread signalHandlerThread; /** - * The TargetController possesses full control of the connect debug tool and target. It runs on a + * The TargetController possesses full control of the connected debug tool and target. It runs on a * dedicated thread. * * See the TargetController class for more on this. * * I could have used std::optional here, for the late initialisation, but given that we're using - * std::unique_ptr for the debug server (for polymorphism), I thought I'd keep it consistent and just use - * std::unique_ptr for lazy loading. + * std::unique_ptr for the debug server (for polymorphism), I thought I'd keep it consistent. */ std::unique_ptr targetController = nullptr; std::thread targetControllerThread; @@ -94,10 +92,8 @@ namespace Bloom * * Insight is optional - users can disable it via their project configuration. * - * When the user closes the Insight GUI, control of the main thread is returned to Application::run(). How we - * deal with the GUI being closed at this point depends on user configuration. - * - * See the Insight class for more on this. + * When the user closes the Insight GUI, control of the main thread is returned to Application::run(). See the + * Insight class for more on this. * * Because Insight is optional, we only construct the Insight object when we need it. We can't use * std::optional here because the Insight class extends QObject, which disables the copy constructor and diff --git a/src/TargetController/README.md b/src/TargetController/README.md index b4becf6c..2ea43080 100644 --- a/src/TargetController/README.md +++ b/src/TargetController/README.md @@ -89,6 +89,11 @@ When in a suspended state, the TargetController will reject most commands. More requires access to the debug tool or target. Issuing any of these commands whilst the TargetController is suspended will result in an error response. +In some cases, the TargetController may be forced to go into a suspended state. This could be in response to the user +disconnecting the debug tool, or from another program stealing control of the hardware. Actually, this is what led to +the introduction of TargetController suspension. See the corresponding +[GitHub issue](https://github.com/navnavnav/Bloom/issues/3) for more. + Upon suspension, the TargetController will trigger a `Bloom::Events::TargetControllerStateChanged` event. Other components listen for this event to promptly perform the necessary actions in response to the state change. For example, the [GDB debug server implementation](../DebugServer/Gdb/README.md) will terminate any active debug session: @@ -102,10 +107,6 @@ void GdbRspDebugServer::onTargetControllerStateChanged(const Events::TargetContr } ``` -In some cases, the TargetController may be forced to go into a suspended state. This could be in response to another -program stealing control of the hardware. Actually, this is what led to the introduction of TargetController suspension. -See the corresponding [GitHub issue](https://github.com/navnavnav/Bloom/issues/3) for more. - For more on TargetController suspension, see `TargetControllerComponent::suspend()` and `TargetControllerComponent::resume()`. @@ -114,7 +115,7 @@ For more on TargetController suspension, see `TargetControllerComponent::suspend When a component needs to write to the target's program memory, it must enable programming mode on the target. This can be done by issuing the `EnableProgrammingMode` command to the TargetController (see `TargetControllerConsole::enableProgrammingMode()`). Once programming mode has been enabled, the TargetController will -reject any subsequent commands that involve debug operations (such as `ResumeTargetExecution`, `RaedTargetRegisters`, +reject any subsequent commands that involve debug operations (such as `ResumeTargetExecution`, `ReadTargetRegisters`, etc), until programming mode has been disabled. The TargetController will emit `ProgrammingModeEnabled` and `ProgrammingModeDisabled` events when it enables/disables diff --git a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp index 642c6090..e5f97150 100644 --- a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp +++ b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp @@ -539,12 +539,13 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit::TargetDescription targetPin.variantId = targetVariant.id; // TODO: REMOVE THIS: - if (tdPin.pad.find("vcc") == 0 + if ( + tdPin.pad.find("vcc") == 0 || tdPin.pad.find("avcc") == 0 || tdPin.pad.find("aref") == 0 || tdPin.pad.find("avdd") == 0 || tdPin.pad.find("vdd") == 0 - ) { + ) { targetPin.type = TargetPinType::VCC; } else if (tdPin.pad.find("gnd") == 0) { diff --git a/src/main.cpp b/src/main.cpp index d8255e57..62233119 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,11 +4,6 @@ #include "Application.hpp" int main(int argc, char* argv[]) { - auto arguments = std::vector(); - if (argc > 1) { - arguments.assign(argv + 1, argv + argc); - } - - auto application = Bloom::Application(); - return application.run(arguments); + auto application = Bloom::Application(std::vector(argv, argv + argc)); + return application.run(); }