Skip to content

Commit

Permalink
[config] Modernized config path handling (#1889)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peguen authored Jan 14, 2025
1 parent 5a90554 commit e75a706
Show file tree
Hide file tree
Showing 28 changed files with 1,474 additions and 156 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ jobs:
cd $GITHUB_WORKSPACE
git submodule init
git submodule deinit thirdparty/curl/curl
git submodule deinit thirdparty/gtest/googletest
git submodule deinit thirdparty/hdf5/hdf5
git submodule deinit thirdparty/protobuf/protobuf
git submodule update
Expand Down Expand Up @@ -128,7 +127,7 @@ jobs:
-DECAL_THIRDPARTY_BUILD_TINYXML2=ON \
-DECAL_THIRDPARTY_BUILD_FINEFTP=ON \
-DECAL_THIRDPARTY_BUILD_CURL=OFF \
-DECAL_THIRDPARTY_BUILD_GTEST=OFF \
-DECAL_THIRDPARTY_BUILD_GTEST=ON \
-DECAL_THIRDPARTY_BUILD_HDF5=OFF \
-DECAL_THIRDPARTY_BUILD_RECYCLE=ON \
-DECAL_THIRDPARTY_BUILD_TCP_PUBSUB=ON \
Expand Down
2 changes: 1 addition & 1 deletion app/play/play_core/include/ecal_play_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class EcalPlayLogger
static const int MAXIMUM_ROTATING_FILES = 5;
static const int FIVE_MEGABYTES = 5 * 1024 * 1024;

auto ecal_data_path = eCAL::Util::GeteCALLogPath();
auto ecal_data_path = eCAL::Util::GeteCALLogDir();
std::string log_filename = ecal_data_path + EcalPlayGlobals::ECAL_PLAY_NAME + ".log";

// create console logger and rotating file logger with maximum size 5MB and maximum 5 rotating files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace eCAL
static const int MAXIMUM_ROTATING_FILES = 5;
static const int FIVE_MEGABYTES = 5 * 1024 * 1024;

auto ecal_data_path = eCAL::Util::GeteCALLogPath();
auto ecal_data_path = eCAL::Util::GeteCALLogDir();
std::string log_filename = ecal_data_path + ECAL_REC_NAME + ".log";

// create console logger and rotating file logger with maximum size 5MB and maximum 5 rotating files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace eCAL
static const int MAXIMUM_ROTATING_FILES = 5;
static const int FIVE_MEGABYTES = 5 * 1024 * 1024;

auto ecal_data_path = eCAL::Util::GeteCALLogPath();
auto ecal_data_path = eCAL::Util::GeteCALLogDir();
std::string log_filename = ecal_data_path + ecal_sys_client + ".log";

// create console logger and rotating file logger with maximum size 5MB and maximum 5 rotating files
Expand Down
2 changes: 1 addition & 1 deletion app/sys/sys_core/include/ecalsys/ecal_sys_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class EcalSysLogger
static const int MAXIMUM_ROTATING_FILES = 5;
static const int FIVE_MEGABYTES = 5 * 1024 * 1024;

auto ecal_data_path = eCAL::Util::GeteCALLogPath();
auto ecal_data_path = eCAL::Util::GeteCALLogDir();
std::string log_filename = ecal_data_path + ECAL_SYS_LIB_NAME + ".log";

// create console logger and rotating file logger with maximum size 5MB and maximum 5 rotating files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ void ImportFromCloudWidget::import()

void ImportFromCloudWidget::loadExcludeTasksFilter()
{
std::string default_cfg_file_path = eCAL::Util::GeteCALActiveIniFile();
const std::string default_cfg_file_path = eCAL::GetConfiguration().GetYamlFilePath();
QFile default_cfg_file(default_cfg_file_path.c_str());
if (default_cfg_file.exists())
{
Expand Down
6 changes: 3 additions & 3 deletions contrib/ecaltime/linuxptp/src/config/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,8 +33,8 @@ namespace LinuxPtpConfig {
* @return the device value from the linuxptp section
*/
std::string getDevice() {
std::string path_to_ini = eCAL::Util::GeteCALConfigPath();
path_to_ini += "ecaltime.yaml";
std::string path_to_ini = eCAL::Util::GeteCALDataDir();
path_to_ini += "/ecaltime.yaml";

YAML::Node yaml;
try
Expand Down
4 changes: 3 additions & 1 deletion ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ endif()
set(ecal_config_src
src/config/default_configuration.cpp
src/config/ecal_config.cpp
src/config/ecal_config_initializer.cpp
src/config/configuration.cpp
src/config/ecal_path_processing.cpp
src/types/ecal_custom_data_types.cpp
)
if (ECAL_CORE_CONFIGURATION)
list(APPEND ecal_config_src
src/config/configuration_to_yaml.cpp
src/config/configuration_reader.cpp
src/config/configuration_writer.cpp
)
endif()
######################################
Expand Down
13 changes: 8 additions & 5 deletions ecal/core/cfg/gen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ set(ECAL_YAML "ecal.yaml")

add_executable(${PROJECT_NAME}
${ECAL_CORE_PROJECT_ROOT}/core/cfg/gen/generate_configuration_yaml.cpp
${ECAL_CORE_PROJECT_ROOT}/core/src/config/configuration_writer.cpp
${ECAL_CORE_PROJECT_ROOT}/core/src/config/default_configuration.cpp
${ECAL_CORE_PROJECT_ROOT}/core/src/config/ecal_path_processing.cpp
)

# Set the output path for the generated YAML file
set(YAML_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${ECAL_YAML})

# Add a custom command to generate the YAML file
add_custom_command(
OUTPUT ${YAML_OUTPUT_PATH} # Specify the output file
COMMAND $<TARGET_FILE:${PROJECT_NAME}> # Command to run the executable
DEPENDS ${PROJECT_NAME} # Ensure the executable is built before running the command
COMMENT "Generating ${YAML_OUTPUT_PATH}" # Comment to display during the build process
VERBATIM # Ensure command arguments are passed as-is
OUTPUT ${YAML_OUTPUT_PATH} # Specify the output file
COMMAND $<TARGET_FILE:${PROJECT_NAME}> --dump # Command to run the executable
DEPENDS ${PROJECT_NAME} # Ensure the executable is built before running the command
COMMENT "Generating ${YAML_OUTPUT_PATH}" # Comment to display during the build process
VERBATIM # Ensure command arguments are passed as-is
)

# Add a custom target that depends on the generated YAML file
Expand All @@ -54,6 +56,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE

target_link_libraries(${PROJECT_NAME} PRIVATE
eCAL::core
eCAL::ecal-utils
)

# Select the correct ecal config directory on Linux and Windows
Expand Down
106 changes: 100 additions & 6 deletions ecal/core/cfg/gen/generate_configuration_yaml.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,105 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================= eCAL LICENSE =================================
*/

/**
* @brief Generate an ecal.yaml file with default configuration.
* Use --dump or -d to write the default configuration to file in current folder.
* Use with no arguments to create the eCAL directory in the first available of the following paths:
* 1. ECAL_DATA environment variable path if set
* 2. local user path
* 3. system path like etc, ProgramData
**/

#include "config/configuration_writer.h"
#include "config/default_configuration.h"
#include "config/ecal_path_processing.h"

#include <iostream>
#include <string>


void exitWithMessage(const std::string& message, int exitCode, bool wait_for_it = true) {
if (!message.empty()) {
if (exitCode == 0) {
std::cout << message << "\n";
} else {
std::cerr << message << "\n";
}
}

if (wait_for_it)
{
std::cout << "Press Enter to continue...";
std::cin.get();
}

exit(exitCode);
}

int main(int argc, char* argv[]) {
bool dump = false;

for (int i = 1; i < argc; i++) {
const std::string arg = argv[i];
if (arg == "--dump" || arg == "-d") {
dump = true;
} else {
exitWithMessage("Unknown argument: " + arg, 1);
}
}

int main() {
if (!eCAL::Config::dumpConfigToFile())
{
std::cerr << "Failed to write default configuration to file." << std::endl;
return 1;
if (dump) {
if (!eCAL::Config::dumpConfigToFile()) {
exitWithMessage("Failed to write default configuration to file.", 1, false);
}

if (!eCAL::Config::dumpToFile(eCAL::Config::getTimeConfigAsYamlSS(), "time.yaml")) {
exitWithMessage("Failed to write time configuration to file.", 1, false);
}

exitWithMessage("", 0, false);
}

std::string created_path;
auto dir_manager = eCAL::Util::DirManager();
const std::vector<std::string> dir_paths = eCAL::Config::getEcalDefaultPaths(eCAL::Util::DirProvider(), dir_manager);

// create the ecal paths
for (const std::string& path : dir_paths) {
if (!path.empty() && dir_manager.createEcalDirStructure(path)) {
created_path = path;
std::cout << "Created eCAL directory structure in: " << path << "\n";
break;
}
}

// dump config to file
if (!created_path.empty()) {
if (!eCAL::Config::dumpDefaultConfig(created_path)) {
exitWithMessage("Failed to write default configuration to file.", 1);
}
if (!eCAL::Config::dumpToFile(eCAL::Config::getTimeConfigAsYamlSS(), created_path + "/time.yaml")) {
exitWithMessage("Failed to write time configuration to file.", 1);
}

return 0;
exitWithMessage("Created eCAL configuration files in: " + created_path, 0);
} else {
exitWithMessage("Failed to create eCAL directory structure.", 1);
}
}
11 changes: 3 additions & 8 deletions ecal/core/include/ecal/config/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
#include <vector>
#include <string>

namespace
{
// After switchting to c++17, this can be replaced by an inline constexpr
static const eCAL_Logging_Filter log_filter_default = log_level_info | log_level_warning | log_level_error | log_level_fatal;
}

namespace eCAL
{
Expand Down Expand Up @@ -65,9 +60,9 @@ namespace eCAL

struct Configuration
{
Sink console { true, log_level_error | log_level_fatal}; //!< default: true, log_level_error
Sink file { false, log_level_none }; //!< default: false, log_level_none
Sink udp { true, log_filter_default }; //!< default: true, log_filter_default
Sink console { true, log_level_warning | log_level_error | log_level_fatal }; //!< default: true, log_level_warning | log_level_error | log_level_fatal
Sink file { false, log_level_none }; //!< default: false, log_level_none
Sink udp { true, log_level_info | log_level_warning | log_level_error | log_level_fatal }; //!< default: true, log_level_info | log_level_warning | log_level_error | log_level_fatal

File::Configuration file_config;
UDP::Configuration udp_config;
Expand Down
44 changes: 20 additions & 24 deletions ecal/core/include/ecal/ecal_util.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,39 +35,35 @@ namespace eCAL
namespace Util
{
/**
* @brief Retrieve eCAL configuration path.
* This is path is for the global eCAL configuration files
* like ecal.yaml.
* This path is read only for standard users.
* @brief Retrieve eCAL data path.
*
* @return eCAL configuration path.
**/
ECAL_API std::string GeteCALConfigPath();

/**
* @brief Retrieve eCAL user configuration path.
* This is path is for the eCAL application settings files.
* This path has read/write permissions for standard users.
* Checks if a valid eCAL data path is available in the following order:
* 1. ECAL_DATA environment variable path
* 2. Local user path (win: Appdata/Local, unix: ~/.ecal)
* 3. System paths like /etc/ecal, ProgramData/eCAL
*
* @return eCAL data path.
* @return First directory that is not empty.
* Returns empty string if no valid directory is found.
**/
ECAL_API std::string GeteCALUserSettingsPath();
ECAL_API std::string GeteCALDataDir();

/**
* @brief Retrieve eCAL standard logging path.
* This is path is for the eCAL logging files.
* This path has read/write permissions for standard users.
*
* 1. ECAL_LOG_DIR environment variable path
* 2. ECAL_DATA environment variable path
* 3. Path provided by eCAL configuration
* 4. Path to local eCAL directory
* 5. For windows: ProgramData/eCAL if available
* 6. System temp path if available
* 7. Fallback path /ecal_tmp
*
* @return eCAL data path.
**/
ECAL_API std::string GeteCALLogPath();

/**
* @brief Retrieve full path to active eCAL ini file.
*
* @return eCAL active ini file name.
* @return eCAL logging path if exists.
* Returns empty string if no valid path is found.
**/
ECAL_API std::string GeteCALActiveIniFile();
ECAL_API std::string GeteCALLogDir();

/**
* @brief Send shutdown event to specified local user process using it's unit name.
Expand Down
Loading

0 comments on commit e75a706

Please sign in to comment.