Skip to content

Commit

Permalink
Added some test for path processing. Refined logic for pathgetter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peguen committed Jan 3, 2025
1 parent 8f79247 commit cf698de
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 162 deletions.
55 changes: 46 additions & 9 deletions ecal/core/cfg/gen/generate_configuration_yaml.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
/* ========================= 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"
Expand All @@ -21,7 +49,6 @@ int main(int argc, char* argv[]) {
}
}


if (dump)
{
if(!eCAL::Config::dumpConfigToFile())
Expand All @@ -30,25 +57,29 @@ int main(int argc, char* argv[]) {
return 1;
}

return static_cast<int>(!eCAL::Config::dumpToFile(eCAL::Config::getTimeConfigAsYamlSS(), "time.yaml"));
if(!eCAL::Config::dumpToFile(eCAL::Config::getTimeConfigAsYamlSS(), "time.yaml"))
{
std::cerr << "Failed to write time configuration to file." << "\n";
return 1;
}

return 0;
}

const std::vector<std::string> dir_paths =
{
eCAL::Config::eCALConfigEnvPath(),
eCAL::Config::eCALDataEnvPath(),
eCAL::Config::eCALLocalUserDir(),
eCAL::Config::eCALDataSystemDir()
};

bool created = false;
std::string created_path;

// create the ecal paths
for (const std::string& path : dir_paths)
{
if (!path.empty() && eCAL::Config::createEcalDirStructure(path))
{
created = true;
created_path = path;
std::cout << "Created eCAL directory structure in: " << path << "\n";
break;
Expand All @@ -58,16 +89,22 @@ int main(int argc, char* argv[]) {
// dump config to file
if (!created_path.empty())
{
const eCAL::Configuration default_config{};
if (!eCAL::Config::dumpDefaultConfig(created_path))
{
std::cerr << "Failed to write default configuration to file." << "\n";
return 1;
}
return static_cast<int>(!eCAL::Config::dumpToFile(eCAL::Config::getTimeConfigAsYamlSS(), created_path + "/time.yaml"));
}
if(!eCAL::Config::dumpToFile(eCAL::Config::getTimeConfigAsYamlSS(), created_path + "/time.yaml"))
{
std::cerr << "Failed to write time configuration to file." << "\n";
return 1;
}

std::cout << "Created eCAL configuration files in: " << created_path << "\n";

if (!created)
return 0;
}
else
{
std::cerr << "Failed to create eCAL directory structure." << "\n";
return 1;
Expand Down
27 changes: 15 additions & 12 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,30 +35,33 @@ namespace eCAL
namespace Util
{
/**
* @brief Retrieve eCAL configuration path.
* @brief Retrieve eCAL data path.
*
* Checks for a valid default configuration file (ecal.yaml) in the following paths:
* 1. ECAL_CONFIG_DIR environment variable path
* 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 First path that contains a valid config file.
* Returns empty string if no valid config file is found.
* @return First directory that is not empty.
* Returns empty string if no valid directory is found.
**/
ECAL_API std::string GeteCALConfigDir(); // ECAL_DATA PATH?
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 configuration path
* 3. eCAL default configuration path
* 4. System temporary directory
* 5. Fallback path /ecal_tmp
* 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 logging path.
* @return eCAL logging path if exists.
* Returns empty string if no valid path is found.
**/
ECAL_API std::string GeteCALLogDir();

Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/config/builder/logging_attribute_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace eCAL
attributes.file_sink.enabled = log_config_.provider.file.enable;
attributes.file_sink.filter_log = log_config_.provider.file.filter_log;

attributes.file_config.path = log_config_.provider.file_config.path.empty() ? Util::GeteCALLogDir() : log_config_.provider.file_config.path;
attributes.file_config.path = Util::GeteCALLogDir();

attributes.console_sink.enabled = log_config_.provider.console.enable;
attributes.console_sink.filter_log = log_config_.provider.console.filter_log;
Expand Down
Loading

0 comments on commit cf698de

Please sign in to comment.