Other bits of tidying
This commit is contained in:
@@ -1,26 +1,28 @@
|
|||||||
#include "Application.hpp"
|
#include "Application.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <csignal>
|
|
||||||
#include <thread>
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
#include "src/Logger/Logger.hpp"
|
#include "src/Logger/Logger.hpp"
|
||||||
#include "src/Helpers/Paths.hpp"
|
#include "src/Helpers/Paths.hpp"
|
||||||
|
|
||||||
#include "src/Exceptions/InvalidConfig.hpp"
|
#include "src/Exceptions/InvalidConfig.hpp"
|
||||||
|
|
||||||
namespace Bloom
|
namespace Bloom
|
||||||
{
|
{
|
||||||
using namespace Exceptions;
|
using namespace Exceptions;
|
||||||
|
|
||||||
int Application::run(const std::vector<std::string>& arguments) {
|
Application::Application(std::vector<std::string>&& arguments)
|
||||||
|
: arguments(std::move(arguments))
|
||||||
|
{}
|
||||||
|
|
||||||
|
int Application::run() {
|
||||||
try {
|
try {
|
||||||
this->setName("Bloom");
|
this->setName("Bloom");
|
||||||
|
|
||||||
if (!arguments.empty()) {
|
if (this->arguments.size() > 1) {
|
||||||
auto& firstArg = arguments.front();
|
auto& firstArg = this->arguments.at(1);
|
||||||
const auto commandHandlersByCommandName = this->getCommandHandlersByCommandName();
|
const auto commandHandlersByCommandName = this->getCommandHandlersByCommandName();
|
||||||
|
|
||||||
if (commandHandlersByCommandName.contains(firstArg)) {
|
if (commandHandlersByCommandName.contains(firstArg)) {
|
||||||
@@ -36,7 +38,7 @@ namespace Bloom
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BLOOM_DEBUG_BUILD
|
#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
|
#endif
|
||||||
|
|
||||||
this->startup();
|
this->startup();
|
||||||
@@ -332,9 +334,7 @@ namespace Bloom
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Application::initProject() {
|
int Application::initProject() {
|
||||||
auto configFile = QFile(
|
auto configFile = QFile(QString::fromStdString(Paths::projectConfigPath()));
|
||||||
QString::fromStdString(std::filesystem::current_path().string() + "/bloom.json")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (configFile.exists()) {
|
if (configFile.exists()) {
|
||||||
throw Exception("Bloom configuration file (bloom.json) already exists in working directory.");
|
throw Exception("Bloom configuration file (bloom.json) already exists in working directory.");
|
||||||
|
|||||||
@@ -33,19 +33,16 @@ namespace Bloom
|
|||||||
class Application: public Thread
|
class Application: public Thread
|
||||||
{
|
{
|
||||||
public:
|
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<std::string>&& arguments);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry-point for the Bloom program.
|
* Main entry-point for the Bloom program.
|
||||||
*
|
*
|
||||||
* @param arguments
|
|
||||||
* A vector of string arguments passed from the user via the cli.
|
|
||||||
*
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int run(const std::vector<std::string>& arguments);
|
int run();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the current effective user running Bloom has root privileges.
|
* Checks if the current effective user running Bloom has root privileges.
|
||||||
@@ -55,6 +52,8 @@ namespace Bloom
|
|||||||
static bool isRunningAsRoot();
|
static bool isRunningAsRoot();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::vector<std::string> arguments;
|
||||||
|
|
||||||
EventListenerPointer applicationEventListener = std::make_shared<EventListener>("ApplicationEventListener");
|
EventListenerPointer applicationEventListener = std::make_shared<EventListener>("ApplicationEventListener");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,14 +66,13 @@ namespace Bloom
|
|||||||
std::thread signalHandlerThread;
|
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.
|
* dedicated thread.
|
||||||
*
|
*
|
||||||
* See the TargetController class for more on this.
|
* 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
|
* 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 the debug server (for polymorphism), I thought I'd keep it consistent.
|
||||||
* std::unique_ptr for lazy loading.
|
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<TargetController::TargetControllerComponent> targetController = nullptr;
|
std::unique_ptr<TargetController::TargetControllerComponent> targetController = nullptr;
|
||||||
std::thread targetControllerThread;
|
std::thread targetControllerThread;
|
||||||
@@ -94,10 +92,8 @@ namespace Bloom
|
|||||||
*
|
*
|
||||||
* Insight is optional - users can disable it via their project configuration.
|
* 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
|
* When the user closes the Insight GUI, control of the main thread is returned to Application::run(). See the
|
||||||
* deal with the GUI being closed at this point depends on user configuration.
|
* Insight class for more on this.
|
||||||
*
|
|
||||||
* 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
|
* 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
|
* std::optional here because the Insight class extends QObject, which disables the copy constructor and
|
||||||
|
|||||||
@@ -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
|
requires access to the debug tool or target. Issuing any of these commands whilst the TargetController is suspended
|
||||||
will result in an error response.
|
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
|
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,
|
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:
|
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
|
For more on TargetController suspension, see `TargetControllerComponent::suspend()` and
|
||||||
`TargetControllerComponent::resume()`.
|
`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
|
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
|
be done by issuing the `EnableProgrammingMode` command to the TargetController (see
|
||||||
`TargetControllerConsole::enableProgrammingMode()`). Once programming mode has been enabled, the TargetController will
|
`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.
|
etc), until programming mode has been disabled.
|
||||||
|
|
||||||
The TargetController will emit `ProgrammingModeEnabled` and `ProgrammingModeDisabled` events when it enables/disables
|
The TargetController will emit `ProgrammingModeEnabled` and `ProgrammingModeDisabled` events when it enables/disables
|
||||||
|
|||||||
@@ -539,7 +539,8 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit::TargetDescription
|
|||||||
targetPin.variantId = targetVariant.id;
|
targetPin.variantId = targetVariant.id;
|
||||||
|
|
||||||
// TODO: REMOVE THIS:
|
// TODO: REMOVE THIS:
|
||||||
if (tdPin.pad.find("vcc") == 0
|
if (
|
||||||
|
tdPin.pad.find("vcc") == 0
|
||||||
|| tdPin.pad.find("avcc") == 0
|
|| tdPin.pad.find("avcc") == 0
|
||||||
|| tdPin.pad.find("aref") == 0
|
|| tdPin.pad.find("aref") == 0
|
||||||
|| tdPin.pad.find("avdd") == 0
|
|| tdPin.pad.find("avdd") == 0
|
||||||
|
|||||||
@@ -4,11 +4,6 @@
|
|||||||
#include "Application.hpp"
|
#include "Application.hpp"
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
auto arguments = std::vector<std::string>();
|
auto application = Bloom::Application(std::vector<std::string>(argv, argv + argc));
|
||||||
if (argc > 1) {
|
return application.run();
|
||||||
arguments.assign(argv + 1, argv + argc);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto application = Bloom::Application();
|
|
||||||
return application.run(arguments);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user