#include "config-parser.hpp"
-#include "../low-can-binding.hpp"
+#include "../binding/low-can-hat.hpp"
namespace utils
{
- /// @brief constructor using a POSIX file handle as input.
- ///
- /// @param conf_file - a POSIX file handle to the INI configuration file
- config_parser_t::config_parser_t(int conf_file)
- : config_content_(fdopen(conf_file, "r"))
+ /// @brief constructor using path to file
+ config_parser_t::config_parser_t(std::string conf_file)
+ : filepath_{conf_file}, config_content_{}
{
- ::close(conf_file);
+ config_content_.read_file(conf_file);
}
- /// @brief constructor using path to file
- config_parser_t::config_parser_t(std::string conf_file)
- : config_content_{INIReader(conf_file)}
- {}
+ const std::string& config_parser_t::filepath() const
+ {
+ return filepath_;
+ }
/// @brief read the conf_file_ and parse it into an INIReader object
/// to search into later.
bool config_parser_t::check_conf()
{
- if (config_content_.ParseError() < 0)
+ if (config_content_.size() <= 0)
{
- ERROR(binder_interface, "read_conf: Can't load the INI config file.");
+ ERROR(binder_interface, "%s: Can't load the INI config file.", __FUNCTION__);
return false;
}
- DEBUG(binder_interface, "read_conf: Configuration file parsed");
+ DEBUG(binder_interface, "%s: Configuration file parsed", __FUNCTION__);
return true;
}
/// have to test the returned value.
///
/// @return A const vector with string of linux CAN devices.
- const std::vector<std::string> config_parser_t::get_devices_name()
+ const std::vector<std::pair<std::string, std::string> > config_parser_t::get_devices_name()
{
- std::vector<std::string> devices_name;
+ std::vector<std::pair<std::string, std::string> > devices_name;
- std::set<std::string> sections = config_content_.GetSections();
- for(const auto& sectionsIt : sections)
+ std::map<std::string, std::string> bus_mapping = config_content_.get_keys("CANbus-mapping");
+ for(const auto& busIt : bus_mapping )
{
- if(sectionsIt == "CANbus-mapping")
- {
- std::set<std::string> fields = config_content_.GetFields(sectionsIt);
- for(const auto& fieldsIt : fields)
- {
- std::string val = config_content_.Get(sectionsIt, fieldsIt, "INVALID");
- devices_name.push_back(val);
- }
- }
+ devices_name.push_back(std::make_pair(busIt.first, busIt.second));
}
return devices_name;