Renamed and refactored extractConfig() member function

This commit is contained in:
Nav
2022-01-02 20:13:18 +00:00
parent 49383eb448
commit addb3ef64e
2 changed files with 38 additions and 33 deletions

View File

@@ -94,7 +94,7 @@ void Application::startup() {
std::bind(&Application::onShutdownApplicationRequest, this, std::placeholders::_1) std::bind(&Application::onShutdownApplicationRequest, this, std::placeholders::_1)
); );
this->projectConfig = Application::extractConfig(); this->loadProjectConfiguration();
Logger::configure(this->projectConfig.value()); Logger::configure(this->projectConfig.value());
// Start signal handler // Start signal handler
@@ -105,33 +105,6 @@ void Application::startup() {
Logger::debug("Number of environments extracted from config: " Logger::debug("Number of environments extracted from config: "
+ std::to_string(this->projectConfig->environments.size())); + std::to_string(this->projectConfig->environments.size()));
// Validate the selected environment
if (!this->projectConfig->environments.contains(this->selectedEnvironmentName)) {
throw InvalidConfig("Environment (\"" + this->selectedEnvironmentName + "\") not found in configuration.");
}
this->environmentConfig = this->projectConfig->environments.at(this->selectedEnvironmentName);
if (this->environmentConfig->insightConfig.has_value()) {
this->insightConfig = this->environmentConfig->insightConfig.value();
} else if (this->projectConfig->insightConfig.has_value()) {
this->insightConfig = this->projectConfig->insightConfig.value();
} else {
throw InvalidConfig("Insight configuration missing.");
}
if (this->environmentConfig->debugServerConfig.has_value()) {
this->debugServerConfig = this->environmentConfig->debugServerConfig.value();
} else if (this->projectConfig->debugServerConfig.has_value()) {
this->debugServerConfig = this->projectConfig->debugServerConfig.value();
} else {
throw InvalidConfig("Debug server configuration missing.");
}
applicationEventListener->registerCallbackForEventType<Events::TargetControllerThreadStateChanged>( applicationEventListener->registerCallbackForEventType<Events::TargetControllerThreadStateChanged>(
std::bind(&Application::onTargetControllerThreadStateChanged, this, std::placeholders::_1) std::bind(&Application::onTargetControllerThreadStateChanged, this, std::placeholders::_1)
); );
@@ -180,7 +153,7 @@ void Application::shutdown() {
Thread::setThreadState(ThreadState::STOPPED); Thread::setThreadState(ThreadState::STOPPED);
} }
ProjectConfig Application::extractConfig() { void Application::loadProjectConfiguration() {
auto currentPath = std::filesystem::current_path().string(); auto currentPath = std::filesystem::current_path().string();
auto jsonConfigFile = QFile(QString::fromStdString(currentPath + "/bloom.json")); auto jsonConfigFile = QFile(QString::fromStdString(currentPath + "/bloom.json"));
@@ -197,7 +170,36 @@ ProjectConfig Application::extractConfig() {
auto jsonObject = QJsonDocument::fromJson(jsonConfigFile.readAll()).object(); auto jsonObject = QJsonDocument::fromJson(jsonConfigFile.readAll()).object();
jsonConfigFile.close(); jsonConfigFile.close();
return ProjectConfig(jsonObject); this->projectConfig = ProjectConfig(jsonObject);
// Validate the selected environment
if (!this->projectConfig->environments.contains(this->selectedEnvironmentName)) {
throw InvalidConfig(
"Environment (\"" + this->selectedEnvironmentName + "\") not found in configuration."
);
}
this->environmentConfig = this->projectConfig->environments.at(this->selectedEnvironmentName);
if (this->environmentConfig->insightConfig.has_value()) {
this->insightConfig = this->environmentConfig->insightConfig.value();
} else if (this->projectConfig->insightConfig.has_value()) {
this->insightConfig = this->projectConfig->insightConfig.value();
} else {
throw InvalidConfig("Insight configuration missing.");
}
if (this->environmentConfig->debugServerConfig.has_value()) {
this->debugServerConfig = this->environmentConfig->debugServerConfig.value();
} else if (this->projectConfig->debugServerConfig.has_value()) {
this->debugServerConfig = this->projectConfig->debugServerConfig.value();
} else {
throw InvalidConfig("Debug server configuration missing.");
}
} }
int Application::presentHelpText() { int Application::presentHelpText() {

View File

@@ -202,12 +202,15 @@ namespace Bloom
void shutdown(); void shutdown();
/** /**
* Extracts config from the user's JSON config file and generates an ProjectConfig object. * Extracts the project config from the user's JSON config file and populates the following members:
* - this->projectConfig
* - this->environmentConfig
* - this->debugServerConfig
* - this->insightConfig
* *
* @see ProjectConfig declaration for more on this. * @see ProjectConfig declaration for more on this.
* @return
*/ */
static ProjectConfig extractConfig(); void loadProjectConfiguration();
/** /**
* Presents application help text to user. * Presents application help text to user.